diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2017-08-05 05:05:55 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2017-08-05 05:05:55 +0300 |
commit | b9d09edf84e8ed0838aeaf3c228c82cf316437f6 (patch) | |
tree | 41755ce4cbe15fec988c7f2925b1f73fda9d9274 | |
parent | Improved iquery (diff) | |
download | pomu-b9d09edf84e8ed0838aeaf3c228c82cf316437f6.tar.gz pomu-b9d09edf84e8ed0838aeaf3c228c82cf316437f6.tar.bz2 pomu-b9d09edf84e8ed0838aeaf3c228c82cf316437f6.zip |
Added a RemoteRepo object for remote fetching
Added utility functions for git data structures
-rw-r--r-- | pomu/repo/remote/remote.py | 28 | ||||
-rw-r--r-- | pomu/util/git.py | 46 |
2 files changed, 74 insertions, 0 deletions
diff --git a/pomu/repo/remote/remote.py b/pomu/repo/remote/remote.py new file mode 100644 index 0000000..e177f68 --- /dev/null +++ b/pomu/repo/remote/remote.py @@ -0,0 +1,28 @@ +"""A template class for remote repos""" + + +class RemoteRepo(): + """A class responsible for remotes""" + def __init__(self, url): + self.uri = uri + raise NotImplementedError() + + def fetch_package(self, name, category=None, version=None): + """Fetches a package, determined by the parametres""" + raise NotImplementedError() + + def list_cpvs(self): + """Gets a list of all pebuilds in the repo""" + raise NotImplementedError() + + def fetch_tree(self): + """Returns repos hierarchy""" + raise NotImplementedError() + + def fetch_subtree(self, key): + """Lists a subtree""" + raise NotImplementedError() + + def fetch_file(self, key): + """Fetches a file from the repo""" + raise NotImplementedError() diff --git a/pomu/util/git.py b/pomu/util/git.py new file mode 100644 index 0000000..4c3e2ed --- /dev/null +++ b/pomu/util/git.py @@ -0,0 +1,46 @@ +"""Miscellaneous utility functions for git structures""" + +from base64 import b16encode + +from pomu.util.result import Result + +def parse_tree(blob): + """Parses a git tree""" + res = [] + leng, _, tree = blob.partition('\0') + if not tree: + return Result.Err('Invalid tree') + while len(data) > 0: + data = data[7:] # strip access code + name, _, data = data.partition('\0') + sha = b16encode(data[0:20]).decode('utf-8') + data = data[20:] + if not name or not sha: + return Result.Err() + res.append((sha, name)) + return Result.Ok(res) + +def parse_blob(blob): + """Parses a git blob""" + data = zlib.decompress(blob) + leng, _, data = data.partition('\0') + if not leng or not data: + return Result.Err() + +def commit_head(blob): + if not blob[7:] == 'commit ': + return Result.Err() + l = blob.split('\n')[0] + cid, _, tid = l.partition('\0') + if not tid[0:5] == 'tree ': + return Result.Err() + return tid[5:] + +def parse_object(obj): + """Parses a git object""" + data = zlib.decompress(obj) + if data[0:5] == 'blob ': + return parse_blob(data[5:]) + elif data[0:5] == 'tree ': + return parse_tree(data[5:]) + return Result.Err('Unsupported object type') |