Exemple #1
0
from strawman.storage import NestedStorage


class FileSystemStorage(object):

    def __init__(self, basedir):
        self.basedir = os.path.abspath(os.path.expanduser(basedir))

    def _get_path(self, path):
        return os.path.join(self.basedir, path[1:])

    def content(self, path):
        with open(self._get_path(path), 'rb') as f:
            return f.read()

    def mtime(self, path):
        return os.stat(self._get_path(path)).st_mtime

    def list(self, path):
        for filename in os.listdir(self._get_path(path)):
            relpath = os.path.join(path, filename)

            if os.path.isdir(self._get_path(relpath)):
                relpath += '/'

            yield relpath


NestedStorage.register(FileSystemStorage)
Exemple #2
0
        return self.repo[sha]

    def content(self, path):
        return self._get_object(path).as_raw_string()

    def mtime(self, path):
        walker = self.repo.get_walker(
            include=[self.commit.id],
            max_entries=1,
            paths=[os.path.join(self.path, path[1:])[1:]])

        commit = list(walker)[0].commit
        return commit.commit_time

    def list(self, path):
        if path == '/':
            tree = self.tree
        else:
            tree = self._get_object(path[:-1])

        for filename in tree:
            relpath = os.path.join(path, filename)

            if self._get_object(relpath).type_name == 'tree':
                relpath += '/'

            yield relpath

NestedStorage.register(DulwichStorage)