Commit 223ce982 authored by A. Wilcox's avatar A. Wilcox 🦊
Browse files

Portage: Add SLOT to dependent package names (closes #1)

parent 18943b88
......@@ -92,6 +92,7 @@ from apkkit.base.package import Package
from 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')
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.'
elif len(potential_slots) == 1:
slot = potential_slots.pop()
if slot and slot != '0':
package += slot
pass # We assume no slot.
op = dep.operator
ver = dep.version
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment