def setup_usage_report(): """Sets up the usagestats module. """ global usage_report certificate_file = get_ca_certificate() usage_report = usagestats.Stats( '~/.vistrails/usage_stats', usagestats.Prompt( "\nUploading usage statistics is currently disabled\n" "Please help us by providing anonymous usage statistics; " "you can enable this\neither from the GUI or by using " "--enable-usage-stats\n" "If you do not want to see this message again, you can disable " "it from the GUI or with --disable-usage-stats\n" "Nothing will be uploaded before you opt in.\n"), 'https://reprozip-stats.poly.edu/', version='VisTrails %s' % vistrails_version(), unique_user_id=True, env_var='VISTRAILS_USAGE_STATS', ssl_verify=certificate_file) cwd = os.getcwd() record_usage(cwd_spaces=b' ' in cwd) try: cwd.decode('ascii') except UnicodeDecodeError: record_usage(cwd_ascii=False) else: record_usage(cwd_ascii=True)
def get_server_news(): global _server_news if _server_news is not None: return _server_news dot_vistrails = os.path.expanduser('~/.vistrails') if not os.path.exists(dot_vistrails): os.mkdir(dot_vistrails) file_name = os.path.join(dot_vistrails, 'server_news.json') file_exists = os.path.exists(file_name) headers = {} if file_exists: mtime = email.utils.formatdate(os.path.getmtime(file_name), usegmt=True) headers['If-Modified-Since'] = mtime try: resp = requests.get( 'https://reprozip-stats.poly.edu/vistrails_news/%s' % vistrails_version(), headers=headers, timeout=2 if file_exists else 10, stream=True, verify=get_ca_certificate()) resp.raise_for_status() if resp.status_code == 304: raise requests.HTTPError( '304 File is up to date, no data returned', response=resp) except requests.RequestException, e: if not e.response or e.response.status_code != 304: debug.warning("Can't download server news", e)