summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Wilcox <AWilcox@Wilcox-Tech.com>2016-04-24 15:01:53 -0500
committerAndrew Wilcox <AWilcox@Wilcox-Tech.com>2016-04-24 15:01:53 -0500
commit223ce982d68e8ac653fc9d6a898773d60c25bd6b (patch)
tree88adcddf2661639e151af39b6ab712228e436161
parent18943b88d76364e85331414c08bbeeae80fc29a8 (diff)
downloadapkkit-223ce982d68e8ac653fc9d6a898773d60c25bd6b.tar.gz
apkkit-223ce982d68e8ac653fc9d6a898773d60c25bd6b.tar.bz2
apkkit-223ce982d68e8ac653fc9d6a898773d60c25bd6b.tar.xz
apkkit-223ce982d68e8ac653fc9d6a898773d60c25bd6b.zip
Portage: Add SLOT to dependent package names (closes #1)
-rw-r--r--apkkit/portage.py37
1 files changed, 35 insertions, 2 deletions
diff --git a/apkkit/portage.py b/apkkit/portage.py
index e250fe5..7521a9f 100644
--- a/apkkit/portage.py
+++ b/apkkit/portage.py
@@ -92,6 +92,7 @@ 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
@@ -103,6 +104,20 @@ ARCH_MAP = {'amd64': 'x86_64', 'hppa': 'parisc'}
"""Mapping for architectures that have the wrong name in Portage."""
+VARDB = db['/']['vartree'].dbapi
+
+
+def _fatal(msg):
+ """Print a fatal error to the user.
+
+ :param str msg:
+ The message to print.
+ """
+
+ print('\033[01;31m *\033[01;39m An APK cannot be created.')
+ print('\033[01;31m *\033[00;39m {msg}'.format(msg=msg))
+
+
def _maybe_xlat(pn, category):
"""Offers the ability to translate a package name.
@@ -144,7 +159,8 @@ def native(settings, mydbapi=None):
params['name'] = _maybe_xlat(settings['PN'], settings['CATEGORY'])
if 'SLOT' in settings and not settings['SLOT'].startswith('0/') and\
settings['SLOT'] != '0':
- params['name'] += settings['SLOT']
+ slot = settings['SLOT'].split('/')[0]
+ params['name'] += slot
params['version'] = settings['PVR'] # include -rX if necessary
params['arch'] = ARCH_MAP.get(settings['ARCH'], settings['ARCH'])
params['provides'] = list()
@@ -152,7 +168,7 @@ def native(settings, mydbapi=None):
cpv = '%s/%s' % (settings['CATEGORY'], settings['PF'])
if mydbapi is None or not mydbapi.cpv_exists(cpv):
- print('!!! Fatal error: CPV does not exist or DBAPI is missing')
+ _fatal('CPV does not exist or DBAPI is missing')
sys.exit(-1)
desc, url = mydbapi.aux_get(cpv, ('DESCRIPTION', 'HOMEPAGE'))
@@ -165,6 +181,23 @@ def native(settings, mydbapi=None):
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