当前位置: 首页>>代码示例>>Python>>正文


Python Task.submission_format方法代码示例

本文整理汇总了Python中cms.db.Task.submission_format方法的典型用法代码示例。如果您正苦于以下问题:Python Task.submission_format方法的具体用法?Python Task.submission_format怎么用?Python Task.submission_format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cms.db.Task的用法示例。


在下文中一共展示了Task.submission_format方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_task

# 需要导入模块: from cms.db import Task [as 别名]
# 或者: from cms.db.Task import submission_format [as 别名]
    def get_task(self, get_statement=True):
        """See docstring in class TaskLoader."""
        name = os.path.split(self.path)[1]

        if (not os.path.exists(os.path.join(self.path, "task.yaml"))) and \
           (not os.path.exists(os.path.join(self.path, "..", name + ".yaml"))):
            logger.critical("File missing: \"task.yaml\"")
            return None

        # We first look for the yaml file inside the task folder,
        # and eventually fallback to a yaml file in its parent folder.
        try:
            conf = yaml.safe_load(
                io.open(os.path.join(self.path, "task.yaml"),
                        "rt", encoding="utf-8"))
        except IOError as err:
            try:
                deprecated_path = os.path.join(self.path, "..", name + ".yaml")
                conf = yaml.safe_load(io.open(deprecated_path, "rt",
                                              encoding="utf-8"))

                logger.warning("You're using a deprecated location for the "
                               "task.yaml file. You're advised to move %s to "
                               "%s.", deprecated_path,
                               os.path.join(self.path, "task.yaml"))
            except IOError:
                # Since both task.yaml and the (deprecated) "../taskname.yaml"
                # are missing, we will only warn the user that task.yaml is
                # missing (to avoid encouraging the use of the deprecated one)
                raise err

        # Here we update the time of the last import
        touch(os.path.join(self.path, ".itime"))
        # If this file is not deleted, then the import failed
        touch(os.path.join(self.path, ".import_error"))

        args = {}

        load(conf, args, ["name", "nome_breve"])
        load(conf, args, ["title", "nome"])

        if name != args["name"]:
            logger.info("The task name (%s) and the directory name (%s) are "
                        "different. The former will be used.", args["name"],
                        name)

        if args["name"] == args["title"]:
            logger.warning("Short name equals long name (title). "
                           "Please check.")

        name = args["name"]

        logger.info("Loading parameters for task %s.", name)

        if get_statement:
            primary_language = load(conf, None, "primary_language")
            if primary_language is None:
                primary_language = 'it'
            paths = [os.path.join(self.path, "statement", "statement.pdf"),
                     os.path.join(self.path, "testo", "testo.pdf")]
            for path in paths:
                if os.path.exists(path):
                    digest = self.file_cacher.put_file_from_path(
                        path,
                        "Statement for task %s (lang: %s)" %
                        (name, primary_language))
                    break
            else:
                logger.critical("Couldn't find any task statement, aborting.")
                sys.exit(1)
            args["statements"] = {
                primary_language: Statement(primary_language, digest)
            }

            args["primary_statements"] = [primary_language]

        args["submission_format"] = ["%s.%%l" % name]

        if conf.get("score_mode", None) == SCORE_MODE_MAX:
            args["score_mode"] = SCORE_MODE_MAX
        elif conf.get("score_mode", None) == SCORE_MODE_MAX_TOKENED_LAST:
            args["score_mode"] = SCORE_MODE_MAX_TOKENED_LAST

        # Use the new token settings format if detected.
        if "token_mode" in conf:
            load(conf, args, "token_mode")
            load(conf, args, "token_max_number")
            load(conf, args, "token_min_interval", conv=make_timedelta)
            load(conf, args, "token_gen_initial")
            load(conf, args, "token_gen_number")
            load(conf, args, "token_gen_interval", conv=make_timedelta)
            load(conf, args, "token_gen_max")
        # Otherwise fall back on the old one.
        else:
            logger.warning(
                "task.yaml uses a deprecated format for token settings which "
                "will soon stop being supported, you're advised to update it.")
            # Determine the mode.
            if conf.get("token_initial", None) is None:
                args["token_mode"] = TOKEN_MODE_DISABLED
#.........这里部分代码省略.........
开发者ID:ioi-germany,项目名称:cms,代码行数:103,代码来源:italy_yaml.py

示例2: get_task

# 需要导入模块: from cms.db import Task [as 别名]
# 或者: from cms.db.Task import submission_format [as 别名]
    def get_task(self, name):
        """See docstring in class Loader.

        """
        try:
            num = self.tasks_order[name]

        # Here we expose an undocumented behavior, so that cmsMake can
        # import a task even without the whole contest; this is not to
        # be relied upon in general
        except AttributeError:
            num = 1

        task_path = os.path.join(self.path, name)

        # We first look for the yaml file inside the task folder,
        # and eventually fallback to a yaml file in its parent folder.
        try:
            conf = yaml.safe_load(
                io.open(os.path.join(task_path, "task.yaml"),
                        "rt", encoding="utf-8"))
        except IOError:
            conf = yaml.safe_load(
                io.open(os.path.join(self.path, name + ".yaml"),
                        "rt", encoding="utf-8"))

        logger.info("Loading parameters for task %s." % name)

        # Here we update the time of the last import
        touch(os.path.join(task_path, ".itime"))
        # If this file is not deleted, then the import failed
        touch(os.path.join(task_path, ".import_error"))

        args = {}

        args["num"] = num
        load(conf, args, ["name", "nome_breve"])
        load(conf, args, ["title", "nome"])

        assert name == args["name"]

        if args["name"] == args["title"]:
            logger.warning("Short name equals long name (title). "
                           "Please check.")

        primary_language = load(conf, None, "primary_language")
        if primary_language is None:
            primary_language = 'it'
        paths = [os.path.join(task_path, "statement", "statement.pdf"),
                 os.path.join(task_path, "testo", "testo.pdf")]
        for path in paths:
            if os.path.exists(path):
                digest = self.file_cacher.put_file_from_path(
                    path,
                    "Statement for task %s (lang: %s)" % (name,
                                                          primary_language))
                break
        else:
            logger.critical("Couldn't find any task statement, aborting...")
            sys.exit(1)
        args["statements"] = [Statement(primary_language, digest)]

        args["primary_statements"] = '["%s"]' % (primary_language)

        args["attachments"] = []  # FIXME Use auxiliary

        args["submission_format"] = [
            SubmissionFormatElement("%s.%%l" % name)]

        # Use the new token settings format if detected.
        if "token_mode" in conf:
            load(conf, args, "token_mode")
            load(conf, args, "token_max_number")
            load(conf, args, "token_min_interval", conv=make_timedelta)
            load(conf, args, "token_gen_initial")
            load(conf, args, "token_gen_number")
            load(conf, args, "token_gen_interval", conv=make_timedelta)
            load(conf, args, "token_gen_max")
        # Otherwise fall back on the old one.
        else:
            logger.warning(
                "%s.yaml uses a deprecated format for token settings which "
                "will soon stop being supported, you're advised to update it.",
                name)
            # Determine the mode.
            if conf.get("token_initial", None) is None:
                args["token_mode"] = "disabled"
            elif conf.get("token_gen_number", 0) > 0 and \
                    conf.get("token_gen_time", 0) == 0:
                args["token_mode"] = "infinite"
            else:
                args["token_mode"] = "finite"
            # Set the old default values.
            args["token_gen_initial"] = 0
            args["token_gen_number"] = 0
            args["token_gen_interval"] = timedelta()
            # Copy the parameters to their new names.
            load(conf, args, "token_total", "token_max_number")
            load(conf, args, "token_min_interval", conv=make_timedelta)
            load(conf, args, "token_initial", "token_gen_initial")
#.........这里部分代码省略.........
开发者ID:dongockhanh1997,项目名称:cms,代码行数:103,代码来源:YamlLoader.py

示例3: get_task

# 需要导入模块: from cms.db import Task [as 别名]
# 或者: from cms.db.Task import submission_format [as 别名]
    def get_task(self, name):
        """See docstring in class Loader.

        """
        try:
            num = self.tasks_order[name]
        # Here we expose an undocumented behavior, so that cmsMake can
        # import a task even without the whole contest; this is not to
        # be relied upon in general
        except AttributeError:
            num = 1
        logger.info("Load task %s" % name)

        task_path = os.path.join(self.path, name)
        conf = {}
        try:
            conf = yaml.safe_load(
                io.open(os.path.join(task_path, "task.yaml"),
                        "rt", encoding="utf-8"))
        except IOError:
            if os.path.exists(os.path.join(task_path, name + ".yaml")):
                conf = yaml.safe_load(
                    io.open(os.path.join(task_path, name + ".yaml"),
                            "rt", encoding="utf-8"))
        args = {}

        args["num"] = num
        args["name"] = name
        args["title"] = name.title()
        primary_language = conf.get("task", {}).get("primary_language", "en")
        for path in os.listdir(os.path.join(task_path, "statement")):
            digest = self.file_cacher.put_file_from_path(
                os.path.join(task_path, "statement", path),
                "Statement for task %s (lang: %s)" % (name,
                                                      primary_language))
            break
        else:
            logger.critical("Couldn't find any task statement, aborting...")
            sys.exit(1)
        args["statements"] = [Statement(primary_language, digest)]
        args["primary_statements"] = '["%s"]' % (primary_language)
        args["submission_format"] = [
            SubmissionFormatElement("%s.%%l" % name)]
        args["token_mode"] = "disabled"
        
        args.update(self.token_mode)

        # Load attachments
        args["attachments"] = []
        if os.path.exists(os.path.join(task_path, "attachments")):
            for filename in os.listdir(os.path.join(task_path, "attachments")):
                digest = self.file_cacher.put_file_from_path(
                    os.path.join(task_path, "attachments", filename),
                    "Attachment %s for task %s" % (filename, name))
                args["attachments"] += [Attachment(filename, digest)]
        
        args.update(conf.get("task", {}))
        task = Task(**args)

        args = {}
        args["task"] = task
        args["description"] = "Default"
        args["autojudge"] = False
        args["time_limit"] = 2.0
        args["memory_limit"] = 256
        args["task_type"] = "Batch"
        args["score_type"] = "Sum"
        input_file = ""
        output_file = ""
        args["managers"] = []

        # Overwrite parameters
        for key, param in conf.iteritems():
            if key == "input":
                input_file = param
            elif key == "output":
                output_file = param
            elif key == "time_limit":
                args[key] = float(param)
            elif key in self.timedelta_params:
                args[key] = timedelta(seconds=param)
            elif key != "subtasks_parameters" and key != "subtasks" and key != "task":
                args[key] = param
        
        # Intelligent tests format detector
        # Load all tests recursively
        def load_tests(tests_path, name):
            if os.path.isfile(os.path.join(tests_path, name)):
                return [name]
            elif os.path.isdir(os.path.join(tests_path, name)):
                l = []
                for path in os.listdir(os.path.join(tests_path, name)):
                    l += load_tests(tests_path, os.path.join(name, path))
                return l
            else:
                return []
        full_names = load_tests(os.path.join(task_path, "tests"), "")
        tests_dict = dict((os.path.split(test)[-1], test)
                    for test in full_names)
        tests = []
#.........这里部分代码省略.........
开发者ID:zemen,项目名称:cms,代码行数:103,代码来源:SimpleLoader.py


注:本文中的cms.db.Task.submission_format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。