aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pomu/repo/remote/git.py15
-rw-r--r--pomu/repo/remote/hg.py3
-rw-r--r--pomu/repo/remote/remote.py11
-rw-r--r--pomu/repo/remote/rsync.py3
-rw-r--r--pomu/util/git.py16
-rw-r--r--pomu/util/remote.py8
6 files changed, 31 insertions, 25 deletions
diff --git a/pomu/repo/remote/git.py b/pomu/repo/remote/git.py
index 2cb00d2..42db11a 100644
--- a/pomu/repo/remote/git.py
+++ b/pomu/repo/remote/git.py
@@ -14,8 +14,7 @@ class RemoteGitRepo(RemoteRepo):
def __init__(self, url):
self.uri = url
self.dir = mkdtemp()
- chdir(self.dir)
- if call('git', 'clone', '--depth=1', '--bare', url) > 0: # we've a problem
+ if call(['git', 'clone', '--depth=1', '--bare', url, self.dir]) > 0: # we've a problem
raise RuntimeError()
self.repo = Repo(self.dir)
@@ -28,23 +27,23 @@ class RemoteGitRepo(RemoteRepo):
def get_object(self, oid):
head, tail = oid[0:2], oid[2:]
opath = path.join(self.dir, 'objects', head, tail)
- return opath.read()
+ return open(opath, 'rb').read()
def _fetch_tree(self, obj, tpath):
res = []
ents = parse_object(self.get_object(obj), tpath).unwrap()
for is_dir, sha, opath in ents:
- res.append((opath + '/' if is_dir else '', sha))
+ res.append((opath.decode('utf-8') + ('/' if is_dir else ''), sha))
if is_dir:
- res.extend(self._fetch_tree(sha, tpath + opath))
+ res.extend(self._fetch_tree(sha, opath))
return res
def fetch_tree(self):
"""Returns repos hierarchy"""
if hasattr(self, '_tree'):
- return self._tree
+ return [x for x, y in self._tree]
tid = self.repo.tree().hexsha
- res = self._fetch_tree(tid, '')
+ res = self._fetch_tree(tid, b'')
self._tree = res
return [x for x, y in res]
@@ -66,4 +65,4 @@ class RemoteGitRepo(RemoteRepo):
dic = dict(self._tree)
if k not in dic:
return Result.Err()
- return Result.Ok(parse_object(self.get_object(dic[k])))
+ return parse_object(self.get_object(dic[k]))
diff --git a/pomu/repo/remote/hg.py b/pomu/repo/remote/hg.py
index de4290b..4e5e8a9 100644
--- a/pomu/repo/remote/hg.py
+++ b/pomu/repo/remote/hg.py
@@ -1,7 +1,8 @@
"""A class for remote hg repos"""
-from os import chdir, mkdtemp
+from os import chdir
from shutil import rmtree
from subprocess import call, run
+from tempfile import mkdtemp
from pomu.repo.remote.remote import RemoteRepo, normalize_key
from pomu.util.result import Result
diff --git a/pomu/repo/remote/remote.py b/pomu/repo/remote/remote.py
index 7fa75bf..b8815ea 100644
--- a/pomu/repo/remote/remote.py
+++ b/pomu/repo/remote/remote.py
@@ -31,7 +31,7 @@ class RemoteRepo():
return tp(uri)
@classmethod
- def type_for_name(type_):
+ def type_for_name(cls, type_):
from pomu.repo.remote.git import RemoteGitRepo
from pomu.repo.remote.hg import RemoteHgRepo
from pomu.repo.remote.rsync import RemoteRsyncRepo
@@ -42,17 +42,17 @@ class RemoteRepo():
def fetch_package(self, name, category=None, version=None):
"""Fetches a package, determined by the parametres"""
- cat, n, ver = get_full_cpv(self.fetch_tree(), name, category, version).unwrap()
+ cat, n, ver = get_full_cpv(self.list_cpvs(), name, category, version).unwrap()
ebuild = '{}/{}/{}-{}.ebuild'.format(cat, n, n, ver)
- subdir = '/{}/{}'.format(category, name)
+ subdir = '/{}/{}'.format(cat, name)
filemap = {}
filemap[ebuild] = self.fetch_file(ebuild).unwrap()
- subtree = self.fetch_subtree('/{}/{}/'.format(category, name))
+ subtree = self.fetch_subtree('/{}/{}/'.format(cat, name)).unwrap()
for fpath in subtree:
if '/' in fpath:
parent, _, child = fpath.rpartition('/')
if parent != 'files': continue
- if fpath.endswith('.ebuild') or fpath.endswith('/'): continue
+ if not fpath or fpath.endswith('.ebuild') or fpath.endswith('/'): continue
p = path.join(subdir, fpath)
filemap[p] = self.fetch_file(p).unwrap()
return Package(name, '/', None, category, version, filemap=filemap)
@@ -77,3 +77,4 @@ def normalize_key(key, trail=False):
k = '/' + key.lstrip('/')
if trail:
k = k.rstrip('/') + '/'
+ return k
diff --git a/pomu/repo/remote/rsync.py b/pomu/repo/remote/rsync.py
index b93719b..ae6ab76 100644
--- a/pomu/repo/remote/rsync.py
+++ b/pomu/repo/remote/rsync.py
@@ -1,6 +1,7 @@
"""A class for remote rsync repos"""
-from os import mkdtemp, rmdir, mkfifo, unlink, path
+from os import rmdir, mkfifo, unlink, path
from subprocess import run
+from tempfile import mkdtemp
from pomu.repo.remote.remote import RemoteRepo, normalize_key
from pomu.util.result import Result
diff --git a/pomu/util/git.py b/pomu/util/git.py
index 611b27c..985087c 100644
--- a/pomu/util/git.py
+++ b/pomu/util/git.py
@@ -5,10 +5,12 @@ import zlib
from pomu.util.result import Result
-def parse_tree(blob, path=''):
+def parse_tree(blob, path=b''):
"""Parses a git tree"""
res = []
leng, _, tree = blob.partition(b'\0')
+ if path is str:
+ path = path.encode('utf-8')
if not tree:
return Result.Err('Invalid tree')
while len(tree) > 0:
@@ -19,15 +21,15 @@ def parse_tree(blob, path=''):
if not name or not sha:
return Result.Err()
is_dir = mode[0:1] != b'1'
- res.append((is_dir, sha, path.encode('utf-8') + b'/' + name))
+ res.append((is_dir, sha, path + b'/' + name))
return Result.Ok(res)
def parse_blob(blob):
"""Parses a git blob"""
- data = zlib.decompress(blob)
- leng, _, data = data.partition('\0')
+ leng, _, data = blob.partition(b'\0')
if not leng or not data:
return Result.Err()
+ return Result.Ok(data)
def commit_head(blob):
if not blob[7:] == 'commit ':
@@ -38,11 +40,13 @@ def commit_head(blob):
return Result.Err()
return tid[5:]
-def parse_object(obj):
+def parse_object(obj, tpath=b''):
"""Parses a git object"""
+ if tpath is str:
+ tpath = tpath.encode('utf-8')
data = zlib.decompress(obj)
if data[0:5] == b'blob ':
return parse_blob(data[5:])
elif data[0:5] == b'tree ':
- return parse_tree(data[5:])
+ return parse_tree(data[5:], tpath)
return Result.Err('Unsupported object type')
diff --git a/pomu/util/remote.py b/pomu/util/remote.py
index 9e3875a..c0c6554 100644
--- a/pomu/util/remote.py
+++ b/pomu/util/remote.py
@@ -13,7 +13,7 @@ def filelist_to_cpvs(tree):
"""Converts a list of files to list of cpvs"""
res = []
for opath in tree:
- comps = opath.split('/')
+ comps = opath.split('/')[1:]
if (opath.endswith('/') or
any(opath.startswith('/' + x + '/') for x in misc_dirs) or
len(comps) != 3 or
@@ -21,18 +21,18 @@ def filelist_to_cpvs(tree):
continue
category, name, ebuild = comps[0], comps[1], comps[2][:-7]
c, n, v, s, r = cpv_split(ebuild)
- if category or n != name:
+ if not category or n != name:
continue
ver = ver_str(v, s, r)
res.append((category, name, ver))
return res
def get_full_cpv(cpvs, name, category=None, version=None):
- cpvl = cpvs.filter(lambda x: x[1] == name and (not category or x[0] == category))
+ cpvl = filter(lambda x: x[1] == name and (not category or x[0] == category), cpvs)
if not cpvl: return Result.Err()
if version:
cpvl = cpvl.filter(lambda x: x[2] == version)[:1]
- b = best('{}/{}-{}'.format(c, n, v) for c, n, v in cpvl)
+ b = best(list('{}/{}-{}'.format(c, n, v) for c, n, v in cpvl))
if b:
cat, name, v, s, r = cpv_split(b)
ver = ver_str(v, s, r)