Пример #1
0
def python_tree(root_path='libbe', root_modname='libbe'):
    tree = Tree()
    tree.path = root_path
    tree.parent = None
    stack = [tree]
    while len(stack) > 0:
        f = stack.pop(0)
        if f.path.endswith('.py'):
            f.name = os.path.basename(f.path)[:-len('.py')]
        elif os.path.isdir(f.path) \
                and os.path.exists(os.path.join(f.path, '__init__.py')):
            f.name = os.path.basename(f.path)
            f.is_module = True
            for child in os.listdir(f.path):
                if child == '__init__.py':
                    continue
                c = Tree()
                c.path = os.path.join(f.path, child)
                c.parent = f
                stack.append(c)
        else:
            continue
        if f.parent == None:
            f.modname = root_modname
        else:
            f.modname = f.parent.modname + '.' + f.name
            f.parent.append(f)
    return tree
Пример #2
0
 def __init__(self, id, value=_EMPTY, parent=None, directory=False,
              children=None):
     if children == None:
         Tree.__init__(self)
     else:
         Tree.__init__(self, children)
     self.id = id
     self.value = value
     self.parent = parent
     if self.parent != None:
         if self.parent.directory == False:
             raise InvalidDirectory(
                 'Non-directory %s cannot have children' % self.parent)
         parent.append(self)
     self.directory = directory
Пример #3
0
 def __init__(self, id, value=_EMPTY, parent=None, directory=False,
              children=None):
     if children == None:
         Tree.__init__(self)
     else:
         Tree.__init__(self, children)
     self.id = id
     self.value = value
     self.parent = parent
     if self.parent != None:
         if self.parent.directory == False:
             raise InvalidDirectory(
                 'Non-directory %s cannot have children' % self.parent)
         parent.append(self)
     self.directory = directory
Пример #4
0
    def __init__(self,
                 bug=None,
                 uuid=None,
                 from_storage=False,
                 in_reply_to=None,
                 body=None,
                 content_type=None):
        """
        Set ``from_storage=True`` to load an old comment.
        Set ``from_storage=False`` to create a new comment.

        The ``uuid`` option is required when ``from_storage==True``.

        The in_reply_to, body, and content_type options are only used
        if ``from_storage==False`` (the default).  When
        ``from_storage==True``, they are loaded from the bug database.
        ``content_type`` decides if the body should be run through
        :py:func:`util.id.short_to_long_text` before saving.  See
        :py:meth:`_set_comment_body` for details.

        ``in_reply_to`` should be the uuid string of the parent comment.
        """
        Tree.__init__(self)
        settings_object.SavedSettingsObject.__init__(self)
        self.bug = bug
        self.storage = None
        self.uuid = uuid
        self.id = libbe.util.id.ID(self, 'comment')
        if from_storage == False:
            if uuid == None:
                self.uuid = libbe.util.id.uuid_gen()
            self.time = int(time.time())  # only save to second precision
            self.in_reply_to = in_reply_to
            if content_type != None:
                self.content_type = content_type
            self.body = body
        if self.bug != None:
            self.storage = self.bug.storage
        if from_storage == False:
            if self.storage != None and self.storage.is_writeable():
                self.save()
Пример #5
0
def python_tree(root_path='libbe', root_modname='libbe'):
    tree = Tree()
    tree.path = root_path
    tree.parent = None
    stack = [tree]
    while len(stack) > 0:
        f = stack.pop(0)
        if f.path.endswith('.py'):
            f.name = os.path.basename(f.path)[:-len('.py')]
        elif os.path.isdir(f.path) \
                and os.path.exists(os.path.join(f.path, '__init__.py')):
            f.name = os.path.basename(f.path)
            f.is_module = True
            for child in os.listdir(f.path):
                if child == '__init__.py':
                    continue
                c = Tree()
                c.path = os.path.join(f.path, child)
                c.parent = f
                stack.append(c)
        else:
            continue
        if f.parent == None:
            f.modname = root_modname
        else:
            f.modname = f.parent.modname + '.' + f.name
            f.parent.append(f)
    return tree
Пример #6
0
    def __init__(self, bug=None, uuid=None, from_storage=False,
                 in_reply_to=None, body=None, content_type=None):
        """
        Set ``from_storage=True`` to load an old comment.
        Set ``from_storage=False`` to create a new comment.

        The ``uuid`` option is required when ``from_storage==True``.

        The in_reply_to, body, and content_type options are only used
        if ``from_storage==False`` (the default).  When
        ``from_storage==True``, they are loaded from the bug database.
        ``content_type`` decides if the body should be run through
        :func:`util.id.short_to_long_text` before saving.  See
        :meth:`_set_comment_body` for details.

        ``in_reply_to`` should be the uuid string of the parent comment.
        """
        Tree.__init__(self)
        settings_object.SavedSettingsObject.__init__(self)
        self.bug = bug
        self.storage = None
        self.uuid = uuid
        self.id = libbe.util.id.ID(self, 'comment')
        if from_storage == False:
            if uuid == None:
                self.uuid = libbe.util.id.uuid_gen()
            self.time = int(time.time()) # only save to second precision
            self.in_reply_to = in_reply_to
            if content_type != None:
                self.content_type = content_type
            self.body = body
        if self.bug != None:
            self.storage = self.bug.storage
        if from_storage == False:
            if self.storage != None and self.storage.is_writeable():
                self.save()
Пример #7
0
 def traverse(self, *args, **kwargs):
     """Avoid working with the possible dummy root comment"""
     for comment in Tree.traverse(self, *args, **kwargs):
         if comment.uuid == INVALID_UUID:
             continue
         yield comment
Пример #8
0
 def traverse(self, *args, **kwargs):
     """Avoid working with the possible dummy root comment"""
     for comment in Tree.traverse(self, *args, **kwargs):
         if comment.uuid == INVALID_UUID:
             continue
         yield comment