Exemple #1
0
    def initContent(data):
        conf.set_default_domain_by_inter(data['interpreter'])
        domain_data = conf.default_domain_data
        # if not domain_data.get('key'):
        #     raise CheckiOClientConfigError('Domain is not configure. Please do $ checkio config')
        if not domain_data.get('solutions'):
            raise CheckiOClientConfigError('Solutions are not synchronized yet. Please do $ checkio sync -h')

        paths = solutions_paths(domain_data['solutions'], domain_data['extension'])
        if data['slug'] in paths:

            filename = paths[data['slug']]

            with open(filename, 'r', encoding='utf-8') as fh:
                content = code_for_sync(fh.read())

            return {
                'do': 'initContent',
                'filename': filename,
                'content': content,
                'slug': data['slug']
            }
        else:
            filename = gen_filename(data['slug'], data['station'])
            init_code_file(filename, 
                gen_env_line(data['slug']) + '\n' + data['content'])

            return {
                'do': 'initContent',
                'filename': filename,
                'slug': data['slug'],
                'isNew': True
            }
Exemple #2
0
def get_filename(args):
    if args.filename:
        return args.filename
    default_data = conf.default_domain_data
    if 'solutions' not in default_data:
        raise ValueError('Solutions folder is not defined')

    mission = args.mission[0]
    try:
        return solutions_paths()[mission]
    except KeyError:
        raise ValueError('File for mission "{}"" not found'.format(mission))
Exemple #3
0
def get_filename(args):
    if args.filename:
        filename = args.filename
        filename = os.path.expanduser(filename)
        filename = os.path.abspath(filename)
        return filename
    default_data = conf.default_domain_data
    if 'solutions' not in default_data:
        raise ValueError('Solutions folder is not defined')

    mission = args.mission[0]
    try:
        return solutions_paths()[mission]
    except KeyError:
        return None
Exemple #4
0
def main(args):
    folder = args.folder
    with_unseen = not args.exclude_unseen
    with_solved = not args.exclude_solved
    save_config = not args.without_config

    domain_data = conf.default_domain_data

    if not folder:
        folder = domain_data.get('solutions')
        if not folder:
            print('Select folder')
            return
        print('Using folder "{}"'.format(folder))

    if args.configure_only:
        conf.default_domain_section['solutions'] = os.path.abspath(folder)
        conf.save()
        return

    paths = solutions_paths(folder)

    print('Requesting...')
    data = get_user_missions()
    for item in data['objects']:
        if not item['isStarted'] and not with_unseen:
            continue

        if item['isSolved'] and not with_solved:
            continue

        mission = item['slug']
        code = item['code']
        description = item['description']

        output = code_for_file(mission, code,
                               None if args.without_info else description)

        # file exist
        if mission not in paths:
            filename = gen_filename(mission, item['stationName'], folder)
            init_code_file(filename, output)
            print(filename + ' - Created')
            continue

        filename = paths[mission]
        f_stats = os.stat(filename)

        # file changed
        with open(filename, 'r', encoding='utf-8') as fh:
            local_code = fh.read()
            if code_for_send(local_code) == code_for_send(output):
                continue

        t_changed = time.time() - f_stats.st_mtime

        # local file have been changed
        if not item['secondsPast'] or t_changed < item['secondsPast']:
            print(filename + ' - Sending... ', end='')
            save_code(code_for_send(local_code), item['id'])
            print('Done')

        # file was changed through the web interface
        else:
            init_code_file(filename, output)
            print(filename + ' - Overwritten')

    if save_config:
        conf.default_domain_section['solutions'] = os.path.abspath(folder)
        conf.save()