예제 #1
0
def sweep(fromFile, toFile):
    "Move finished tasks from the first filename to the second."
    todoList = parseTodoFile(fromFile)
    doneList = parseTodoFile(toFile)
    for task in todoList:
        # Move finished tasks
        if task.status in todo.doneStatuses:
            todoList.remove(task)
            doneList.append(task)
        # Copy date lines
        if task.lineNumber == 0:
            doneList.append(task)

    # Now merge the donefile, since it is probably somewhat messed up.
    merge([toFile])
예제 #2
0
def merge(filenames):
    "Iterate over files, parsing days, merging, sorting, uniquing"

    # Accumulate all the (no doubt duplicated) tasks
    combinedList = []
    for filename in filenames:
        combinedList += parseTodoFile(filename)

    # For tasks that are the same except for their status,
    # eliminate the less done version.
    taskDict = {}
    for task in combinedList:
        # Put task in a dictionary indexed by dateTime + text
        key = task.string(withLineNumber=True, fixedDate=True, withStatus=False)

        if key in taskDict.keys():
            # Task is already in dictionary so keep only the task with
            # the most finished state.
            oldTask = taskDict[key]
            debug("Dup: %s already in taskDict at %s" % (key, oldTask))
            debug("Old status is %s" % oldTask.status)
            debug("New status is %s" % task.status)
            # statusDict is ordered by doneness.  If the new status is
            # closer to done, replace the older, less done task.
            if statusDict[task.status] > statusDict[oldTask.status]:
                taskDict[key] = task
        else:
            # Haven't seen this one before
            taskDict[key] = task

    # Re-create taskList from the (now unique) dictionary values
    taskList = []
    for task in taskDict.values():
        taskList.append(task)

    # Sort them for printing
    sortedTasks = sorted(taskList, reverse=True)

    # Now print latest version of tasks (print a date on only the
    # tasks from line 0)

    printTaskList(sortedTasks, withLegend=True)