aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pomu/cli.py1
-rw-r--r--pomu/source/__init__.py2
-rw-r--r--pomu/source/manager.py2
-rw-r--r--pomu/source/portage.py161
-rw-r--r--pomu/util/result.py4
-rw-r--r--pomu/util/str.py7
6 files changed, 97 insertions, 80 deletions
diff --git a/pomu/cli.py b/pomu/cli.py
index 1b9093a..c17840e 100644
--- a/pomu/cli.py
+++ b/pomu/cli.py
@@ -19,6 +19,7 @@ g_params = GlobalVars()
class needs_repo():
def __init__(self, func):
self.func = func
+ self.__name__ = func.__name__
def __call__(self, *args):
pomu_active_repo(g_params.no_portage, g_params.repo_path)
diff --git a/pomu/source/__init__.py b/pomu/source/__init__.py
index a86679f..027227e 100644
--- a/pomu/source/__init__.py
+++ b/pomu/source/__init__.py
@@ -1,3 +1,5 @@
from pomu.source.manager import PackageDispatcher
dispatcher = PackageDispatcher()
+
+import pomu.source.portage
diff --git a/pomu/source/manager.py b/pomu/source/manager.py
index 93fd1b4..f36eb90 100644
--- a/pomu/source/manager.py
+++ b/pomu/source/manager.py
@@ -60,7 +60,7 @@ class PackageDispatcher():
def register_package_handler(self, source, handler, priority):
i = 0
for i in range(len(self.handlers)):
- if self.handlers[0] > priority:
+ if self.handlers[0][0] > priority:
break
self.handlers.insert(i, (priority, source, handler))
diff --git a/pomu/source/portage.py b/pomu/source/portage.py
index a92879c..aaf5c1c 100644
--- a/pomu/source/portage.py
+++ b/pomu/source/portage.py
@@ -9,9 +9,10 @@ from os import path
from portage.versions import best, suffix_value, vercmp
-from pomu.repo.repo import portage_repos
+from pomu.package import Package
+from pomu.repo.repo import portage_repos, portage_repo_path
from pomu.source import dispatcher
-from pomu.util import Result
+from pomu.util.result import Result
from pomu.util.str import pivot
class PortagePackage():
@@ -28,8 +29,12 @@ class PortagePackage():
files=[path.join(self.category, self.name, 'metadata.xml'),
path.join(self.category, self.name, self.name + '-' + self.version + '.ebuild')])
+ def __str__(self):
+ return '{}/{}-{}{}::{}'.format(self.category, self.name, self.version,
+ '' if self.slot == '0' else ':' + self.slot, self.repo)
+
suffixes = [x[0] for x in sorted(suffix_value.items(), key=lambda x:x[1])]
-misc_dirs = ['profiles', 'licenses', 'eclass', 'metadata', 'distfiles', 'packages', 'scripts'. '.git']
+misc_dirs = ['profiles', 'licenses', 'eclass', 'metadata', 'distfiles', 'packages', 'scripts', '.git']
@dispatcher.source
class PortageSource():
@@ -49,36 +54,10 @@ class PortageSource():
return Result.Err()
return Result.Ok(res)
- def cpv_split(pkg):
- # dev-libs/openssl-0.9.8z_p8-r100
- category, _, pkg = pkg.rpartition('/') # category may be omitted
- # openssl-0.9.8z_p8-r100
- m = re.search(r'-r\d+$', pkg) # revision is optional
- if m:
- pkg, rev = pivot(pkg, m.start(0))
- else:
- rev = None
- # openssl-0.9.8z_p8
- m = re.search(r'_({})(\d*)$'.format('|'.join(suffixes)))
- if m:
- pkg, suff = pivot(pkg, m.start(0))
- else:
- suff = None
- # openssl-0.9.8z
- m = re.search(r'-(\d+(\.\d+)*)([a-z])?$')
- if m:
- pkg, vernum = pivot(pkg, m.start(0))
- else:
- vernum = None
- # openssl
- name = pkg
- return category, name, vernum, suff, rev
-
-
@dispatcher.handler()
def parse_full(uri):
# portage/gentoo:dev-libs/openssl-0.9.8z_p8-r100:0.9.8::gentoo
- if not uri.startswith('portage')
+ if not uri.startswith('portage'):
return Result.Err()
uri = uri[len('portage'):]
# gentoo:dev-libs/openssl-0.9.8z_p8-r100:0.9.8::gentoo
@@ -92,50 +71,82 @@ class PortageSource():
uri = uri[1:]
return parse_spec(uri, repo)
- def sanity_check(repo, category, name, vernum, suff, rev, slot):
- if not name:
- return False
- if repo and repo not in list(portage_repos()):
- return False
- if (rev or suff) and not vernum:
- return False
- if vernum:
- ver = ver_str(vernum, suff, rev)
- else:
- ver = None
- pkgs = repo_pkgs(repo, category, name, ver, slot)
- if not pkgs:
- return False
- pkg = sorted(pkgs, key=cmp_to_key(lambda x,y:vercmp(x[3],y[3])), reverse=True)[0]
- return PortagePackage(*pkg)
-
-
- def ver_str(vernum, suff, rev):
- return vernum + (suff if suff else '') + (rev if rev else '')
-
- def best_ver(repo, category, name, ver=None):
- """Gets the best (newest) version of a package in the repo"""
- ebuilds = [category + '/' + name + x[len(name):-6] for x in
- os.listdir(path.join(portage_repo_path(repo)), category, name)
- if x.endswith('.ebuild')]
- cat, name, vernum, suff, rev = cpv_split(best(ebuilds))
- return ver_str(vernum, suff, rev)
-
- def repo_pkgs(repo, category, name, ver=None, slot=None):
- """List of package occurences in the repo"""
- if not repo:
- res = []
- for r in portage_repos():
- res.extend(repo_pkgs(r, category, name, ver, slot))
- return res
- if category:
- if path.exists(path.join(portage_repo_path(repo), category, name)):
- return [(repo, category, name, best_ver(repo, category, name))]
- return []
- rpath = portage_repo_path(repo)
- dirs = set(os.listdir(rpath)) - set(misc_dirs)
+ @classmethod
+ def fetch_package(cls, pkg):
+ return pkg.fetch()
+
+
+def sanity_check(repo, category, name, vernum, suff, rev, slot):
+ if not name:
+ return False
+ if repo and repo not in list(portage_repos()):
+ return False
+ if (rev or suff) and not vernum:
+ return False
+ if vernum:
+ ver = ver_str(vernum, suff, rev)
+ else:
+ ver = None
+ pkgs = repo_pkgs(repo, category, name, ver, slot)
+ if not pkgs:
+ return False
+ pkg = sorted(pkgs, key=cmp_to_key(lambda x,y:vercmp(x[3],y[3])), reverse=True)[0]
+ return PortagePackage(*pkg)
+
+
+def ver_str(vernum, suff, rev):
+ return vernum + (suff if suff else '') + (rev if rev else '')
+
+def best_ver(repo, category, name, ver=None):
+ """Gets the best (newest) version of a package in the repo"""
+ ebuilds = [category + '/' + name + x[len(name):-7] for x in
+ os.listdir(path.join(portage_repo_path(repo), category, name))
+ if x.endswith('.ebuild')]
+ cat, name, vernum, suff, rev = cpv_split(best(ebuilds))
+ return ver_str(vernum, suff, rev)
+
+def repo_pkgs(repo, category, name, ver=None, slot=None):
+ """List of package occurences in the repo"""
+ if not repo:
res = []
- for d in dirs:
- if path.isdir(path.join(rpath, d, name)):
- res.append((repo, d, name, best_ver(repo, d, name)))
+ for r in portage_repos():
+ res.extend(repo_pkgs(r, category, name, ver, slot))
return res
+ if category:
+ if path.exists(path.join(portage_repo_path(repo), category, name)):
+ return [(repo, category, name, best_ver(repo, category, name))]
+ return []
+ rpath = portage_repo_path(repo)
+ dirs = set(os.listdir(rpath)) - set(misc_dirs)
+ res = []
+ for d in dirs:
+ if path.isdir(path.join(rpath, d, name)):
+ res.append((repo, d, name, best_ver(repo, d, name)))
+ return res
+
+def cpv_split(pkg):
+ # dev-libs/openssl-0.9.8z_p8-r100
+ category, _, pkg = pkg.rpartition('/') # category may be omitted
+ # openssl-0.9.8z_p8-r100
+ m = re.search(r'-r\d+$', pkg) # revision is optional
+ if m:
+ pkg, rev = pivot(pkg, m.start(0), False)
+ else:
+ rev = None
+ # openssl-0.9.8z_p8
+ m = re.search(r'_({})(\d*)$'.format('|'.join(suffixes)), pkg)
+ if m:
+ pkg, suff = pivot(pkg, m.start(0), False)
+ else:
+ suff = None
+ # openssl-0.9.8z
+ m = re.search(r'-(\d+(\.\d+)*)([a-z])?$', pkg)
+ if m:
+ pkg, vernum = pivot(pkg, m.start(0), False)
+ else:
+ vernum = None
+ # openssl
+ name = pkg
+ return category, name, vernum, suff, rev
+
+__all__ = [PortagePackage, PortageSource]
diff --git a/pomu/util/result.py b/pomu/util/result.py
index a5dae3b..cd67fa0 100644
--- a/pomu/util/result.py
+++ b/pomu/util/result.py
@@ -40,7 +40,7 @@ class Result():
return Result.Err(f(self.err())) if not self._is_val else Result.Ok(self.ok())
def unwrap(self):
- return self.expect(self.err())
+ return self.expect()
def expect(self, msg='Error'):
if self._is_val:
@@ -48,7 +48,7 @@ class Result():
raise ResultException(msg + ': ' + self._val)
def unwrap_err(self):
- return self.expect_err(self.ok())
+ return self.expect_err()
def expect_err(self, msg='Error'):
if not self._is_val:
diff --git a/pomu/util/str.py b/pomu/util/str.py
index 4fcd4ac..419425b 100644
--- a/pomu/util/str.py
+++ b/pomu/util/str.py
@@ -1,2 +1,5 @@
-def pivot(string, idx):
- return (string[:idx], string[idx:])
+def pivot(string, idx, keep_pivot=True):
+ if keep_pivot:
+ return (string[:idx], string[idx:])
+ else:
+ return (string[:idx], string[idx+1:])