def test_parse_expr_accessing_missing_params(self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise('flagged'))[0] self.assertFalse(expr(Folder(name="aabbccdd"))) expr = parse_expr(tokenise('due=today'), now=tue)[0] self.assertFalse(expr(Folder(name="aabbccdd")))
def __init__(self, ofattribs): Folder.__init__(self, name=ofattribs['name']) self.ofattribs = ofattribs if 'persistentIdentifier' in ofattribs: self.link = 'omnifocus:///folder/' + ofattribs['persistentIdentifier'] logger.debug ('loaded folder: %s %s', self.id, self.name)
def test_bug_2013_04_27(self): expr = parse_expr(tokenise('(type=Folder) and !name=".*Folder 2"'))[0] self.assertTrue(expr(Folder(name="Miscellaneous"))) self.assertFalse(expr(Folder(name="xxx Folder 2"))) expr = parse_expr(tokenise('(type=Folder) and name!=".*Folder 2"'))[0] self.assertTrue(expr(Folder(name="Miscellaneous"))) self.assertFalse(expr(Folder(name="xxx Folder 2")))
def test_FolderNameFilterVisitor_include(self): n1 = Folder(name=u'n1') n2 = Folder(name=u'n2 xxx') nodes = [n1, n2] visitor = FolderNameFilterVisitor('xxx') traverse_list(visitor, nodes) self.assertFalse(n1.marked) self.assertTrue(n2.marked)
def test__include_ignores_children (self): n1 = Folder (name=u'n1 xxx') n2 = Folder (name=u'n2') n1.add_child(n2) visitor = Filter ([PROJECT, CONTEXT, TASK, FOLDER], lambda x: match_name(x, 'xxx'), True, 'pretty') traverse (visitor, n1) self.assertTrue(n1.marked) self.assertTrue(n2.marked)
def test_FolderNameFilterVisitor_include_ignores_children(self): n1 = Folder(name=u'n1 xxx') n2 = Folder(name=u'n2') n1.add_child(n2) visitor = FolderNameFilterVisitor('xxx') traverse(visitor, n1) self.assertTrue(n1.marked) self.assertTrue(n2.marked)
def test_exclude(self): n1 = Folder(name=u'n1') n2 = Folder(name=u'n2 xxx') nodes = [n1, n2] visitor = Filter([PROJECT, CONTEXT, TASK, FOLDER], lambda x: match_name(x, 'xxx'), False, 'pretty') traverse_list(visitor, nodes) self.assertTrue(n1.marked) self.assertFalse(n2.marked)
def test_FolderNameFilterVisitor_include_ignores_children (self): n1 = Folder (name=u'n1 xxx') n2 = Folder (name=u'n2') n1.add_child(n2) visitor = FolderNameFilterVisitor ('xxx') traverse (visitor, n1) self.assertTrue(n1.marked) self.assertTrue(n2.marked)
def __init__(self, ofattribs): Folder.__init__(self, name=ofattribs['name']) self.ofattribs = ofattribs self.order = ofattribs['rank'] if 'persistentIdentifier' in ofattribs: self.id = ofattribs['persistentIdentifier'] self.link = 'omnifocus:///folder/' + ofattribs[ 'persistentIdentifier'] logger.debug('loaded folder: %s %s', self.id, self.name)
def test_bug_2013_04_24(self): expr = parse_expr(tokenise('(type="Folder") and (name!="^Misc")'))[0] self.assertFalse(expr(Folder(name="Miscellaneous"))) expr = parse_expr(tokenise('(type="Project") and (name="Misc")'))[0] self.assertTrue(expr(Project(name="Miscellaneous"))) self.assertFalse(expr(Project(name="xxx"))) expr = parse_expr(tokenise('((type="Project") and (name="Misc"))'))[0] self.assertTrue(expr(Project(name="Miscellaneous"))) self.assertFalse(expr(Project(name="xxx"))) self.assertFalse(expr(Folder(name="Misc")))
def test__include_ignores_children(self): n1 = Folder(name=u'n1 xxx') n2 = Folder(name=u'n2') n1.add_child(n2) visitor = Filter([PROJECT, CONTEXT, TASK, FOLDER], lambda x: match_name(x, 'xxx'), True, 'pretty') traverse(visitor, n1) self.assertTrue(n1.marked) self.assertTrue(n2.marked)
def test_bug_2013_04_26(self): expr = parse_expr(tokenise('text=^Work$|^Miscellaneous$'))[0] self.assertFalse(expr(Folder(name="Misc"))) self.assertTrue(expr(Folder(name="Miscellaneous"))) expr = parse_expr(tokenise('(type=Folder)'))[0] self.assertTrue(expr(Folder(name="Miscellaneous"))) expr = parse_expr( tokenise('(type=Folder)and(text=^Work$|^Miscellaneous$)'))[0] self.assertFalse(expr(Folder(name="Misc"))) self.assertTrue(expr(Folder(name="Miscellaneous")))
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)
def test_traverse_list_folders(self): n1 = Folder(name=u'n1') n2 = Folder(name=u'n2') nodes = [n1, n2] visitor = DemoVisitor() traverse_list(visitor, nodes) self.assertEqual(2, len(visitor.folders_started)) self.assertTrue(n1 in visitor.folders_started) self.assertTrue(n2 in visitor.folders_started) self.assertEqual(2, len(visitor.folders_ended)) self.assertTrue(n1 in visitor.folders_ended) self.assertTrue(n2 in visitor.folders_ended) self.assertEqual(0, len(visitor.tasks_started)) self.assertEqual(0, len(visitor.projects_started)) self.assertEqual(0, len(visitor.contexts_started))
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)
def test_traverse_folder(self): parent = Folder(name=u'p') n1 = Project(name=u'n1') n2 = Folder(name=u'n2') parent.children.append(n1) parent.children.append(n2) visitor = DemoVisitor() traverse(visitor, parent) self.assertEqual(2, len(visitor.folders_started)) self.assertEqual(1, len(visitor.projects_started)) self.assertTrue(parent in visitor.folders_started) self.assertTrue(n1 in visitor.projects_started) self.assertTrue(n2 in visitor.folders_started) self.assertEqual(2, len(visitor.folders_ended)) self.assertEqual(1, len(visitor.projects_ended)) self.assertTrue(parent in visitor.folders_ended) self.assertTrue(n1 in visitor.projects_ended) self.assertTrue(n2 in visitor.folders_ended)
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
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
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
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
def __init__(self, ofattribs): Folder.__init__(self, name=ofattribs['name']) self.ofattribs = ofattribs