示例#1
0
def generate (out, root_project, root_context, project_mode, template_dir, type_config):
    # json has intrinsic formatting - no template required
    root_project.marked = True
    root_context.marked = True
    visitor = ConvertStructureToJsonVisitor ()
    traverse (visitor, root_project, project_mode=True)
    visitor = ConvertStructureToJsonVisitor ()
    traverse (visitor, root_context, project_mode=False)
    print >> out, json.dumps([root_project.attribs['json_data'], root_context.attribs['json_data']], sort_keys=True, indent=2)
示例#2
0
 def test_ProjectNameFilterVisitor_include_ignores_children (self):
     n1 = Project (name=u'n1 xxx')
     n2 = Task (name=u'n2')
     n1.add_child(n2)
     
     visitor = ProjectNameFilterVisitor ('xxx')
     traverse (visitor, n1)
     self.assertTrue(n1.marked)
     self.assertTrue(n2.marked)
示例#3
0
 def test_TaskNameFilterVisitor_include_ignores_children (self):
     n1 = Task (name=u'n1 xxx')
     n2 = Task (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)
示例#4
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)
示例#5
0
 def test_Sort_out_of__order (self):
     n1 = Task (name=u'b n1')
     n2 = Task (name=u'a n2')
     root = Project (name=u'r')
     root.add_child(n1)
     root.add_child(n2)
     
     visitor = Sort ([PROJECT], lambda x: x.name, 'pretty')
     traverse (visitor, root)
     self.assertIs(root.children[0], n2)
     self.assertIs(root.children[1], n1)
示例#6
0
 def test_Sort_same_use_underlying_order_out_of_order (self):
     n1 = Task (name=u'aaa', order=2)
     n2 = Task (name=u'aaa', order=1)
     root = Project (name=u'r')
     root.add_child(n1)
     root.add_child(n2)
     
     visitor = Sort ([PROJECT], lambda x: x.name, 'pretty')
     traverse (visitor, root)
     self.assertIs(root.children[0], n2)
     self.assertIs(root.children[1], n1)
示例#7
0
 def test_traverse_task_when_not_marked (self):
     parent = Task (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.tasks_ended))
示例#8
0
 def test_traverse_task (self):
     parent = Task (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(3, len(visitor.tasks_started))
     self.assertTrue(parent in visitor.tasks_started)
     self.assertTrue(n1 in visitor.tasks_started)
     self.assertTrue(n2 in visitor.tasks_started)
     
     self.assertEqual(3, len(visitor.tasks_ended))
     self.assertTrue(parent in visitor.tasks_ended)
     self.assertTrue(n1 in visitor.tasks_ended)
     self.assertTrue(n2 in visitor.tasks_ended)
示例#9
0
 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)
示例#10
0
    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)
示例#11
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)
示例#12
0
         subject = root_context
     elif '-P' == opt:
         logger.info ('project mode')
         project_mode = True
         subject = root_project
     elif '-I' == opt:
         logger.info ('include mode')
         include = True
     elif '-E' == opt:
         include = False
         logger.info ('exclude mode')
     
     logger.debug ("created filter %s", visitor)
     if visitor != None:
         logger.info ('running filter %s', visitor)
         traverse (visitor, subject, project_mode=project_mode)
         
 logger.info ('Generating: %s', file_name)
 
 if file_name != None:
     out=codecs.open(file_name, 'w', 'utf-8')
 else: 
     out = sys.stdout
 
 generated = False
 file_types = config['file_types']
 for type_config in file_types.values():
     if not generated and fmt in type_config['suffixes']:
         plugin = 'plugin_' + type_config['plugin']
         m = __import__(plugin)
         type_config.update (override_data)
示例#13
0
         subject = root_context
     elif '-P' == opt:
         logger.info ('project mode')
         project_mode = True
         subject = root_project
     elif '-I' == opt:
         logger.info ('include mode')
         include = True
     elif '-E' == opt:
         include = False
         logger.info ('exclude mode')
     
     logger.debug ("created filter %s", visitor)
     if visitor != None:
         logger.info ('running filter %s', visitor)
         traverse (visitor, subject, project_mode=project_mode)
         
 logger.info ('Generating: %s', file_name)
 
 if file_name != None:
     out=codecs.open(file_name, 'w', 'utf-8')
 else: 
     out = sys.stdout
 
 generated = False
 file_types = config['file_types']
 for type_config in file_types.values():
     if not generated and fmt in type_config['suffixes']:
         plugin = 'plugin_' + type_config['plugin']
         m = __import__(plugin)
         type_config.update (type_config_override_data)