Exemplo n.º 1
0
def configure_editor():
    if not platform.system() == 'Windows':
        return
    default_data = conf.default_domain_data
    editor = default_data['editor']
    editor = input('Command that will be used for editing files [{}]:'.format(
        editor)) or editor
    conf.default_domain_section['editor'] = editor.strip()
    conf.save()
Exemplo n.º 2
0
def main(args):
    if not conf.has_section('Main'):
        conf.add_section('Main')
    for domain_key in conf.domains:
        domain_section = domain_key + '_checkio'
        if not conf.has_section(domain_section):
            conf.add_section(domain_section)

    print('Config file {} will be created'.format(conf.filename))
    print('after short configuration process')

    print(
        'Which domain you want to use by default? (first two letters are needed)'
    )
    for dom, dom_conf in conf.domains.items():
        print('[{}] - {}'.format(dom, dom_conf['url_main']))
    print('by default:{}'.format(conf.default_domain))

    while True:
        new_domain = input('First two letters of the domain[{}]:'.format(
            conf.default_domain)).strip()
        if not new_domain:
            new_domain = conf.default_domain
            break
        if new_domain not in conf.domains:
            continue
        break

    conf['Main']['default_domain'] = new_domain

    domain_data = conf.domains[new_domain]

    print('What is your KEY for {} ?'.format(domain_data['url_main']))
    print('You can find one on {}/profile/edit/'.format(
        domain_data['url_main']))
    while True:
        new_key = input('KEY:').strip()
        if not new_key:
            continue
        break

    domain_section = new_domain + '_checkio'

    conf[domain_section]['key'] = new_key
    conf.save()

    print('Config file {} was updated.'.format(conf.filename))
    print('Thank you')
Exemplo n.º 3
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()
Exemplo n.º 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()
Exemplo n.º 5
0
def main(args):
    if not conf.has_section('Main'):
        conf.add_section('Main')

    if args.domain and args.domain not in conf.domains:
        print('Wrong Domain')
        return

    for domain_key in conf.domains:
        domain_section = domain_key + '_checkio'
        if not conf.has_section(domain_section):
            conf.add_section(domain_section)

    if args.domain is None:
        print('Config file {} will be created'.format(conf.filename))
        print('after short configuration process')

        print('Which domain you want to use by default? (code required)')
        for dom, dom_conf in conf.domains.items():
            print('[{}] - {}'.format(dom, dom_conf['url_main']))
        print('by default:{}'.format(conf.default_domain))

        while True:
            new_domain = input('Code for domain[{}]:'.format(
                conf.default_domain)).strip()

            if not new_domain:
                new_domain = conf.default_domain
                break

            if new_domain not in conf.domains:
                continue
            break
    else:
        new_domain = args.domain

    conf['Main']['default_domain'] = new_domain

    domain_data = conf.domains[new_domain]
    domain_section = new_domain + '_checkio'

    if args.key is None:
        print('What is your KEY for {} ?'.format(domain_data['url_main']))

        if domain_data['game'] == 'eoc':
            print('You can find one in game settings')
        else:
            print('You can find one on {}/profile/edit/'.format(
                domain_data['url_main']))

        while True:
            new_key = input('KEY:').strip()
            if not new_key:
                continue
            break
    else:
        new_key = args.key

    conf[domain_section]['key'] = new_key

    for param in TRANSFER_PARAMETERS:
        if param in domain_data:
            conf[domain_section][param] = domain_data[param]

    default_solutions = domain_data['solutions']
    solutions_folder = input('Choose folder for your solutions [{}]'.format(
        default_solutions)).strip()
    if not solutions_folder:
        solutions_folder = default_solutions
    conf[domain_section]['solutions'] = solutions_folder

    if domain_data['game'] == 'eoc':
        default_source = domain_data['missions_source']
        source_folder = input(
            'Choose folder for your source missions [{}]'.format(
                default_source)).strip()
        if not source_folder:
            source_folder = default_source

        conf[domain_section]['source'] = source_folder

    conf.save()

    print('Config file {} was updated.'.format(conf.filename))
    print('Thank you')