示例#1
0
文件: views.py 项目: catseye/klaus
    def make_template_context(self, repo, rev, path):
        repo, rev, path, commit = _get_repo_and_rev(repo, rev, path)

        try:
            submodule_rev = tree_lookup_path(repo.__getitem__, commit.tree,
                                             encode_for_git(path))[1]
        except KeyError:
            raise NotFound("Parent path for submodule missing")

        try:
            (submodule_url,
             submodule_path) = _get_submodule(repo, commit,
                                              encode_for_git(path))
        except KeyError:
            submodule_url = None
            submodule_path = None

        # TODO(jelmer): Rather than printing an information page,
        # redirect to the page in klaus for the repository at
        # submodule_path, revision submodule_rev.

        self.context = {
            'view': self.view_name,
            'repo': repo,
            'rev': rev,
            'commit': commit,
            'branches': repo.get_branch_names(exclude=rev),
            'tags': repo.get_tag_names(),
            'path': path,
            'subpaths': list(subpaths(path)) if path else None,
            'submodule_url': force_unicode(submodule_url),
            'submodule_path': force_unicode(submodule_path),
            'submodule_rev': force_unicode(submodule_rev),
            'base_href': None,
        }
示例#2
0
文件: views.py 项目: wsldankers/klaus
    def make_template_context(self, repo, namespace, rev, path):
        repo, rev, path, commit = _get_repo_and_rev(repo, namespace, rev, path)

        try:
            submodule_rev = tree_lookup_path(repo.__getitem__, commit.tree,
                                             encode_for_git(path))[1]
        except KeyError:
            raise NotFound("Parent path for submodule missing")

        try:
            (submodule_url,
             submodule_path) = _get_submodule(repo, commit,
                                              encode_for_git(path))
        except KeyError:
            submodule_url = None
            submodule_path = None

        # TODO(jelmer): Rather than printing an information page,
        # redirect to the page in klaus for the repository at
        # submodule_path, revision submodule_rev.

        self.context = {
            "view": self.view_name,
            "repo": repo,
            "rev": rev,
            "commit": commit,
            "branches": repo.get_branch_names(exclude=rev),
            "tags": repo.get_tag_names(),
            "path": path,
            "subpaths": list(subpaths(path)) if path else None,
            "submodule_url": force_unicode(submodule_url),
            "submodule_path": force_unicode(submodule_path),
            "submodule_rev": force_unicode(submodule_rev),
            "base_href": None,
        }
示例#3
0
文件: views.py 项目: jonashaag/klaus
    def make_template_context(self, repo, rev, path):
        repo, rev, path, commit = _get_repo_and_rev(repo, rev, path)

        try:
            submodule_rev = tree_lookup_path(
                repo.__getitem__, commit.tree, encode_for_git(path))[1]
        except KeyError:
            raise NotFound("Parent path for submodule missing")

        try:
            (submodule_url, submodule_path) = _get_submodule(
                repo, commit, encode_for_git(path))
        except KeyError:
            submodule_url = None
            submodule_path = None

        # TODO(jelmer): Rather than printing an information page,
        # redirect to the page in klaus for the repository at
        # submodule_path, revision submodule_rev.

        self.context = {
            'view': self.view_name,
            'repo': repo,
            'rev': rev,
            'commit': commit,
            'branches': repo.get_branch_names(exclude=rev),
            'tags': repo.get_tag_names(),
            'path': path,
            'subpaths': list(subpaths(path)) if path else None,
            'submodule_url': force_unicode(submodule_url),
            'submodule_path': force_unicode(submodule_path),
            'submodule_rev': force_unicode(submodule_rev),
            'base_href': None,
        }
示例#4
0
文件: repo.py 项目: jonashaag/klaus
    def listdir(self, commit, path):
        """Return a list of submodules, directories and files in given
        directory: Lists of (link name, target path) tuples.
        """
        submodules, dirs, files = [], [], []
        for entry_rel in self.get_blob_or_tree(commit, path).items():
            # entry_rel: Entry('foo.txt', ...)
            # entry_abs: Entry('spam/eggs/foo.txt', ...)
            entry_abs = entry_rel.in_path(encode_for_git(path))
            path_str = decode_from_git(entry_abs.path)
            item = (os.path.basename(path_str), path_str)
            if S_ISGITLINK(entry_abs.mode):
                submodules.append(item)
            elif stat.S_ISDIR(entry_abs.mode):
                dirs.append(item)
            else:
                files.append(item)

        keyfunc = lambda tpl: tpl[0].lower()
        submodules.sort(key=keyfunc)
        files.sort(key=keyfunc)
        dirs.sort(key=keyfunc)

        if path:
            dirs.insert(0, ('..', parent_directory(path)))

        return {'submodules': submodules, 'dirs' : dirs, 'files' : files}
示例#5
0
文件: repo.py 项目: momodel/klaus
    def listdir(self, commit, path):
        """Return a list of submodules, directories and files in given
        directory: Lists of (link name, target path) tuples.
        """
        submodules, dirs, files = [], [], []
        for entry_rel in self.get_blob_or_tree(commit, path).items():
            # entry_rel: Entry('foo.txt', ...)
            # entry_abs: Entry('spam/eggs/foo.txt', ...)
            entry_abs = entry_rel.in_path(encode_for_git(path))
            path_str = decode_from_git(entry_abs.path)
            item = (os.path.basename(path_str), path_str)
            if S_ISGITLINK(entry_abs.mode):
                submodules.append(item)
            elif stat.S_ISDIR(entry_abs.mode):
                dirs.append(item)
            else:
                files.append(item)

        keyfunc = lambda tpl: tpl[0].lower()
        submodules.sort(key=keyfunc)
        files.sort(key=keyfunc)
        dirs.sort(key=keyfunc)

        if path:
            dirs.insert(0, ('..', parent_directory(path)))

        return {'submodules': submodules, 'dirs': dirs, 'files': files}
示例#6
0
文件: repo.py 项目: momodel/klaus
 def get_blob_or_tree(self, commit, path):
     """Return the Git tree or blob object for `path` at `commit`."""
     try:
         (mode, oid) = tree_lookup_path(self.__getitem__, commit.tree,
                                        encode_for_git(path))
     except NotTreeError:
         # Some part of the path was a file where a folder was expected.
         # Example: path="/path/to/foo.txt" but "to" is a file in "/path".
         raise KeyError
     return self[oid]
示例#7
0
文件: repo.py 项目: jonashaag/klaus
 def get_blob_or_tree(self, commit, path):
     """Return the Git tree or blob object for `path` at `commit`."""
     try:
         (mode, oid) = tree_lookup_path(self.__getitem__, commit.tree,
                                        encode_for_git(path))
     except NotTreeError:
         # Some part of the path was a file where a folder was expected.
         # Example: path="/path/to/foo.txt" but "to" is a file in "/path".
         raise KeyError
     return self[oid]
示例#8
0
 def get_commit(self, rev):
     for prefix in ['refs/heads/', 'refs/tags/', '']:
         key = prefix + rev
         try:
             obj = self[encode_for_git(key)]
             if isinstance(obj, dulwich.objects.Tag):
                 obj = self[obj.object[1]]
             return obj
         except KeyError:
             pass
     raise KeyError(rev)
示例#9
0
 def get_blob_or_tree(self, commit, path):
     """ Returns the Git tree or blob object for `path` at `commit`. """
     tree_or_blob = self[commit.tree]  # Still a tree here but may turn into
                                       # a blob somewhere in the loop.
     for part in path.strip('/').split('/'):
         if part:
             if isinstance(tree_or_blob, dulwich.objects.Blob):
                 # Blobs don't have sub-files/folders.
                 raise KeyError
             tree_or_blob = self[tree_or_blob[encode_for_git(part)][1]]
     return tree_or_blob
示例#10
0
文件: repo.py 项目: johnko/klaus
 def get_blob_or_tree(self, commit, path):
     """Return the Git tree or blob object for `path` at `commit`."""
     tree_or_blob = self[commit.tree]  # Still a tree here but may turn into
                                       # a blob somewhere in the loop.
     for part in path.strip('/').split('/'):
         if part:
             if isinstance(tree_or_blob, dulwich.objects.Blob):
                 # Blobs don't have sub-files/folders.
                 raise KeyError
             tree_or_blob = self[tree_or_blob[encode_for_git(part)][1]]
     return tree_or_blob
示例#11
0
文件: repo.py 项目: Mechazawa/klaus
 def get_commit(self, rev):
     for prefix in ['refs/heads/', 'refs/tags/', '']:
         key = prefix + rev
         try:
             obj = self[encode_for_git(key)]
             if isinstance(obj, dulwich.objects.Tag):
                 obj = self[obj.object[1]]
             return obj
         except KeyError:
             pass
     raise KeyError(rev)
示例#12
0
文件: repo.py 项目: momodel/klaus
 def get_commit(self, rev):
     """Get commit object identified by `rev` (SHA or branch or tag name)."""
     for prefix in ['refs/heads/', 'refs/tags/', '']:
         key = prefix + rev
         try:
             obj = self[encode_for_git(key)]
             if isinstance(obj, dulwich.objects.Tag):
                 obj = self[obj.object[1]]
             return obj
         except KeyError:
             pass
     raise KeyError(rev)
示例#13
0
文件: repo.py 项目: jonashaag/klaus
 def get_commit(self, rev):
     """Get commit object identified by `rev` (SHA or branch or tag name)."""
     for prefix in ['refs/heads/', 'refs/tags/', '']:
         key = prefix + rev
         try:
             obj = self[encode_for_git(key)]
             if isinstance(obj, dulwich.objects.Tag):
                 obj = self[obj.object[1]]
             return obj
         except KeyError:
             pass
     raise KeyError(rev)
示例#14
0
文件: repo.py 项目: Mechazawa/klaus
    def get_sorted_ref_names(self, prefix, exclude=None):
        refs = self.refs.as_dict(encode_for_git(prefix))
        if exclude:
            refs.pop(prefix + exclude, None)

        def get_commit_time(refname):
            obj = self[refs[refname]]
            if isinstance(obj, dulwich.objects.Tag):
                return obj.tag_time
            return obj.commit_time

        return [decode_from_git(ref) for ref in
                sorted(refs.keys(), key=get_commit_time, reverse=True)]
示例#15
0
    def get_sorted_ref_names(self, prefix, exclude=None):
        refs = self.refs.as_dict(encode_for_git(prefix))
        if exclude:
            refs.pop(prefix + exclude, None)

        def get_commit_time(refname):
            obj = self[refs[refname]]
            if isinstance(obj, dulwich.objects.Tag):
                return obj.tag_time
            return obj.commit_time

        return [decode_from_git(ref) for ref in
                sorted(refs.keys(), key=get_commit_time, reverse=True)]
示例#16
0
文件: repo.py 项目: Mechazawa/klaus
    def listdir(self, commit, path):
        dirs, files = [], []
        for entry in self.get_blob_or_tree(commit, path).items():
            name, entry = entry.path, entry.in_path(encode_for_git(path))
            if entry.mode & stat.S_IFDIR:
                dirs.append((name.lower(), name, entry.path))
            else:
                files.append((name.lower(), name, entry.path))
        files.sort()
        dirs.sort()

        if path:
            dirs.insert(0, (None, '..', parent_directory(path)))

        return {'dirs' : dirs, 'files' : files}
示例#17
0
    def get_ref_names_ordered_by_last_commit(self, prefix, exclude=None):
        """Return a list of ref names that begin with `prefix`, ordered by the
        time they have been committed to last.
        """
        def get_commit_time(refname):
            obj = self[refs[refname]]
            if isinstance(obj, dulwich.objects.Tag):
                return obj.tag_time
            return obj.commit_time

        refs = self.refs.as_dict(encode_for_git(prefix))
        if exclude:
            refs.pop(prefix + exclude, None)
        sorted_names = sorted(refs.keys(), key=get_commit_time, reverse=True)
        return [decode_from_git(ref) for ref in sorted_names]
示例#18
0
文件: repo.py 项目: jonashaag/klaus
    def get_ref_names_ordered_by_last_commit(self, prefix, exclude=None):
        """Return a list of ref names that begin with `prefix`, ordered by the
        time they have been committed to last.
        """
        def get_commit_time(refname):
            obj = self[refs[refname]]
            if isinstance(obj, dulwich.objects.Tag):
                return obj.tag_time
            return obj.commit_time

        refs = self.refs.as_dict(encode_for_git(prefix))
        if exclude:
            refs.pop(prefix + exclude, None)
        sorted_names = sorted(refs.keys(), key=get_commit_time, reverse=True)
        return [decode_from_git(ref) for ref in sorted_names]
示例#19
0
    def listdir(self, commit, path):
        dirs, files = [], []
        for entry in self.get_blob_or_tree(commit, path).items():
            name, entry = entry.path, entry.in_path(encode_for_git(path))
            if entry.mode & stat.S_IFDIR:
                dirs.append((name.lower(), name, entry.path))
            else:
                files.append((name.lower(), name, entry.path))
        files.sort()
        dirs.sort()

        if path:
            dirs.insert(0, (None, '..', parent_directory(path)))

        return {'dirs' : dirs, 'files' : files}
示例#20
0
文件: repo.py 项目: pingf/klaus
    def listdir(self, commit, path):
        """Return a list of directories and files in given directory."""
        submodules, dirs, files = [], [], []
        for entry in self.get_blob_or_tree(commit, path).items():
            name, entry = entry.path, entry.in_path(encode_for_git(path))
            if S_ISGITLINK(entry.mode):
                submodules.append((name.lower(), name, entry.path, entry.sha))
            elif stat.S_ISDIR(entry.mode):
                dirs.append((name.lower(), name, entry.path))
            else:
                files.append((name.lower(), name, entry.path))
        files.sort()
        dirs.sort()

        if path:
            dirs.insert(0, (None, '..', parent_directory(path)))

        return {'submodules': submodules, 'dirs': dirs, 'files': files}
示例#21
0
文件: views.py 项目: catseye/klaus
    def get_response(self):
        basename = "%s@%s" % (self.context['repo'].name,
                              sanitize_branch_name(self.context['rev']))
        tarname = basename + ".tar.gz"
        headers = {
            'Content-Disposition': "attachment; filename=%s" % tarname,
            'Cache-Control': "no-store",  # Disables browser caching
        }

        tar_stream = dulwich.archive.tar_stream(
            self.context['repo'],
            self.context['blob_or_tree'],
            self.context['commit'].commit_time,
            format="gz",
            prefix=encode_for_git(basename),
        )
        return Response(tar_stream,
                        mimetype="application/x-tgz",
                        headers=headers)
示例#22
0
文件: repo.py 项目: jahir/klaus
    def listdir(self, commit, path):
        """Return a list of directories and files in given directory."""
        submodules, dirs, files = [], [], []
        for entry in self.get_blob_or_tree(commit, path).items():
            name, entry = entry.path, entry.in_path(encode_for_git(path))
            if S_ISGITLINK(entry.mode):
                submodules.append(
                    (name.lower(), name, entry.path, entry.sha))
            elif stat.S_ISDIR(entry.mode):
                dirs.append((name.lower(), name, entry.path))
            else:
                files.append((name.lower(), name, entry.path))
        files.sort()
        dirs.sort()

        if path:
            dirs.insert(0, (None, '..', parent_directory(path)))

        return {'submodules': submodules, 'dirs' : dirs, 'files' : files}
示例#23
0
文件: views.py 项目: jonashaag/klaus
    def get_response(self):
        basename = "%s@%s" % (self.context['repo'].name,
                              sanitize_branch_name(self.context['rev']))
        tarname = basename + ".tar.gz"
        headers = {
            'Content-Disposition': "attachment; filename=%s" % tarname,
            'Cache-Control': "no-store",  # Disables browser caching
        }

        tar_stream = dulwich.archive.tar_stream(
            self.context['repo'],
            self.context['blob_or_tree'],
            self.context['commit'].commit_time,
            format="gz",
            prefix=encode_for_git(basename),
        )
        return Response(
            tar_stream,
            mimetype="application/x-tgz",
            headers=headers
        )
示例#24
0
    def get_ref_names_ordered_by_last_commit(self, prefix, exclude=None):
        """Return a list of ref names that begin with `prefix`, ordered by the
        time they have been committed to last.
        """
        def get_commit_time(obj):
            if obj is None:
                # Put refs that point to non-existent objects last.
                return 0
            elif isinstance(obj, dulwich.objects.Tag):
                return obj.tag_time
            else:
                return obj.commit_time

        refs = self.get_resolved_refs_as_dict(encode_for_git(prefix),
                                              resolve_default=None)
        if exclude:
            refs.pop(prefix + exclude, None)
        sorted_refs = sorted(refs.items(),
                             key=lambda item: get_commit_time(item[1]),
                             reverse=True)
        return [decode_from_git(name) for name, _ in sorted_refs]