示例#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
            }
示例#2
0
def main(args):
    if args.out and args.filename:
        raise ValueError('out and filename can not be used together')

    mission = args.mission[0]
    filename = args.filename
    if not filename:
        filename = (
            mission.replace('-', '_') + '.' +
            conf.default_domain_data['extension']
        )


    if not args.out:
        print('Requesting...')

    data = get_mission_info(mission)
    code = data['code']
    description = data['description']

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

    if args.out:
        print(output)
        return


    init_code_file(filename, output)
    print('Done')
示例#3
0
def sync_single_mission(mission):
    domain_data = conf.default_domain_data
    item = get_user_single_mission(mission)
    if item is None or item['stationName'] is None:
        return
    mission = item['slug']
    code = item['code']
    description = item['description']
    folder = domain_data.get('solutions')

    output = code_for_file(mission, code, description)

    filename = gen_filename(mission, item['stationName'], folder)
    init_code_file(filename, output)
    return filename
示例#4
0
def main(args):
    folder = args.folder
    with_unseen = args.include_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('Requesting...')
    data = get_user_missions()
    os.makedirs(folder, exist_ok=True)

    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']

        filename = os.path.join(
            folder,
            mission.replace('-', '_') + '.' + domain_data['extension'])

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

        init_code_file(filename, output)

        print(filename + ' - Done')

        if save_config:
            conf.default_domain_section['solutions'] = os.path.abspath(folder)
            conf.save()
示例#5
0
def main(args):
    mission = args.mission[0]
    filename = args.filename

    if filename:
        print('Requesting...')

    data = get_mission_info(mission)
    code = data['code']
    description = data['description']

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

    if not filename:
        print(output)
        return

    init_code_file(filename, output)
    print('Done')
示例#6
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()