def task_mode(args, optlist): if not args: ui.ocimatic_help(TASK_ACTIONS) (contest_dir, task_call) = filesystem.change_directory() if args[0] == 'new': new_task(args[1:]) elif args[0] in TASK_ACTIONS: contest = core.Contest(contest_dir) if ocimatic.config['task']: tasks = [contest.find_task(ocimatic.config['task'])] elif task_call: tasks = [contest.find_task(task_call.basename)] else: tasks = contest.tasks if not tasks: ui.show_message("Warning", "no tasks", ui.WARNING) action_name = args[0] args.pop(0) action = TASK_ACTIONS[action_name] kwargs = parseopt.kwargs_from_optlist(action, args, optlist) for task in tasks: getattr(task, action.get('method', action_name))(**kwargs) else: ui.fatal_error('Unknown action for task mode.') ui.ocimatic_help(TASK_ACTIONS)
def server_mode(args, optlist): if not args: ui.ocimatic_help(SERVER_ACTIONS) if args[0] in SERVER_ACTIONS: action_name = args[0] args.pop() action = SERVER_ACTIONS[action_name] kwargs = parseopt.kwargs_from_optlist(action, args, optlist) getattr(server, action.get('method', action_name))(**kwargs) else: ui.fatal_error('Unknown action for server mode.')
def dataset_mode(args, optlist): if not args: ui.ocimatic_help(DATASET_ACTIONS) if args[0] in DATASET_ACTIONS: action_name = args[0] args.pop() action = DATASET_ACTIONS[action_name] kwargs = parseopt.kwargs_from_optlist(action, args, optlist) dataset = core.Dataset(Directory.getcwd()) getattr(dataset, action.get('method', action_name))(**kwargs) else: ui.fatal_error('Unknown action for dataset mode.')
def contest_mode(args, optlist): if not args: ui.ocimatic_help(CONTEST_ACTIONS) if args[0] == "new": new_contest(args[1:], optlist) elif args[0] in CONTEST_ACTIONS: action_name = args[0] args.pop(0) action = CONTEST_ACTIONS[action_name] contest_dir = filesystem.change_directory()[0] contest = core.Contest(contest_dir) getattr(contest, action.get('method', action_name))() else: ui.fatal_error('Unknown action for contest mode.') ui.ocimatic_help(CONTEST_ACTIONS)
def main(): try: optlist, args = parseopt.gnu_getopt( sys.argv[1:], 'hvt:', ['help', 'task=', 'phase=', 'timeout='], TASK_ACTIONS, CONTEST_ACTIONS, DATASET_ACTIONS) except getopt.GetoptError as err: ui.fatal_error(str(err)) if not args: ui.ocimatic_help(TASK_ACTIONS) modes = { 'contest': (contest_mode, CONTEST_ACTIONS), 'task': (task_mode, TASK_ACTIONS), 'dataset': (dataset_mode, DATASET_ACTIONS), 'server': (server_mode, SERVER_ACTIONS), } # If no mode is provided we assume task if args[0] in modes: mode = args.pop(0) else: mode = 'task' # Process options for key, val in optlist.items(): if key == '-v': ocimatic.config['verbosity'] += 1 if key in ('--help', '-h'): ui.ocimatic_help(modes[mode][1]) elif key in ('--task', 't'): ocimatic.config['task'] = val elif key == '--timeout': ocimatic.config['timeout'] = float(val) # Select mode # try: if mode in modes: modes[mode][0](args, optlist) print() else: ui.fatal_error('Unknown mode.')
def main(): try: optlist, args = parseopt.gnu_getopt(sys.argv[1:], 'hvt:', ['help', 'task=', 'phase=', 'timeout='], TASK_ACTIONS, CONTEST_ACTIONS, DATASET_ACTIONS) except getopt.GetoptError as err: ui.fatal_error(str(err)) if not args: ui.ocimatic_help(TASK_ACTIONS) modes = { 'contest': (contest_mode, CONTEST_ACTIONS), 'task': (task_mode, TASK_ACTIONS), 'dataset': (dataset_mode, DATASET_ACTIONS), 'server': (server_mode, SERVER_ACTIONS), } # If no mode is provided we assume task if args[0] in modes: mode = args.pop(0) else: mode = 'task' # Process options for key, val in optlist.items(): if key == '-v': ocimatic.config['verbosity'] += 1 if key in ('--help', '-h'): ui.ocimatic_help(modes[mode][1]) elif key in ('--task', 't'): ocimatic.config['task'] = val elif key == '--timeout': ocimatic.config['timeout'] = float(val) # Select mode # try: if mode in modes: modes[mode][0](args, optlist) print() else: ui.fatal_error('Unknown mode.')