def setup_usage_report(name, version): """Sets up the usagestats module. """ global _usage_report # Unpack CA certificate fd, certificate_file = Path.tempfile(prefix='rpz_stats_ca_', suffix='.pem') with certificate_file.open('wb') as fp: fp.write(usage_report_ca) os.close(fd) atexit.register(os.remove, certificate_file.path) _usage_report = usagestats.Stats( '~/.reprozip/usage_stats', usagestats.Prompt(enable='%s usage_report --enable' % name, disable='%s usage_report --disable' % name), os.environ.get('REPROZIP_USAGE_URL', 'https://reprozip-stats.poly.edu/'), version='%s %s' % (name, version), unique_user_id=True, env_var='REPROZIP_USAGE_STATS', ssl_verify=certificate_file.path) try: os.getcwd().encode('ascii') except (UnicodeEncodeError, UnicodeDecodeError): record_usage(cwd_ascii=False) else: record_usage(cwd_ascii=True)
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 setup_usage_report(name, version): """Sets up the usagestats module. """ global _usage_report certificate_file = get_reprozip_ca_certificate() _usage_report = usagestats.Stats( '~/.reprozip/usage_stats', usagestats.Prompt(enable='%s usage_report --enable' % name, disable='%s usage_report --disable' % name), os.environ.get('REPROZIP_USAGE_URL', 'https://stats.reprozip.org/'), version='%s %s' % (name, version), unique_user_id=True, env_var='REPROZIP_USAGE_STATS', ssl_verify=certificate_file.path) try: os.getcwd().encode('ascii') except (UnicodeEncodeError, UnicodeDecodeError): record_usage(cwd_ascii=False) else: record_usage(cwd_ascii=True)
# Copyright (C) 2014-2017 New York University # This file is part of ReproZip which is released under the Revised BSD License # See file LICENSE for full license details. import os from reprounzip.common import get_reprozip_ca_certificate import usagestats from reprounzip_qt import __version__ as version _certificate_file = get_reprozip_ca_certificate() _usage_report = usagestats.Stats( '~/.reprozip/usage_stats', usagestats.Prompt(''), os.environ.get('REPROZIP_USAGE_URL', 'https://stats.reprozip.org/'), version='%s %s' % ('reprounzip-qt', version), unique_user_id=True, env_var='REPROZIP_USAGE_STATS', ssl_verify=_certificate_file.path ) def record_usage(**kwargs): """Records some info in the current usage report. """ if _usage_report is not None: _usage_report.note(kwargs)
import functools import os import shutil import signal import subprocess import sys import tempfile import time import unittest import usagestats from tests.utils import capture_stderr, regex_compare optin_prompt = usagestats.Prompt(enable='cool_program --enable-stats', disable='cool_program --disable-stats') def temp_recv_dir(func): @functools.wraps(func) def wrapper(self): for name in os.listdir(self._recv_dir): os.remove(os.path.join(self._recv_dir, name)) tdir = tempfile.mkdtemp(prefix='usagestats_tests_send_') try: os.environ['HOME'] = tdir func(self, tdir=tdir) finally: shutil.rmtree(tdir) return wrapper