diff options
-rw-r--r-- | pomu/source/portage.py | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/pomu/source/portage.py b/pomu/source/portage.py index ded09c9..6cf8f3f 100644 --- a/pomu/source/portage.py +++ b/pomu/source/portage.py @@ -6,6 +6,8 @@ import re from os import path +from portage.versions import suffix_value, best + from pomu.repo.repo import portage_repos from pomu.source import dispatcher from pomu.util import Result @@ -20,30 +22,17 @@ class PortagePackage(): self.version = version self.slot = slot -suffixes = ['alpha', 'beta', 'pre', 'rc', 'p'] +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'] @dispatcher.source class PortageSource(): - @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') - return Result.Err() - uri = uri[len('portage'):] - # gentoo:dev-libs/openssl-0.9.8z_p8-r100:0.9.8::gentoo - if uri.startswith('/'): # repo may be omitted - repo, _, uri_ = uri[1:].partition(':') - if uri_ == uri[1:]: - return Result.Err() - uri = uri_ - elif uri.startswith(':'): - repo = None - uri = uri[1:] + @dispatcher.handler(priority=5) + def parse_spec(uri, repo=None): # dev-libs/openssl-0.9.8z_p8-r100:0.9.8::gentoo pkg, _, repo_ = uri.partition('::') # portage repo may be specified on the rhs as well if repo_: - repo = repo + repo = repo_ # dev-libs/openssl-0.9.8z_p8-r100:0.9.8 pkg, _, slot = uri.partition(':') # slot may be omitted if not slot: @@ -70,6 +59,28 @@ class PortageSource(): vernum = None # openssl name = pkg + res = sanity_check(repo, category, name, vernum, suff, rev, slot) + if not res: + return Result.Err() + return Result.Ok(res) + + + @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') + return Result.Err() + uri = uri[len('portage'):] + # gentoo:dev-libs/openssl-0.9.8z_p8-r100:0.9.8::gentoo + if uri.startswith('/'): # repo may be omitted + repo, _, uri_ = uri[1:].partition(':') + if uri_ == uri[1:]: + return Result.Err() + uri = uri_ + elif uri.startswith(':'): + repo = None + uri = uri[1:] + return parse_spec(uri, repo) def sanity_check(repo, category, name, vernum, suff, rev, slot): if not name: @@ -79,36 +90,39 @@ class PortageSource(): if (rev or suff) and not vernum: return False if vernum: - ver = vernum + (suff if suff else '') + (rev if rev else '') + ver = ver_str(vernum, suff, rev) else: ver = None - if not repo_pkgs(repo, category, name, ver, slot): + pkgs = repo_pkgs(repo, category, name, ver, slot) + if not pkgs: return False + return pkgs - # TODO: vvv - def pkg_slot(repo, category, name, ver): + def ver_str(vernum, suff, rev): + return vernum + (suff if suff else '') + (rev if rev else '') - def best_ver(repo, category, name, ver, slot): + def best_ver(repo, category, name, ver=None, slot=None): """Gets the best (newest) version of a package matching slot in the repo""" ebuilds = [x[:-6] for x in os.listdir(path.join(portage_repo_path(repo)), category, name) if x.endswith('.ebuild')] + return best(ebuilds) - def repo_pkgs(repo, category, name, ver, slot): + 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(has_pkg(r, category, name)) + 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)] + 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) + res.append((repo, d, name, best_ver(repo, d, name)) return res |