Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
    def run(self):
        (subtasks, cmds) = self.parse_file()

        for stn in range(1, subtasks + 1):
            dire = FilePath(self._dataset_directory, 'st%d' % stn).get_or_create_dir()
            dire.clear()

        if not cmds:
            ui.show_message("Warning", 'no commands were executed for the plan.', ui.WARNING)

        for (stn, subtask) in sorted(cmds.items()):
            self.run_subtask(stn, subtask)
Beispiel #4
0
def new_task(args):
    if not args:
        ui.fatal_error('You have to specify a name for the task.')
    name = args[0]
    try:
        contest_dir = filesystem.change_directory()[0]
        if contest_dir.find(name):
            ui.fatal_error('Cannot create task in existing directory.')
        core.Contest(contest_dir).new_task(name)
        ui.show_message('Info', 'Task [%s] created' % name)
    except Exception as exc:  # pylint: disable=broad-except
        ui.fatal_error('Couldn\'t create task: %s' % exc)
Beispiel #5
0
def new_task(args):
    if not args:
        ui.fatal_error('You have to specify a name for the task.')
    name = args[0]
    try:
        contest_dir = filesystem.change_directory()[0]
        if contest_dir.find(name):
            ui.fatal_error('Cannot create task in existing directory.')
        core.Contest(contest_dir).new_task(name)
        ui.show_message('Info', 'Task [%s] created' % name)
    except Exception as exc:  # pylint: disable=broad-except
        ui.fatal_error('Couldn\'t create task: %s' % exc)
Beispiel #6
0
 def validate_subtask(self, stn, subtask):
     validator = None
     if subtask['validator']:
         (validator, msg) = self.build_validator(subtask['validator'])
         if validator is None:
             ui.show_message('Warning', 'Failed to build validator: %s' % msg, ui.WARNING)
     else:
         ui.show_message('Info', 'No validator specified', ui.INFO)
     if validator:
         for (group, tests) in sorted(subtask['groups'].items()):
             for (i, _) in enumerate(tests, 1):
                 test_file = self.test_filepath(stn, group, i)
                 self.validate_test_input(test_file, validator)
Beispiel #7
0
    def run(self):
        (subtasks, cmds) = self.parse_file()

        for stn in range(1, subtasks + 1):
            dire = FilePath(self._dataset_directory,
                            'st%d' % stn).get_or_create_dir()
            dire.clear()

        if not cmds:
            ui.show_message("Warning",
                            'no commands were executed for the plan.',
                            ui.WARNING)

        for (stn, subtask) in sorted(cmds.items()):
            self.run_subtask(stn, subtask)
Beispiel #8
0
 def validate_subtask(self, stn, subtask):
     validator = None
     if subtask['validator']:
         (validator, msg) = self.build_validator(subtask['validator'])
         if validator is None:
             ui.show_message('Warning',
                             'Failed to build validator: %s' % msg,
                             ui.WARNING)
     else:
         ui.show_message('Info', 'No validator specified', ui.INFO)
     if validator:
         for (group, tests) in sorted(subtask['groups'].items()):
             for (i, _) in enumerate(tests, 1):
                 test_file = self.test_filepath(stn, group, i)
                 self.validate_test_input(test_file, validator)
Beispiel #9
0
def new_contest(args, optlist):
    if not args:
        ui.fatal_error('You have to specify a name for the contest.')
    name = args[0]

    contest_config = {}
    if '--phase' in optlist:
        contest_config['phase'] = optlist['--phase']

    try:
        cwd = Directory.getcwd()
        if cwd.find(name):
            ui.fatal_error("Couldn't create contest. Path already exists")
        contest_path = FilePath(cwd, name)
        core.Contest.create_layout(contest_path, contest_config)
        ui.show_message('Info', 'Contest [%s] created' % name)
    except Exception as exc:  # pylint: disable=broad-except
        ui.fatal_error("Couldn't create contest: %s." % exc)
Beispiel #10
0
def new_contest(args, optlist):
    if not args:
        ui.fatal_error('You have to specify a name for the contest.')
    name = args[0]

    contest_config = {}
    if '--phase' in optlist:
        contest_config['phase'] = optlist['--phase']

    try:
        cwd = Directory.getcwd()
        if cwd.find(name):
            ui.fatal_error("Couldn't create contest. Path already exists")
        contest_path = FilePath(cwd, name)
        core.Contest.create_layout(contest_path, contest_config)
        ui.show_message('Info', 'Contest [%s] created' % name)
    except Exception as exc:  # pylint: disable=broad-except
        ui.fatal_error("Couldn't create contest: %s." % exc)