Beispiel #1
0
def main():
    # because of calling inside of #!/usr/bin/
    call_args = sum(map(lambda a: shlex.split(a), sys.argv[1:]), [])
    args = parser.parse_args(call_args)

    logging.basicConfig(level=LEVELS[args.verbose])

    try:
        module = import_module('checkio_client.actions.' + args.module)
    except AttributeError:
        if not conf.exists():
            print('In order to start using CheckiO client')
            print('It should be configured first:')
            print()
            print('   $ checkio config')
            print()

        parser.print_help()
    else:
        if not getattr(args, 'config_not_required',
                       False) and apply_main_args(args):
            return
        if hasattr(args, 'func'):
            func_name = args.func
        else:
            func_name = 'main'
        getattr(module, func_name)(args)
Beispiel #2
0
def apply_main_args(args):
    try:
        conf.set_default_domain(args.domain)
    except ValueError as e:
        print(e)
        return True

    if not 'key' in conf.default_domain_data and conf.exists():
        print('Key for domain ' + conf.default_domain + ' is not defined')
        return True
Beispiel #3
0
def read_next_message():
    global conf
    text_length_bytes = sys.stdin.buffer.read(4)
    if len(text_length_bytes) == 0:
        sys.exit(0)

    text_length = struct.unpack('i', text_length_bytes)[0]
    text = sys.stdin.buffer.read(text_length).decode('utf-8')
    data = json.loads(text)

    conf = Config()
    if conf.exists():
        conf.open()

    return getattr(Actions, data['do'])(data)
Beispiel #4
0
def main():
    args = parser.parse_args()
    try:
        module = import_module('checkio_client.actions.' + args.module)
    except AttributeError:
        if not conf.exists():
            print('In order to start using CheckiO client')
            print('It should be configured first:')
            print()
            print('   $ checkio config')
            print()

        parser.print_help()
    else:
        if apply_main_args(args):
            return
        if hasattr(args, 'func'):
            func_name = args.func
        else:
            func_name = 'main'
        getattr(module, func_name)(args)