コード例 #1
0
ファイル: plugin_json.py プロジェクト: alainyog/ofexport
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
コード例 #2
0
ファイル: visitors_test.py プロジェクト: tmarkiewicz/ofexport
 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)
コード例 #3
0
    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)
コード例 #4
0
 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)
コード例 #5
0
ファイル: visitors_test.py プロジェクト: prateek/ofexport
    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)
コード例 #6
0
ファイル: omnifocus.py プロジェクト: scfcode/ofexport
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
コード例 #7
0
ファイル: omnifocus.py プロジェクト: prateek/ofexport
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
コード例 #8
0
ファイル: plugin_json.py プロジェクト: prateek/ofexport
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