Ejemplo n.º 1
0
 def _createastchild(self, astnode):
     if hasattr(astnode, 'lineno'):
         if astnode.lineno - 1 in self.model.readlines:
             return
     if isinstance(astnode, _ast.Import) \
       or isinstance(astnode, _ast.ImportFrom):
         import_ = Import(None, [], astnode, self.model.buffer)
         import_.readlines = self.model.readlines
         self.model[str(import_.uuid)] = import_
     elif isinstance(astnode, _ast.FunctionDef):
         function = Function(None, astnode, self.model.buffer)
         function.readlines = self.model.readlines
         self.model[str(function.uuid)] = function
         for childastnode in astnode.body:
             function.parser._createastchild(childastnode)
         function.initdecorators()
     elif isinstance(astnode, _ast.ClassDef):
         class_ = Class(None, astnode, self.model.buffer)
         class_.readlines = self.model.readlines
         self.model[str(class_.uuid)] = class_
         for childastnode in astnode.body:
             class_.parser._createastchild(childastnode)
         class_.initdecorators()
     elif isinstance(astnode, _ast.Expr) \
       and isinstance(astnode.value, _ast.Str):
         docstring = Docstring(None, astnode, self.model.buffer)
         docstring.readlines = self.model.readlines
         self.model[str(docstring.uuid)] = docstring
     elif isinstance(astnode, _ast.Assign):
         if not IFunction.providedBy(self.model):
             attribute = Attribute([], None, astnode, self.model.buffer)
             attribute.readlines = self.model.readlines
             self.model[str(attribute.uuid)] = attribute
Ejemplo n.º 2
0
 def _createastchild(self, astnode):
     if hasattr(astnode, 'lineno'):
         if astnode.lineno - 1 in self.model.readlines:
             return
     if isinstance(astnode, _ast.Import) \
       or isinstance(astnode, _ast.ImportFrom):
         import_ = Import(None, [], astnode, self.model.buffer)
         import_.readlines = self.model.readlines
         self.model[str(import_.uuid)] = import_
     elif isinstance(astnode, _ast.FunctionDef):
         function = Function(None, astnode, self.model.buffer)
         function.readlines = self.model.readlines
         self.model[str(function.uuid)] = function
         for childastnode in astnode.body:
             function.parser._createastchild(childastnode)
         function.initdecorators()
     elif isinstance(astnode, _ast.ClassDef):
         class_ = Class(None, astnode, self.model.buffer)
         class_.readlines = self.model.readlines
         self.model[str(class_.uuid)] = class_
         for childastnode in astnode.body:
             class_.parser._createastchild(childastnode)
         class_.initdecorators()
     elif isinstance(astnode, _ast.Expr) \
       and isinstance(astnode.value, _ast.Str):
         docstring = Docstring(None, astnode, self.model.buffer)
         docstring.readlines = self.model.readlines
         self.model[str(docstring.uuid)] = docstring
     elif isinstance(astnode, _ast.Assign):
         if not IFunction.providedBy(self.model):
             attribute = Attribute([], None, astnode, self.model.buffer)
             attribute.readlines = self.model.readlines
             self.model[str(attribute.uuid)] = attribute
Ejemplo n.º 3
0
            #happens if the factory cannot be called without args (e.g. .pt)
            #in this case its no python file and doesnt have to be removed
            continue
        
        if not module.name.endswith('.py'):
            # XXX: thats perhaps not the perfect solution to sk
            continue
        if IDirectory.providedBy(module) \
          or module.name == '__init__.py' \
          or module in ignores:
            continue
        if len(module) > 1:
            continue
        if len(module):
            bl = module[module.keys()[0]]
            if IFunction.providedBy(bl):
               continue 
            if bl.lines != as_comment(get_copyright(source)):
                continue
        # dont throw away templates
        if ITemplate.providedBy(module) and module.template:
            continue
        del module.parent[module.name]


@handler('apiexporter', 'uml2fs', 'semanticsgenerator', 'api')
def apiexporter(self, source,target):
    """Takes classes with 'api' stereotype and imports them into 
    the pyegg's __init__.py.
    """
    egg = egg_source(source)