aboutsummaryrefslogtreecommitdiff
blob: 4b1e1d3d9bb9fcf2e89a6707734366ff67814722 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""A class for remote svn repos"""
from subprocess import run

from pomu.repo.remote import RemoteRepo, normalize_key
from pomu.util.result import Result

class RemoteSvnRepo(RemoteRepo):
    """A class responsible for svn remotes"""
    def __init__(self, url):
        self.uri = uri

    def __enter__(self):
        pass

    def __exit__(self, *_):
        pass

    def fetch_tree(self):
        """Returns repos hierarchy"""
        if hasattr(self, '_tree'):
            return self._tree
        p = run('svn', 'ls', '-R', self.uri)
        if p.returncode:
            return []
        self._tree = p.stdout.split('\n')
        return self._tree

    def fetch_subtree(self, key):
        """Lists a subtree"""
        k = normalize_key(key, True)
        self.fetch_tree()
        dic = dict(self._tree)
        if k not in dic:
            return Result.Err()
        l = len(key)
        return Result.Ok(
                [tpath[l:] for tpath in self.fetch_tree() if tpath.startswith(k)])

    def fetch_file(self, key):
        """Fetches a file from the repo"""
        k = normalize_key(key)
        self.fetch_tree()
        dic = dict(self._tree)
        if k not in dic:
            return Result.Err()
        p = run('svn', 'cat', k)
        if p.returncode:
            return Result.Err()
        return Result.Ok(p.stdout)