Ejemplo n.º 1
0
 def test_include (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'), True, "pretty")
     traverse_list (visitor, nodes)
     self.assertFalse(n1.marked)
     self.assertTrue(n2.marked)
Ejemplo n.º 2
0
 def test_TaskNameFilterVisitor_exclude (self):
     n1 = Task (name=u'n1')
     n2 = Task (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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def test_ProjectNameFilterVisitor_include (self):
     n1 = Project (name=u'n1')
     n2 = Project (name=u'n2 xxx')
     nodes = [n1, n2]
     visitor = ProjectNameFilterVisitor ('xxx')
     traverse_list (visitor, nodes)
     self.assertFalse(n1.marked)
     self.assertTrue(n2.marked)
Ejemplo n.º 5
0
 def test_ProjectNameFilterVisitor_include(self):
     n1 = Project(name=u'n1')
     n2 = Project(name=u'n2 xxx')
     nodes = [n1, n2]
     visitor = ProjectNameFilterVisitor('xxx')
     traverse_list(visitor, nodes)
     self.assertFalse(n1.marked)
     self.assertTrue(n2.marked)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def test_TaskNameFilterVisitor_exclude(self):
     n1 = Task(name=u'n1')
     n2 = Task(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)
Ejemplo n.º 8
0
 def test_include(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'), True, "pretty")
     traverse_list(visitor, nodes)
     self.assertFalse(n1.marked)
     self.assertTrue(n2.marked)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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))
Ejemplo n.º 11
0
 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))
Ejemplo n.º 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 (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)
Ejemplo n.º 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 (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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
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)
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
    def end_context (self, context):
        self.depth-=1
    def print_link (self, link_type, item):
        ident = item.ofattribs['persistentIdentifier']
        print >>self.out, '<tr><td class="projectIcon"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" width="30px" height="30px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve"><g id="Your_Icon"><path fill="none" stroke="#B473FC" stroke-width="4" stroke-miterlimit="10" d="M90,20L30,80L10,60"/></g></svg></td><td class="taskName">' + self.escape(item.name) + '</td></tr>'
        # print >>self.out, self.spaces() + item.type + ': <a href="omnifocus:///' + link_type + '/' + ident + '">' + self.escape(item.name) + '</a><br>'
        # This happens on "No Context" - we fabricate it and it has no persistentIdentifier
        if 'persistentIdentifier' in item.ofattribs:
            ident = item.ofattribs['persistentIdentifier']
            print >>self.out, self.spaces() + item.type + ': <a href="omnifocus:///' + link_type + '/' + ident + '">' + self.escape(item.name) + '</a><br>'
    def spaces (self):
        return '&nbsp' * self.depth * self.indent
    def escape (self, val):
        return val.replace('"','&quot;').replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')

if __name__ == "__main__":
    root_projects_and_folders, root_contexts = build_model (find_database ())
    
    file_name=os.environ['HOME'] + '/Desktop/OF.html'
    
    out=codecs.open(file_name, 'w', 'utf-8')
    print >>out, '<head><title>Omnifocus</title></head><body>'
    traverse_list (PrintHtmlVisitor (out), root_projects_and_folders)
    print >>out, '<hr/>'
    
    traverse_list (PrintHtmlVisitor (out), root_contexts, project_mode=False)
    print >>out, '<hr/>'
    print >>out, '</body>'
    out.close()
    
    os.system("open '" + file_name + "'")
Ejemplo n.º 18
0
            '<', '&lt;').replace('>', '&gt;')


if __name__ == "__main__":

    root_projects_and_folders, root_contexts = build_model(find_database())

    file_name = os.environ['HOME'] + '/Desktop/OF.opml'

    out = codecs.open(file_name, 'w', 'utf-8')

    print >> out, '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
    print >> out, '<opml version="1.0">'
    print >> out, '  <head>'
    print >> out, '    <title>OmniFocus</title>'
    print >> out, '  </head>'
    print >> out, '  <body>'
    print >> out, '    <outline text="OmniFocus">'
    print >> out, '      <outline text="Projects">'
    traverse_list(PrintOpmlVisitor(out, depth=4), root_projects_and_folders)
    print >> out, '      </outline>'
    print >> out, '      <outline text="Contexts">'
    traverse_list(PrintOpmlVisitor(out, depth=4), root_contexts)
    print >> out, '      </outline>'
    print >> out, '    </outline>'
    print >> out, '  </body>'
    print >> out, '</opml>'

    out.close()

    os.system("open '" + file_name + "'")
Ejemplo n.º 19
0
            tags.append("@start(%Y-%m-%d)")
        if item.date_due != None:
            tags.append(item.date_due.strftime("@due(%Y-%m-%d)"))
        if item.context != None:
            tags.append('@' + ''.join(item.context.name.split()))
        if len(tags) > 0:
            return ' ' + ' '.join(tags)
        return ''

    def tabs(self):
        return '\t' * (self.depth)


if __name__ == "__main__":

    root_projects_and_folders, root_contexts = build_model(find_database())

    file_name = os.environ['HOME'] + '/Desktop/OF.taskpaper'

    out = codecs.open(file_name, 'w', 'utf-8')

    print >> out, 'Projects:'
    traverse_list(PrintTaskpaperVisitor(out, depth=1),
                  root_projects_and_folders)
    print >> out, 'Contexts:'
    traverse_list(PrintTaskpaperVisitor(out, depth=1), root_contexts)

    out.close()

    os.system("open '" + file_name + "'")
Ejemplo n.º 20
0
    def begin_project (self, project):
        self.generate_entry ('task', project)
    def begin_context (self, context):
        self.generate_entry ('context', context)
    def generate_entry (self, link_type, item):
        if 'persistentIdentifier' in item.ofattribs:
            ident = item.ofattribs['persistentIdentifier']
            link = 'omnifocus:///' + link_type + '/' + ident
            base = item.name.replace('/','_').replace('\\','/').replace('\.', '_')
            
            file_name=os.environ['HOME'] + '/Desktop/db/' + base + ' ' + ident + '.html'
            out=codecs.open(file_name, 'w', 'utf-8')
            link = 'omnifocus:///' + link_type + '/' + ident
            print >>out, '<html>'
            print >>out, '<head>'
            print >>out, '<meta http-equiv="refresh" content="0; url=' + link + '">'
            print >>out, '</head>'
            print >>out, '<body>'
            print >>out, '<p><a href="' + link + '">' + self.escape(item.name) + '</a>'
            print >>out, '</body>'
            print >>out, '</html>'
            out.close ()
    def escape (self, val):
        return val.replace('"','&quot;').replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')

if __name__ == "__main__":

    root_projects_and_folders, root_contexts = build_model (find_database ())
    
    traverse_list (GenerateTagDBVisitor (), root_projects_and_folders)
    traverse_list (GenerateTagDBVisitor (), root_contexts, project_mode=False)
Ejemplo n.º 21
0
 fmt = file_name[dot+1:]
 
 root_projects_and_folders, root_contexts = build_model (find_database ())
 
 if project_mode:
     items = root_projects_and_folders
 else:
     items = root_contexts
     
 for opt, arg in opts:
     
     # ANYTHING
     if '-i' == opt:
         visitor = AnyNameFilterVisitor (arg, include=True)
         print opt + '\t= ' + str (visitor)
         traverse_list (visitor, items)
     elif '-e' == opt:
         visitor = AnyNameFilterVisitor (arg, include=False)
         print opt + '\t= ' + str (visitor)
         traverse_list (visitor, items)
     elif '--Fi' == opt:
         visitor = AnyFlaggedFilterVisitor (include=True)
         print opt + '\t= ' + str (visitor)
         traverse_list (visitor, items)
     elif '--Fe' == opt:
         visitor = AnyFlaggedFilterVisitor (include=False)
         print opt + '\t= ' + str (visitor)
         traverse_list (visitor, items)
     
     # FOLDER
     elif '--fi' == opt:
Ejemplo n.º 22
0
def format_document(root, formatter, project_mode):
    if formatter.template.preamble != None:
        print >>formatter.out, formatter.template.preamble
    traverse_list(formatter, root.children, project_mode=project_mode)
    if formatter.template.postamble != None:
        print >>formatter.out, formatter.template.postamble
Ejemplo n.º 23
0
def print_structure(visitor, root_projects_and_folders, root_contexts,
                    project_mode):
    if project_mode:
        traverse_list(visitor, root_projects_and_folders)
    else:
        traverse_list(visitor, root_contexts)
Ejemplo n.º 24
0
        self.depth-=1
    def begin_context (self, context):
        print >>self.out, self.spaces() + '* Context: ' + context.name
        self.depth+=1
    def end_context (self, context):
        self.depth-=1
    def attribs (self, task):
        attribs = []
        if task.date_completed != None:
            attribs.append ('Done:' + task.date_completed.strftime ('%Y-%m-%d'))
        if task.flagged:
            attribs.append ('Flagged')
        if len (attribs) > 0:
            return ' ' +  ' '.join(attribs)
        return ''
    def spaces (self):
        return ' ' * self.depth * self.indent
    
if __name__ == "__main__":
    file_name=os.environ['HOME'] + '/Desktop/OF.txt'
    
    out=codecs.open(file_name, 'w', 'utf-8')
     
    visitor = PrintTextVisitor (out)
    root_projects_and_folders, root_contexts = build_model (find_database ())
    traverse_list (visitor, root_projects_and_folders)
    traverse_list (visitor, root_contexts)
        
    os.system("open '" + file_name + "'")
    
    out.close()
Ejemplo n.º 25
0
        self.task_depth = 0
        print >> self.out, ('#' * (self.header_depth + 1)) + ' ' + context.name
        self.header_depth += 1

    def end_context(self, context):
        print >> self.out
        self.header_depth -= 1

    def done(self, completed):
        if completed != None:
            return completed.strftime(" @%Y-%m-%d-%a")
        return ""


if __name__ == "__main__":

    root_projects_and_folders, root_contexts = build_model(find_database())

    file_name = os.environ['HOME'] + '/Desktop/OF.md'

    out = codecs.open(file_name, 'w', 'utf-8')

    print >> out, '# Projects:'
    traverse_list(PrintMarkdownVisitor(out, depth=1),
                  root_projects_and_folders)
    print >> out, '# Contexts:'
    traverse_list(PrintMarkdownVisitor(out, depth=1), root_contexts)

    out.close()

    os.system("open '" + file_name + "'")
Ejemplo n.º 26
0
        if item.flagged:
            tags.append ("@flagged")
        if item.date_to_start != None:
            tags.append(item.date_to_start.strftime("@start(%Y-%m-%d)"))
        if item.date_due != None:
            tags.append (item.date_due.strftime("@due(%Y-%m-%d)"))
        if item.context != None:
            tags.append ('@' + ''.join (item.context.name.split ()))
        if len (tags) > 0:
            return ' ' + ' '.join(tags)
        return ''
    def tabs (self):
        return '\t' * (self.depth)

if __name__ == "__main__":

    root_projects_and_folders, root_contexts = build_model (find_database ())
    
    file_name=os.environ['HOME'] + '/Desktop/OF.taskpaper'
    
    out=codecs.open(file_name, 'w', 'utf-8')
    
    print >>out, 'Projects:'
    traverse_list (PrintTaskpaperVisitor (out, depth=1), root_projects_and_folders)
    print >>out, 'Contexts:'
    traverse_list (PrintTaskpaperVisitor (out, depth=1), root_contexts)
    
    out.close()
    
    os.system("open '" + file_name + "'")
Ejemplo n.º 27
0
def format_document(root, formatter, project_mode):
    if formatter.template.preamble != None:
        print >> formatter.out, formatter.template.preamble
    traverse_list(formatter, root.children, project_mode=project_mode)
    if formatter.template.postamble != None:
        print >> formatter.out, formatter.template.postamble
Ejemplo n.º 28
0
    def begin_project (self, project):
        self.generate_entry ('task', project)
    def begin_context (self, context):
        self.generate_entry ('context', context)
    def generate_entry (self, link_type, item):
        if 'persistentIdentifier' in item.ofattribs:
            ident = item.ofattribs['persistentIdentifier']
            link = 'omnifocus:///' + link_type + '/' + ident
            base = item.name.replace('/','_').replace('\\','/').replace('\.', '_')
            
            file_name=os.environ['HOME'] + '/Desktop/db/' + base + ' ' + ident + '.html'
            out=codecs.open(file_name, 'w', 'utf-8')
            link = 'omnifocus:///' + link_type + '/' + ident
            print >>out, '<html>'
            print >>out, '<head>'
            print >>out, '<meta http-equiv="refresh" content="0; url=' + link + '">'
            print >>out, '</head>'
            print >>out, '<body>'
            print >>out, '<p><a href="' + link + '">' + self.escape(item.name) + '</a>'
            print >>out, '</body>'
            print >>out, '</html>'
            out.close ()
    def escape (self, val):
        return val.replace('"','&quot;').replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')

if __name__ == "__main__":

    root_projects_and_folders, root_contexts = build_model (find_database ())
    
    traverse_list (GenerateTagDBVisitor (), root_projects_and_folders)
    traverse_list (GenerateTagDBVisitor (), root_contexts, project_mode=False)
Ejemplo n.º 29
0
        if item.context != None:
            tags.append ('@' + ''.join (item.context.name.split ()))
        if len (tags) > 0:
            return ' ' + ' '.join(tags)
        return ''
    def remove_trailing_colon (self, string):
        if string.endswith(':'):
            return string[:-1]
        return string
    def is_empty (self, item):
        return len ([x for x in item.children if x.marked]) == 0
    def tabs (self):
        return '\t' * (self.depth)

if __name__ == "__main__":

    root_projects_and_folders, root_contexts = build_model (find_database ())
    
    file_name=os.environ['HOME'] + '/Desktop/OF.taskpaper'
    
    out=codecs.open(file_name, 'w', 'utf-8')
    
    print >>out, 'Projects:'
    traverse_list (PrintTaskpaperVisitor (out, True, depth=1), root_projects_and_folders)
    print >>out, 'Contexts:'
    traverse_list (PrintTaskpaperVisitor (out, False, depth=1), root_contexts, project_mode=False)
    
    out.close()
    
    os.system("open '" + file_name + "'")
Ejemplo n.º 30
0
    fmt = file_name[dot + 1:]

    root_projects_and_folders, root_contexts = build_model(find_database())

    if project_mode:
        items = root_projects_and_folders
    else:
        items = root_contexts

    for opt, arg in opts:

        # FOLDER
        if '--fi' == opt:
            visitor = FolderNameFilterVisitor(arg, include=True)
            print opt + '\t= ' + str(visitor)
            traverse_list(visitor, items)
        elif '--fe' == opt:
            visitor = FolderNameFilterVisitor(arg, include=False)
            print opt + '\t= ' + str(visitor)
            traverse_list(visitor, items)

        # PROJECT
        elif '--pi' == opt:
            visitor = ProjectNameFilterVisitor(arg, include=True)
            print opt + '\t= ' + str(visitor)
            traverse_list(visitor, items)
        elif '--pe' == opt:
            visitor = ProjectNameFilterVisitor(arg, include=False)
            print opt + '\t= ' + str(visitor)
            traverse_list(visitor, items)
        elif '--psi' == opt:
Ejemplo n.º 31
0
        self.depth -= 1

    def print_link(self, link_type, item):
        ident = item.ofattribs['persistentIdentifier']
        print >> self.out, '<tr><td class="projectIcon"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" width="30px" height="30px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve"><g id="Your_Icon"><path fill="none" stroke="#B473FC" stroke-width="4" stroke-miterlimit="10" d="M90,20L30,80L10,60"/></g></svg></td><td class="taskName">' + self.escape(
            item.name) + '</td></tr>'
        # print >>self.out, self.spaces() + item.type + ': <a href="omnifocus:///' + link_type + '/' + ident + '">' + self.escape(item.name) + '</a><br>'
    def spaces(self):
        return '&nbsp' * self.depth * self.indent

    def escape(self, val):
        return val.replace('"', '&quot;').replace('&', '&amp;').replace(
            '<', '&lt;').replace('>', '&gt;')


if __name__ == "__main__":
    root_projects_and_folders, root_contexts = build_model(find_database())

    file_name = os.environ['HOME'] + '/Desktop/OF.html'

    out = codecs.open(file_name, 'w', 'utf-8')
    print >> out, '<head><title>Omnifocus</title></head><body>'
    traverse_list(PrintHtmlVisitor(out), root_projects_and_folders)
    print >> out, '<hr/>'

    traverse_list(PrintHtmlVisitor(out), root_contexts)
    print >> out, '<hr/>'
    print >> out, '</body>'
    out.close()

    os.system("open '" + file_name + "'")
Ejemplo n.º 32
0
    def escape (self, val):
        return val.replace('"','&quot;').replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')

if __name__ == "__main__":

    root_projects_and_folders, root_contexts = build_model (find_database ())
    
    file_name=os.environ['HOME'] + '/Desktop/OF.opml'
    
    out=codecs.open(file_name, 'w', 'utf-8')
    
    print >>out, '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
    print >>out, '<opml version="1.0">'
    print >>out, '  <head>'
    print >>out, '    <title>OmniFocus</title>'
    print >>out, '  </head>'
    print >>out, '  <body>'
    print >>out, '    <outline text="OmniFocus">'
    print >>out, '      <outline text="Projects">'
    traverse_list (PrintOpmlVisitor (out, depth=4), root_projects_and_folders)
    print >>out, '      </outline>'
    print >>out, '      <outline text="Contexts">'
    traverse_list (PrintOpmlVisitor (out, depth=4), root_contexts, project_mode=False)
    print >>out, '      </outline>'
    print >>out, '    </outline>'
    print >>out, '  </body>'
    print >>out, '</opml>'
    
    out.close()
    
    os.system("open '" + file_name + "'")
Ejemplo n.º 33
0
 for opt, arg in opts:
     
     # PROJECT MODE
     if '-P' == opt:
         project_mode = True
         items = root_contexts
     # CONTEXT MODE
     elif '-C' == opt:
         project_mode = False
         items = root_contexts
     
     # ANYTHING
     if '-i' == opt:
         visitor = AnyNameFilterVisitor (arg, include=True)
         print opt + '\t= ' + str (visitor)
         traverse_list (visitor, items, project_mode=project_mode)
     elif '-e' == opt:
         visitor = AnyNameFilterVisitor (arg, include=False)
         print opt + '\t= ' + str (visitor)
         traverse_list (visitor, items, project_mode=project_mode)
     elif '--Fi' == opt:
         visitor = AnyFlaggedFilterVisitor (include=True)
         print opt + '\t= ' + str (visitor)
         traverse_list (visitor, items, project_mode=project_mode)
     elif '--Fe' == opt:
         visitor = AnyFlaggedFilterVisitor (include=False)
         print opt + '\t= ' + str (visitor)
         traverse_list (visitor, items, project_mode=project_mode)
     
     # FOLDER
     elif '--fi' == opt:
Ejemplo n.º 34
0
        self.task_depth+=1
    def end_task (self, task):
        self.task_depth-=1
    def begin_context (self, context):
        self.task_depth = 0
        print >>self.out, ('#' * (self.header_depth+1)) + ' ' + context.name
        self.header_depth+=1
    def end_context (self, context):
        print >>self.out
        self.header_depth-=1
    def done (self, completed):
        if completed != None:
            return completed.strftime(" @%Y-%m-%d-%a")
        return ""

if __name__ == "__main__":

    root_projects_and_folders, root_contexts = build_model (find_database ())
    
    file_name=os.environ['HOME'] + '/Desktop/OF.md'
    
    out=codecs.open(file_name, 'w', 'utf-8')
    
    print >>out, '# Projects:'
    traverse_list (PrintMarkdownVisitor (out, depth=1), root_projects_and_folders)
    print >>out, '# Contexts:'
    traverse_list (PrintMarkdownVisitor (out, depth=1), root_contexts, project_mode=False)
    
    out.close()
    
    os.system("open '" + file_name + "'")
Ejemplo n.º 35
0
def print_structure (visitor, root_projects_and_folders, root_contexts, project_mode):
    if project_mode:
        traverse_list (visitor, root_projects_and_folders)
    else:
        traverse_list (visitor, root_contexts, project_mode=False)