Ejemplo n.º 1
0
def register(email, username, password, date_year, date_month, date_day,
             secondary_email='', marketing_enabled=False):
    email = email.strip()
    username = username.strip()
    password = password.strip()
    if secondary_email:
        secondary_email.strip()

    if not is_number(date_year) or not is_number(date_month) or not is_number(date_day):
        return False, 'Date in bad format!'

    payload = {
        'email': email,
        'username': username,
        'password': password,
        'birthdate': '{}-{}-{}'.format(date_year, date_month, date_day),
    }

    payload['marketing_enabled_primary'] = str(marketing_enabled).lower()
    payload['marketing_enabled_secondary'] = str(marketing_enabled).lower()

    if secondary_email:
        payload['secondary_email'] = secondary_email

    success, text, data = request_wrapper('post', '/users', data=json.dumps(payload), headers=content_type_json)
    if success:
        return login_register_data(data)
    else:
        return False, 'Cannot register, problem: {}'.format(text)
Ejemplo n.º 2
0
def read_config(path=config_path):
    # read a config file for comparison, into a config_vals object

    lines = open(path, "r").readlines()
    values = {}
    comment_values = {}
    comment_keys = {}
    comments = []
    commentRe = re.compile('### ([^:]+): (.*)')
    valRe = re.compile('([^=#]+)=(.*)')
    valCommentRe = re.compile('^\s*#\s*([^=#]+)=(.*)')

    for x in lines:
        m = commentRe.match(x)
        if m:
            comment_values[m.group(1)] = m.group(2)
            continue
        m = valRe.match(x)
        m2 = valCommentRe.match(x)
        if m or m2:
            if not m:
                m = m2
            values[m.group(1)] = m.group(2)
            if is_number(m.group(2)):
                values[m.group(1)] = int(m.group(2))
            if m2:
                comment_keys[m.group(1)] = True
            continue
        comments.append(x)
    return config_vals(values, comment_values, comments, comment_keys)
def read_config(path=config_path):
    # read a config file for comparison, into a config_vals object

    lines = open(path, "r").readlines()
    values = {}
    comment_values = {}
    comment_keys = {}
    comments = []
    commentRe = re.compile('### ([^:]+): (.*)')
    valRe = re.compile('([^=#]+)=(.*)')
    valCommentRe = re.compile('^\s*#\s*([^=#]+)=(.*)')

    for x in lines:
        m = commentRe.match(x)
        if m:
            comment_values[m.group(1)] = m.group(2)
            continue
        m = valRe.match(x)
        m2 = valCommentRe.match(x)
        if m or m2:
            if not m:
                m = m2
            values[m.group(1)] = m.group(2)
            if is_number(m.group(2)):
                values[m.group(1)] = int(m.group(2))
            if m2:
                comment_keys[m.group(1)] = True
            continue
        comments.append(x)
    return config_vals(values, comment_values, comments, comment_keys)
Ejemplo n.º 4
0
def add_runtime_to_app(app, runtime):
    """ Saves the tracking data for a given application.

        Appends a time period to a given app's runtime stats and raises
        starts by one. Apart from the total values, it also updates the
        weekly stats.

        This function uses advisory file locks (see flock(2)) to avoid
        races between different applications saving their tracking data
        at the same time.

        :param app: The name of the application.
        :type app: str
        :param runtime: For how long was the app running.
        :type runtime: number
    """

    if not app or app == 'kano-tracker':
        return

    if not is_number(runtime):
        return

    runtime = float(runtime)

    app = app.replace('.', '_')

    # Make sure no one else is accessing this file
    app_state_file = get_app_state_file('kano-tracker')

    try:
        tracker_store = open_locked(app_state_file, "r")
    except IOError as e:
        logger.error('Error opening app state file {}'.format(e))
    else:
        app_stats = load_app_state_variable('kano-tracker', 'app_stats')
        if not app_stats:
            app_stats = dict()

        try:
            app_stats[app]['starts'] += 1
            app_stats[app]['runtime'] += runtime
        except Exception:
            app_stats[app] = {
                'starts': 1,
                'runtime': runtime,
            }

        # Record usage data on per-week basis
        if 'weekly' not in app_stats[app]:
            app_stats[app]['weekly'] = {}

        week = str(_get_nearest_previous_monday())
        if week not in app_stats[app]['weekly']:
            app_stats[app]['weekly'][week] = {
                'starts': 0,
                'runtime': 0
            }

        app_stats[app]['weekly'][week]['starts'] += 1
        app_stats[app]['weekly'][week]['runtime'] += runtime

        save_app_state_variable('kano-tracker', 'app_stats', app_stats)

        # Close the lock
        tracker_store.close()
Ejemplo n.º 5
0
    def _check_entry_is_number(self, entry):
        entry_text = entry.get_text()
        if not is_number(entry_text):
            return False, ""

        return True, int(entry_text)