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


Python Task.time方法代码示例

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


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

示例1: read_tasks

# 需要导入模块: from task import Task [as 别名]
# 或者: from task.Task import time [as 别名]
 def read_tasks(cls, infile):
     tasks = []
     default_tz = pytz.utc
     for event, elem in etree.iterparse(infile, events=("start", "end")):
         if event == "start":
             if elem.tag == "defaults":
                 in_defaults = True
         else:
             # Stop reading as soon as the </tasks> tag is encountered.
             if elem.tag == "tasks":
                 break
             elif elem.tag == "defaults":
                 in_defaults = False
             # Otherwise, parse each <task> element in accordance to the way
             # it was output.
             elif elem.tag == "task":
                 attrs = elem.attrib
                 # XXX When project of a task becomes something more than
                 # just a string, the code will probably break on the
                 # following line.
                 if "project" in attrs:
                     project = attrs["project"]
                 else:
                     project = ""
                 task = Task(name=elem.text, project=project, id=int(attrs["id"]))
                 if "done" in attrs:
                     task.done = bool(int(attrs["done"]))
                 if "time" in attrs:
                     task.time = cls._timedelta_fromrepr(attrs["time"])
                 if "deadline" in attrs:
                     task.deadline = cls._read_time(attrs, "deadline", default_tz=default_tz)
                 tasks.append(task)
             elif elem.tag == "timezone" and in_defaults:
                 default_tz = pytz.timezone(elem.text)
     return tasks
开发者ID:RichardLitt,项目名称:wyrd-django-dev,代码行数:37,代码来源:xml.py

示例2: read_tasks

# 需要导入模块: from task import Task [as 别名]
# 或者: from task.Task import time [as 别名]
    def read_tasks(cls, infile):
        tasks = []
        default_tz = pytz.utc
        in_tasks = False
        in_groups = False
        in_defaults = False
        for event, elem in etree.iterparse(infile, events=('start', 'end')):
            if event == 'start':
                if elem.tag == 'defaults':
                    in_defaults = True
                elif elem.tag == 'tasks':
                    in_tasks = True
                    continue
                elif elem.tag == 'groups':
                    in_groups = True

            # if event == 'end':
            else:
                if elem.tag == 'defaults':
                    in_defaults = False
                elif elem.tag == "groups":
                    in_groups = False
                # Stop reading as soon as the </tasks> tag is encountered.
                elif elem.tag == "tasks":
                    break
                # Skip the subtree describing groupings.
                if in_groups:
                    continue
                elif in_tasks and elem.tag == "task":
                    # Otherwise, parse each <task> element in accordance to the
                    # way it was output.
                    attrs = elem.attrib
                    # XXX When project of a task becomes something more than
                    # just a string, the code will probably break on the
                    # following line.
                    if 'project' in attrs:
                        project = attrs['project']
                    else:
                        project = ''
                    task = Task(name=elem.text,
                                project=project,
                                id=int(attrs['id']))
                    if 'done' in attrs:
                        task.done = bool(int(attrs['done']))
                    if 'time' in attrs:
                        task.time = cls._timedelta_fromrepr(attrs['time'])
                    if 'deadline' in attrs:
                        task.deadline = cls._read_time(attrs, 'deadline',
                                                       default_tz=default_tz)
                    tasks.append(task)
                elif in_defaults and elem.tag == 'timezone':
                    default_tz = pytz.timezone(elem.text)
        return tasks
开发者ID:RichardLitt,项目名称:wyrd-core,代码行数:55,代码来源:xml.py

示例3: get_task

# 需要导入模块: from task import Task [as 别名]
# 或者: from task.Task import time [as 别名]
    def get_task(selection=None, ask_details=True):
        """ Asks the user for a task from a given selection or a new one.

        Keyword arguments:
        session -- the user session object
        selection -- a selection of tasks to choose from (default: anything)
        ask_details -- whether to ask the user for details, such as deadline
                       and estimated time

        """
        # Check that the selection is satisfiable.
        if selection is not None and not selection:
            raise ValueError("Cannot ask for a task from an empty selection.")

        task = None
        print("What is the task? ")
        if selection is not None:
            restricted = True
        else:
            selection = session.tasks
            restricted = False

        str2task = dict()
        int2task = dict()
        for task_index, a_task in enumerate(selection):
            # FIXME Distinguish between different tasks with the same string
            # representation.
            task_str = str(a_task)
            str2task[task_str] = a_task
            int2task[str(task_index)] = a_task
        if restricted:
            Cli.choosefrom(int2task)

        shown_selection = False
        taskname = input("> ")
        while not taskname or taskname == "?":
            if restricted:
                Cli.choosefrom(int2task)
            else:
                if selection:
                    shown_selection = True
                    Cli.choosefrom(int2task,
                                   msg="You can choose from the existing "
                                       "tasks:")
                else:
                    print("There are currently no tasks defined.")
            taskname = input("> ")
        # Should the task be one of existing Task tasks,
        if restricted:
            # Find the Task task.
            while taskname not in str2task and taskname not in int2task:
                if not taskname or taskname == "?":
                    Cli.choosefrom(int2task)
                else:
                    print("Sorry, this task was not on the menu. Try again.")
                taskname = input("> ")
            if taskname in int2task:
                task = int2task[taskname]
            else:
                task = str2task[taskname]
        # If we are asking for a new task,
        else:
            if shown_selection:
                if taskname in int2task:
                    task = int2task[taskname]
                elif taskname in str2task:
                    task = str2task[taskname]
            if task is None:
                # Create a new task, asking for optional details.
                project = Cli.get_project(
                    prompt="What project does it belong to?")
                task = Task(taskname, project)
                if ask_details:
                    print("Estimated time?")
                    time = input("> ").strip()
                    print("Deadline?")
                    deadline = input("> ").strip()
                    if time:
                        task.time = parse_timedelta(time)
                    if deadline:
                        task.deadline = parse_datetime(
                            deadline, tz=session.config['TIMEZONE'])
        return task
开发者ID:RichardLitt,项目名称:wyrd-core,代码行数:85,代码来源:cli.py


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