示例#1
0
    def getModifiedTree(self, show_unmodified=False):
        """ Return tree of files returned by git status
    """
        path_dict = dict.fromkeys(self.git('ls-files').splitlines(), '')
        path_dict.update(self._patch_with_raw()[0])
        node_dict = {}
        path_list = path_dict.keys()
        for path in path_list:
            status = path_dict[path]
            parent = os.path.dirname(path)
            try:
                node_dict[parent].append(path)
            except KeyError:
                node_dict[parent] = [path]
                path_dict[parent] = status
                if parent:
                    path_list.append(parent)
            else:
                while path_dict.get(parent, status) != status:
                    path_dict[parent] = status = '*'
                    parent = os.path.dirname(parent)
        status_dict = {
            '*': 'normal',
            '': 'normal',
            'A': 'added',
            'D': 'deleted',
            'M': 'modified',
            'U': 'conflicted'
        }

        def dir_status(status):
            return status_dict[status in 'AD' and status or '']

        root = Dir(os.path.normpath(self.prefix), dir_status(path_dict['']))
        path_list = [(node_dict.pop(''), root)]
        for content, node in path_list:
            content.sort()
            for path in content:
                status = path_dict[path]
                if show_unmodified or status:
                    basename = os.path.basename(path)
                    try:
                        content = node_dict.pop(path)
                    except KeyError:
                        if status != 'M' or self.hasDiff(path):
                            node.sub_files.append(
                                File(basename, status_dict[status]))
                    else:
                        child = Dir(basename, dir_status(status))
                        node.sub_dirs.append(child)
                        path_list.append((content, child))
        return (root.sub_dirs or root.sub_files) and root
示例#2
0
 def getModifiedTree(self, show_unmodified=False):
     """ Return tree of files returned by svn status
 """
     # Business template root directory is the root of the tree
     root = Dir(os.path.basename(self.working_copy), "normal")
     something_modified = False
     # We browse the files returned by svn status
     for status_obj in self._getClient().status(path='', update=False):
         # can be (normal, added, modified, deleted, conflicted, unversioned)
         if str(status_obj.getReposTextStatus()) != 'none':
             status = "outdated"
         else:
             status = str(status_obj.getTextStatus())
             if status == "unversioned" or \
               status == "normal" and not show_unmodified:
                 continue
         path = status_obj.getPath()
         if path == '.':
             something_modified = True
             root.status = status
         elif status != "modified" or self.hasDiff(path):
             something_modified = True
             # Get object path
             dirname, basename = os.path.split(path)
             # Always start from root
             parent = root
             if dirname:
                 # First we add the directories present in the path to the tree
                 # if it does not already exist
                 for directory in dirname.split(os.sep):
                     try:
                         parent = parent[directory]
                     except KeyError:
                         child = Dir(directory, "normal")
                         parent.sub_dirs.append(child)
                         parent = child
             # Consider the whole path which can be a folder or a file
             # We add it the to the tree if it does not already exist
             if os.path.isdir(path):
                 parent.sub_dirs.append(Dir(basename, str(status)))
             else:
                 parent.sub_files.append(File(basename, str(status)))
     return something_modified and root