diff options
author | Andrew Wilcox <AWilcox@Wilcox-Tech.com> | 2016-04-24 15:31:10 -0500 |
---|---|---|
committer | Andrew Wilcox <AWilcox@Wilcox-Tech.com> | 2016-04-24 18:17:14 -0500 |
commit | 2a693a78501c889cf825571989458ae9bf56e4af (patch) | |
tree | 7e3fbe7971b65c19b0e0a20860746e5101df0f4a | |
parent | 223ce982d68e8ac653fc9d6a898773d60c25bd6b (diff) | |
download | apkkit-2a693a78501c889cf825571989458ae9bf56e4af.tar.gz apkkit-2a693a78501c889cf825571989458ae9bf56e4af.tar.bz2 apkkit-2a693a78501c889cf825571989458ae9bf56e4af.tar.xz apkkit-2a693a78501c889cf825571989458ae9bf56e4af.zip |
Refactor dependency handling and PyLint fixes
-rw-r--r-- | apkkit/portage.py | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/apkkit/portage.py b/apkkit/portage.py index 7521a9f..a6dab76 100644 --- a/apkkit/portage.py +++ b/apkkit/portage.py @@ -88,14 +88,16 @@ pkg_trigger() { ``` """ -from apkkit.base.package import Package -from apkkit.io.apkfile import APKFile import logging import os -from portage import db -from portage.dep import Atom, use_reduce import sys +import portage +from portage.dep import Atom, use_reduce + +from apkkit.base.package import Package +from apkkit.io.apkfile import APKFile + logging.basicConfig(level=logging.DEBUG) @@ -104,7 +106,9 @@ ARCH_MAP = {'amd64': 'x86_64', 'hppa': 'parisc'} """Mapping for architectures that have the wrong name in Portage.""" -VARDB = db['/']['vartree'].dbapi +# for some reason, it thinks there's no portage.db. pylint: disable=no-member +VARDB = portage.db['/']['vartree'].dbapi +# pylint: enable=no-member def _fatal(msg): @@ -142,6 +146,43 @@ def _maybe_xlat(pn, category): return pn +def _translate_dep(dep): + category, package = dep.cp.split('/', 1) + package = _maybe_xlat(package, category) + if dep.slot: + if dep.slot != "0": + package += dep.slot + elif package != 'ncurses': # so especially broken it's special cased + potentials = VARDB.match(dep) + potential_slots = set([pot.slot for pot in potentials]) + if len(potential_slots) > 1: + msg = 'Dependency for {name} has multiple candidate slots,' + msg += ' and no single slot can be resolved.' + _fatal(msg.format(name=dep)) + sys.exit(-1) + elif len(potential_slots) == 1: + slot = potential_slots.pop() + if slot and slot != '0': + package += slot + else: + pass # We assume no slot. + dep_op = dep.operator + ver = dep.version + + if dep.blocker: + package = '!' + package + + if dep_op is None and ver is None: + # "Easy" dep. + return package + + if dep_op == '~': + dep_op = '=' # broken + # apk-tools/src/package.c:195 + # there is literally no other documentation for this format. + return '{name}{op}{ver}'.format(name=package, op=dep_op, ver=ver) + + def native(settings, mydbapi=None): """Take a Portage settings object and turn it into an APK. @@ -164,7 +205,6 @@ def native(settings, mydbapi=None): params['version'] = settings['PVR'] # include -rX if necessary params['arch'] = ARCH_MAP.get(settings['ARCH'], settings['ARCH']) params['provides'] = list() - params['depends'] = list() cpv = '%s/%s' % (settings['CATEGORY'], settings['PF']) if mydbapi is None or not mydbapi.cpv_exists(cpv): @@ -178,41 +218,8 @@ def native(settings, mydbapi=None): run_deps = use_reduce(mydbapi.aux_get(cpv, ('RDEPEND',)), uselist=settings['USE'], opconvert=True, token_class=Atom, eapi=settings['EAPI']) - for dep in run_deps: - category, package = dep.cp.split('/', 1) - package = _maybe_xlat(package, category) - if dep.slot: - if dep.slot != "0": - package += dep.slot - elif package != 'ncurses': # so especially broken it's special cased - potentials = VARDB.match(dep) - potential_slots = set([pot.slot for pot in potentials]) - if len(potential_slots) > 1: - msg = 'Dependency for {name} has multiple candidate slots,' - msg += ' and no single slot can be determined.' - _fatal(msg.format(name=dep)) - sys.exit(-1) - elif len(potential_slots) == 1: - slot = potential_slots.pop() - if slot and slot != '0': - package += slot - else: - pass # We assume no slot. - op = dep.operator - ver = dep.version - - if dep.blocker: - package = '!' + package - - if op is None and ver is None: - # "Easy" dep. - params['depends'].append(package) - continue - - # apk-tools/src/package.c:195 - # there is literally no other documentation for this format. - apk_format = '{name}{op}{ver}'.format(name=package, op=op, ver=ver) - params['depends'].append(apk_format) + + params['depends'] = map(_translate_dep, run_deps) package = Package(**params) apk = APKFile.create(package, settings['D']) @@ -223,6 +230,6 @@ def native(settings, mydbapi=None): return 0 if __name__ == '__main__': - import portage print("You are calling from the shell, this is not supported!") + # pylint: disable=no-member native(os.environ, portage.db['/']['porttree'].dbapi) |