aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'pomu/repo/remote/svn.py')
-rw-r--r--pomu/repo/remote/svn.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/pomu/repo/remote/svn.py b/pomu/repo/remote/svn.py
new file mode 100644
index 0000000..4b1e1d3
--- /dev/null
+++ b/pomu/repo/remote/svn.py
@@ -0,0 +1,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)