Beispiel #1
0
class Tasks(Visitor):
    def __init__(self, root_folder, root_context):
        Visitor.__init__(self)
        self.root_folder = root_folder
        self.root_context = root_context
        self.project = Project(name="Tasks")
        self.context = Context(name="Tasks")

    def end_project(self, item):
        for child in item.children:
            self.project.add_child(child)
        item.children = []

    def end_folder(self, item):
        if item == self.root_folder:
            self.root_folder.children = []
            self.root_folder.add_child(self.project)

    def end_context(self, item):
        if item != self.root_context:
            for child in item.children:
                if child.type == TASK:
                    self.context.add_child(child)
            item.children = []
        else:
            self.root_context.children = []
            self.root_context.add_child(self.context)

    def __str__(self):
        return "Tasks"
Beispiel #2
0
class Tasks (Visitor):
    def __init__(self, root_folder, root_context):
        Visitor.__init__(self)
        self.root_folder = root_folder
        self.root_context = root_context
        self.project = Project (name='Tasks')
        self.context = Context (name='Tasks')
    def end_project (self, item):
        for child in item.children:
            self.project.add_child(child)
        item.children = []
    def end_folder (self, item):
        if item == self.root_folder:
            self.root_folder.children = []
            self.root_folder.add_child(self.project)
    def end_context (self, item):
        if item != self.root_context:
            for child in item.children:
                if child.type == TASK:
                    self.context.add_child(child)
            item.children = []
        else:
            self.root_context.children = []
            self.root_context.add_child(self.context)
    def __str__ (self):
        return 'Tasks'
Beispiel #3
0
 def __init__(self, ofattribs):
     Context.__init__(self,
                      name=ofattribs['name'])
     self.ofattribs = ofattribs
     if 'persistentIdentifier' in ofattribs:
         self.link = 'omnifocus:///context/' + ofattribs['persistentIdentifier']
     self.status = u'inactive' if 'allowsNextAction' in ofattribs and ofattribs['allowsNextAction'] == 0 else u'active'
     logger.debug ('loaded context: %s %s', self.id, self.name)
Beispiel #4
0
 def test_ContextNameFilterVisitor_exclude(self):
     n1 = Context(name=u'n1')
     n2 = Context(name=u'n2 xxx')
     nodes = [n1, n2]
     visitor = ContextNameFilterVisitor('xxx', include=False)
     traverse_list(visitor, nodes)
     self.assertTrue(n1.marked)
     self.assertFalse(n2.marked)
Beispiel #5
0
    def test_ContextNameFilterVisitor_include_ignores_children(self):
        n1 = Context(name=u'n1 xxx')
        n2 = Context(name=u'n2')
        n1.add_child(n2)

        visitor = ContextNameFilterVisitor('xxx')
        traverse(visitor, n1)
        self.assertTrue(n1.marked)
        self.assertTrue(n2.marked)
Beispiel #6
0
 def test_ContextNameFilterVisitor_include_ignores_children (self):
     n1 = Context (name=u'n1 xxx')
     n2 = Context (name=u'n2')
     n1.add_child(n2)
     
     visitor = ContextNameFilterVisitor ('xxx')
     traverse (visitor, n1)
     self.assertTrue(n1.marked)
     self.assertTrue(n2.marked)
Beispiel #7
0
 def __init__(self, ofattribs):
     Context.__init__(self, name=ofattribs['name'])
     self.ofattribs = ofattribs
     self.order = ofattribs['rank']
     if 'persistentIdentifier' in ofattribs:
         self.id = ofattribs['persistentIdentifier']
         self.link = 'omnifocus:///context/' + ofattribs[
             'persistentIdentifier']
     self.status = u'inactive' if 'allowsNextAction' in ofattribs and ofattribs[
         'allowsNextAction'] == 0 else u'active'
     logger.debug('loaded context: %s %s', self.id, self.name)
 def test_traverse_context_when_not_marked (self):
     parent = Context (name=u'p')
     n1 = Task (name=u'n1')
     n2 = Task (name=u'n2')
     parent.children.append (n1)
     parent.children.append (n2)
     parent.marked = False
     
     visitor = DemoVisitor ()
     traverse (visitor, parent)
     self.assertEqual(0, len(visitor.tasks_started))
     self.assertEqual(0, len(visitor.contexts_started))
     self.assertEqual(0, len(visitor.tasks_ended))
     self.assertEqual(0, len(visitor.contexts_ended))
Beispiel #9
0
    def test_traverse_context_when_not_marked(self):
        parent = Context(name=u'p')
        n1 = Task(name=u'n1')
        n2 = Task(name=u'n2')
        parent.children.append(n1)
        parent.children.append(n2)
        parent.marked = False

        visitor = DemoVisitor()
        traverse(visitor, parent)
        self.assertEqual(0, len(visitor.tasks_started))
        self.assertEqual(0, len(visitor.contexts_started))
        self.assertEqual(0, len(visitor.tasks_ended))
        self.assertEqual(0, len(visitor.contexts_ended))
Beispiel #10
0
    def test_context_add_child(self):
        context = Context()
        child = Context()
        context.add_child(child)
        self.assertEquals(context, child.parent)

        context = Context()
        child = Task()
        context.add_child(child)
        self.assertEquals(context, child.context)
        self.assertEquals(None, child.parent)
Beispiel #11
0
    def test_traverse_list_contexts(self):
        n1 = Context(name=u'n1')
        n2 = Context(name=u'n2')
        nodes = [n1, n2]
        visitor = DemoVisitor()
        traverse_list(visitor, nodes)
        self.assertEqual(2, len(visitor.contexts_started))
        self.assertTrue(n1 in visitor.contexts_started)
        self.assertTrue(n2 in visitor.contexts_started)

        self.assertEqual(2, len(visitor.contexts_ended))
        self.assertTrue(n1 in visitor.contexts_ended)
        self.assertTrue(n2 in visitor.contexts_ended)

        self.assertEqual(0, len(visitor.tasks_started))
        self.assertEqual(0, len(visitor.projects_started))
        self.assertEqual(0, len(visitor.folders_started))
Beispiel #12
0
 def test_Scenario_4 (self):
     '''
     In context mode select a single deeply nested task for exclusion
     '''
     f1 = Folder (name='1')
     p1 = Project (name='2', parent=f1)
     t1 = Task (name='3', parent=p1)
     t2_selected = Task (name='xxx', parent=t1)
     t3 = Task (name='5', parent=t2_selected)
     t4 = Task (name='3', parent=t1)
     
     f2 = Folder (name='1', parent=f1)
     p2 = Project (name='2', parent=f2)
     t5 = Task (name='3', parent=p2)
     t6 = Task (name='3', parent=t5)
     t7 = Task (name='5', parent=t6)
     
     
     c1_on_path = Context (name='6')
     c2_on_path = Context (name='6', parent=c1_on_path)
     c2_on_path.add_child(t2_selected)
     
     c3 = Context (name='7', parent=c2_on_path)
     
     traverse_list (TaskNameFilterVisitor ('xxx', include=False), [c1_on_path], project_mode=False)
     
     self.assertTrue(f1.marked)
     self.assertTrue(p1.marked)
     self.assertTrue(t1.marked)
     self.assertFalse(t2_selected.marked)
     self.assertTrue(t3.marked)
     self.assertTrue(t4.marked)
     self.assertTrue(t5.marked)
     self.assertTrue(t6.marked)
     self.assertTrue(t7.marked)
     self.assertTrue(f2.marked)
     self.assertTrue(p2.marked)
     self.assertTrue(t5.marked)
     self.assertTrue(t6.marked)
     self.assertTrue(t7.marked)
     
     self.assertTrue(c1_on_path.marked)
     self.assertTrue(c2_on_path.marked)
     self.assertTrue(c3.marked)
Beispiel #13
0
 def test_Scenario_4 (self):
     '''
     In context mode select a single deeply nested task for exclusion
     '''
     f1 = Folder (name='1')
     p1 = Project (name='2', parent=f1)
     t1 = Task (name='3', parent=p1)
     t2_selected = Task (name='xxx', parent=t1)
     t3 = Task (name='5', parent=t2_selected)
     t4 = Task (name='3', parent=t1)
     
     f2 = Folder (name='1', parent=f1)
     p2 = Project (name='2', parent=f2)
     t5 = Task (name='3', parent=p2)
     t6 = Task (name='3', parent=t5)
     t7 = Task (name='5', parent=t6)
     
     
     c1_on_path = Context (name='6')
     c2_on_path = Context (name='6', parent=c1_on_path)
     c2_on_path.add_child(t2_selected)
     
     c3 = Context (name='7', parent=c2_on_path)
     
     traverse_list (Filter ([PROJECT, CONTEXT, TASK, FOLDER], lambda x: match_name(x, 'xxx'), False, 'pretty'), [c1_on_path], project_mode=False)
     
     self.assertTrue(f1.marked)
     self.assertTrue(p1.marked)
     self.assertTrue(t1.marked)
     self.assertFalse(t2_selected.marked)
     self.assertTrue(t3.marked)
     self.assertTrue(t4.marked)
     self.assertTrue(t5.marked)
     self.assertTrue(t6.marked)
     self.assertTrue(t7.marked)
     self.assertTrue(f2.marked)
     self.assertTrue(p2.marked)
     self.assertTrue(t5.marked)
     self.assertTrue(t6.marked)
     self.assertTrue(t7.marked)
     
     self.assertTrue(c1_on_path.marked)
     self.assertTrue(c2_on_path.marked)
     self.assertTrue(c3.marked)
Beispiel #14
0
def build_model (db):
    conn = sqlite3.connect(db)
    contexts = query (conn, clazz=OFContext)
    no_context = Context(name = 'No Context')
    inbox = Project (name='Inbox')
    project_infos = query (conn, clazz=ProjectInfo)
    folders = query (conn, clazz=OFFolder)
    tasks = query (conn, clazz=OFTask)
    
    projects = transmute_projects (project_infos, tasks)
    wire_projects_and_folders(projects, folders, tasks)
    wire_task_hierarchy(tasks)
    wire_tasks_to_enclosing_projects (project_infos, tasks, inbox)
    wire_tasks_and_contexts(contexts, tasks, no_context)
    wire_folder_hierarchy (folders)
    wire_context_hierarchy (contexts)
    
    conn.close ()
    
    # Find top level items
    project_roots = only_roots (projects.values())
    folder_roots = only_roots (folders.values())
    root_projects_and_folders = project_roots + folder_roots
    root_contexts = only_roots (contexts.values())
    root_contexts.insert(0, no_context)
    root_projects_and_folders.insert(0, inbox)
    sort(root_projects_and_folders)
    sort(root_contexts)
    
    root_folder = Folder (name='')
    for child in root_projects_and_folders:
        root_folder.add_child(child)
        
    root_context = Context (name='', status='active')
    for child in root_contexts:
        root_context.add_child(child)
        
    return root_folder, root_context
Beispiel #15
0
def build_model(db):
    conn = sqlite3.connect(db)
    contexts = query(conn, clazz=OFContext)
    no_context = Context(name='No Context')
    inbox = Project(name='Inbox')
    project_infos = query(conn, clazz=ProjectInfo)
    folders = query(conn, clazz=OFFolder)
    tasks = query(conn, clazz=OFTask)

    projects = transmute_projects(project_infos, tasks)
    wire_projects_and_folders(projects, folders, tasks)
    wire_task_hierarchy(tasks)
    wire_tasks_to_enclosing_projects(project_infos, tasks, inbox)
    wire_tasks_and_contexts(contexts, tasks, no_context)
    wire_folder_hierarchy(folders)
    wire_context_hierarchy(contexts)

    conn.close()

    # Find top level items
    project_roots = only_roots(projects.values())
    folder_roots = only_roots(folders.values())
    root_projects_and_folders = project_roots + folder_roots
    root_contexts = only_roots(contexts.values())
    root_contexts.insert(0, no_context)
    root_projects_and_folders.insert(0, inbox)
    sort(root_projects_and_folders)
    sort(root_contexts)

    root_folder = Folder(name='')
    for child in root_projects_and_folders:
        root_folder.add_child(child)

    root_context = Context(name='', status='active')
    for child in root_contexts:
        root_context.add_child(child)

    return root_folder, root_context
Beispiel #16
0
 def test_context_add_child (self):
     context = Context ()
     child = Context ()
     context.add_child (child)
     self.assertEquals(context, child.parent)
     
     context = Context ()
     child = Task ()
     context.add_child (child)
     self.assertEquals(context, child.context)
     self.assertEquals(None, child.parent)
Beispiel #17
0
    def test_Scenario_2(self):
        '''
        In project mode select a single deeply nested task for exclusion
        '''
        f_on_path = Folder(name='1')
        p_on_path = Project(name='2', parent=f_on_path)
        t1_on_path = Task(name='3', parent=p_on_path)
        t2_selected = Task(name='xxx', parent=t1_on_path)
        t3_on_path = Task(name='5', parent=t2_selected)
        t4 = Task(name='3', parent=t1_on_path)

        f = Folder(name='1', parent=f_on_path)
        p = Project(name='2', parent=f)
        t1 = Task(name='3', parent=p)
        t2 = Task(name='3', parent=t1)
        t3 = Task(name='5', parent=t2)

        c1 = Context(name='6')
        c1.add_child(t2_selected)

        c2 = Context(name='7')
        c2.add_child(t3)

        traverse_list(
            Filter([PROJECT, CONTEXT, TASK, FOLDER],
                   lambda x: match_name(x, 'xxx'), False, 'pretty'),
            [f_on_path])

        self.assertTrue(f_on_path.marked)
        self.assertTrue(p_on_path.marked)
        self.assertTrue(t1_on_path.marked)
        self.assertFalse(t2_selected.marked)
        self.assertFalse(t3_on_path.marked)

        self.assertTrue(c1.marked)
        self.assertTrue(c2.marked)

        self.assertTrue(f.marked)
        self.assertTrue(p.marked)
        self.assertTrue(t1.marked)
        self.assertTrue(t2.marked)
        self.assertTrue(t3.marked)
        self.assertTrue(t4.marked)
Beispiel #18
0
    def test_traverse_context(self):
        parent = Context(name=u'p')
        n1 = Task(name=u'n1')
        n2 = Task(name=u'n2')
        parent.children.append(n1)
        parent.children.append(n2)

        visitor = DemoVisitor()
        traverse(visitor, parent)
        self.assertEqual(2, len(visitor.tasks_started))
        self.assertEqual(1, len(visitor.contexts_started))
        self.assertTrue(parent in visitor.contexts_started)
        self.assertTrue(n1 in visitor.tasks_started)
        self.assertTrue(n2 in visitor.tasks_started)

        self.assertEqual(2, len(visitor.tasks_ended))
        self.assertEqual(1, len(visitor.contexts_ended))
        self.assertTrue(parent in visitor.contexts_ended)
        self.assertTrue(n1 in visitor.tasks_ended)
        self.assertTrue(n2 in visitor.tasks_ended)
Beispiel #19
0
    def test_Scenario_4(self):
        '''
        In context mode select a single deeply nested task for exclusion
        '''
        f1 = Folder(name='1')
        p1 = Project(name='2', parent=f1)
        t1 = Task(name='3', parent=p1)
        t2_selected = Task(name='xxx', parent=t1)
        t3 = Task(name='5', parent=t2_selected)
        t4 = Task(name='3', parent=t1)

        f2 = Folder(name='1', parent=f1)
        p2 = Project(name='2', parent=f2)
        t5 = Task(name='3', parent=p2)
        t6 = Task(name='3', parent=t5)
        t7 = Task(name='5', parent=t6)

        c1_on_path = Context(name='6')
        c2_on_path = Context(name='6', parent=c1_on_path)
        c2_on_path.add_child(t2_selected)

        c3 = Context(name='7', parent=c2_on_path)

        traverse_list(Filter([PROJECT, CONTEXT, TASK, FOLDER],
                             lambda x: match_name(x, 'xxx'), False, 'pretty'),
                      [c1_on_path],
                      project_mode=False)

        self.assertTrue(f1.marked)
        self.assertTrue(p1.marked)
        self.assertTrue(t1.marked)
        self.assertFalse(t2_selected.marked)
        self.assertTrue(t3.marked)
        self.assertTrue(t4.marked)
        self.assertTrue(t5.marked)
        self.assertTrue(t6.marked)
        self.assertTrue(t7.marked)
        self.assertTrue(f2.marked)
        self.assertTrue(p2.marked)
        self.assertTrue(t5.marked)
        self.assertTrue(t6.marked)
        self.assertTrue(t7.marked)

        self.assertTrue(c1_on_path.marked)
        self.assertTrue(c2_on_path.marked)
        self.assertTrue(c3.marked)
Beispiel #20
0
def load_from_json(json_data, item_db):
    if 'ref' in json_data:
        item = item_db[json_data['ref']]
        return item

    item_type = json_data['type']
    item_id = json_data['id']
    if item_type == FOLDER:
        item = Folder()
    elif item_type == CONTEXT:
        item = Context()
    elif item_type == TASK:
        item = Task()
    elif item_type == PROJECT:
        item = Project()
    load_attrib(item, 'id', json_data, lambda x: x)
    load_attrib(item, 'link', json_data, lambda x: x)
    load_attrib(item, 'status', json_data, lambda x: x)
    load_attrib(item, 'name', json_data, lambda x: x)
    load_attrib(item, 'date_completed', json_data,
                lambda x: datetime.strptime(x, TIME_FMT))
    load_attrib(item, 'date_to_start', json_data,
                lambda x: datetime.strptime(x, TIME_FMT))
    load_attrib(item, 'date_due', json_data,
                lambda x: datetime.strptime(x, TIME_FMT))
    load_attrib(item, 'flagged', json_data, lambda x: x)
    load_attrib(item, 'next', json_data, lambda x: x)
    load_attrib(item, 'note', json_data, lambda x: JSONNote(x))
    load_attrib(item, 'order', json_data, lambda x: x)

    for child_data in json_data['children']:
        child = load_from_json(child_data, item_db)
        item.add_child(child)

    item_db[item_id] = item
    return item
Beispiel #21
0
 def test_Scenario_2 (self):
     '''
     In project mode select a single deeply nested task for exclusion
     '''
     f_on_path = Folder (name='1')
     p_on_path = Project (name='2', parent=f_on_path)
     t1_on_path = Task (name='3', parent=p_on_path)
     t2_selected = Task (name='xxx', parent=t1_on_path)
     t3_on_path = Task (name='5', parent=t2_selected)
     t4 = Task (name='3', parent=t1_on_path)
     
     f = Folder (name='1', parent=f_on_path)
     p = Project (name='2', parent=f)
     t1 = Task (name='3', parent=p)
     t2 = Task (name='3', parent=t1)
     t3 = Task (name='5', parent=t2)
     
     c1 = Context (name='6')
     c1.add_child(t2_selected)
     
     c2 = Context (name='7')
     c2.add_child(t3)
     
     traverse_list (TaskNameFilterVisitor ('xxx', include=False), [f_on_path])
     
     self.assertTrue(f_on_path.marked)
     self.assertTrue(p_on_path.marked)
     self.assertTrue(t1_on_path.marked)
     self.assertFalse(t2_selected.marked)
     self.assertFalse(t3_on_path.marked)
     
     self.assertTrue(c1.marked)
     self.assertTrue(c2.marked)
     
     self.assertTrue(f.marked)
     self.assertTrue(p.marked)
     self.assertTrue(t1.marked)
     self.assertTrue(t2.marked)
     self.assertTrue(t3.marked)
     self.assertTrue(t4.marked)
Beispiel #22
0
 def test_Scenario_1 (self):
     '''
     In project mode select a single deeply nested task for inclusion
     '''
     f_on_path = Folder (name='1')
     p_on_path = Project (name='2', parent=f_on_path)
     t1_on_path = Task (name='3', parent=p_on_path)
     t2_selected = Task (name='xxx', parent=t1_on_path)
     t3_on_path = Task (name='5', parent=t2_selected)
     t4 = Task (name='3', parent=t1_on_path)
     
     f = Folder (name='1', parent=f_on_path)
     p = Project (name='2', parent=f)
     t1 = Task (name='3', parent=p)
     t2 = Task (name='3', parent=t1)
     t3 = Task (name='5', parent=t2)
     
     c1 = Context (name='6')
     c1.add_child(t2_selected)
     
     c2 = Context (name='7')
     c2.add_child(t3)
     
     traverse_list (Filter ([PROJECT, CONTEXT, TASK, FOLDER], lambda x: match_name(x, 'xxx'), True, 'pretty'), [f_on_path])
     
     self.assertTrue(f_on_path.marked)
     self.assertTrue(p_on_path.marked)
     self.assertTrue(t1_on_path.marked)
     self.assertTrue(t2_selected.marked)
     self.assertTrue(t3_on_path.marked)
     
     self.assertTrue(c1.marked)
     self.assertTrue(c2.marked)
     
     self.assertFalse(f.marked)
     self.assertFalse(p.marked)
     self.assertFalse(t1.marked)
     self.assertFalse(t2.marked)
     self.assertFalse(t3.marked)
     self.assertFalse(t4.marked)
Beispiel #23
0
 def __init__(self, root_folder, root_context):
     Visitor.__init__(self)
     self.root_folder = root_folder
     self.root_context = root_context
     self.project = Project(name="Tasks")
     self.context = Context(name="Tasks")
Beispiel #24
0
 def __init__(self, root_folder, root_context):
     Visitor.__init__(self)
     self.root_folder = root_folder
     self.root_context = root_context
     self.project = Project (name='Tasks')
     self.context = Context (name='Tasks')
Beispiel #25
0
 def __init__(self, ofattribs):
     Context.__init__(self,
                      name=ofattribs['name'])
     self.ofattribs = ofattribs
Beispiel #26
0
 def __init__(self, ofattribs):
     Context.__init__(self, name=ofattribs['name'])
     self.ofattribs = ofattribs