Ejemplo n.º 1
0
def update_parameters():
    """Try to download a new version of the parameter file.
    """
    global parameters
    if parameters is not None:
        return

    url = 'https://reprozip-stats.poly.edu/parameters/'
    env_var = os.environ.get('REPROZIP_PARAMETERS')
    if env_var and (
            env_var.startswith('http://') or env_var.startswith('https://')):
        # This is only used for testing
        # Note that this still expects the ReproZip CA
        url = env_var
    elif env_var not in (None, '', '1', 'on', 'enabled', 'yes', 'true'):
        parameters = json.loads(bundled_parameters)
        return

    try:
        from reprounzip.main import __version__ as version
        filename = download_file(
            '%s%s' % (url, version),
            None,
            cachename='parameters.json',
            ssl_verify=get_reprozip_ca_certificate().path)
    except Exception:
        logging.info("Can't download parameters.json, using bundled "
                     "parameters")
    else:
        try:
            with filename.open() as fp:
                parameters = json.load(fp)
        except ValueError:
            logging.info("Downloaded parameters.json doesn't load, using "
                         "bundled parameters")
            try:
                filename.remove()
            except OSError:
                pass
        else:
            ver = LooseVersion(parameters.get('version', '1.0'))
            if LooseVersion('1.1') <= ver < LooseVersion('1.2'):
                return
            else:
                logging.info("parameters.json has incompatible version %s, "
                             "using bundled parameters", ver)

    parameters = json.loads(bundled_parameters)
Ejemplo n.º 2
0
def update_parameters():
    """Try to download a new version of the parameter file.
    """
    global parameters
    if parameters is not None:
        return

    url = 'https://stats.reprozip.org/parameters/'
    env_var = os.environ.get('REPROZIP_PARAMETERS')
    if env_var and (env_var.startswith('http://')
                    or env_var.startswith('https://')):
        # This is only used for testing
        # Note that this still expects the ReproZip CA
        url = env_var
    elif env_var not in (None, '', '1', 'on', 'enabled', 'yes', 'true'):
        parameters = _bundled_parameters
        return

    try:
        from reprounzip.main import __version__ as version
        filename = download_file('%s%s' % (url, version),
                                 None,
                                 cachename='parameters.json',
                                 ssl_verify=get_reprozip_ca_certificate().path)
    except Exception:
        logger.info("Can't download parameters.json, using bundled "
                    "parameters")
    else:
        try:
            with filename.open() as fp:
                parameters = json.load(fp)
        except ValueError:
            logger.info("Downloaded parameters.json doesn't load, using "
                        "bundled parameters")
            try:
                filename.remove()
            except OSError:
                pass
        else:
            ver = LooseVersion(parameters.get('version', '1.0'))
            if LooseVersion('1.1') <= ver < LooseVersion('3.0'):
                return
            else:
                logger.info(
                    "parameters.json has incompatible version %s, "
                    "using bundled parameters", ver)

    parameters = _bundled_parameters
Ejemplo n.º 3
0
# 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)