More error reporting in ebuild module

Now reports blocked packages and slot conflicts. #5393
This commit is contained in:
shadowfax-chc 2013-10-24 20:59:36 -04:00
parent 058eeec39d
commit 2ff2f0c7df

View File

@ -84,13 +84,28 @@ def _cpv_to_version(cpv):
return portage.versions.cpv_getversion(cpv)
def _process_emerge_err(stderr):
def _process_emerge_err(stdout, stderr):
'''
Used to parse emerge output to provide meaningful output when emerge fails
'''
ret = {}
changes = {}
rexp = re.compile(r'([<>=][^ ]+/[^ ]+ [^\n]+)')
rexp = re.compile(r'^[<>=][^ ]+/[^ ]+ [^\n]+', re.M)
slot_conflicts = re.compile(r'^[^ \n]+/[^ ]+:[^ ]', re.M).findall(stderr)
if slot_conflicts:
changes['slot conflicts'] = slot_conflicts
blocked = re.compile(r'(?m)^\[blocks .+\] '
r'([^ ]+/[^ ]+-[0-9]+[^ ]+)'
r'.*$').findall(stdout)
unsatisfied = re.compile(
r'Error: The above package list contains').findall(stderr)
# If there were blocks and emerge could not resolve it.
if blocked and unsatisfied:
changes['blocked'] = blocked
sections = re.split('\n\n', stderr)
for section in sections:
@ -102,7 +117,7 @@ def _process_emerge_err(stderr):
changes['use'] = rexp.findall(section)
elif 'The following mask changes' in section:
changes['mask'] = rexp.findall(section)
ret['changes'] = changes
ret['changes'] = {'Needed changes': changes}
return ret
@ -551,7 +566,7 @@ def install(name=None,
call = __salt__['cmd.run_all'](cmd)
__context__.pop('pkg.list_pkgs', None)
if call['retcode'] != 0:
return _process_emerge_err(call['stderr'])
return _process_emerge_err(call['stdout'], call['stderr'])
new = list_pkgs()
changes.update(__salt__['pkg_resource.find_changes'](old, new))
return changes
@ -596,7 +611,7 @@ def update(pkg, slot=None, fromrepo=None, refresh=False):
call = __salt__['cmd.run_all'](cmd)
__context__.pop('pkg.list_pkgs', None)
if call['retcode'] != 0:
return _process_emerge_err(call['stderr'])
return _process_emerge_err(call['stdout'], call['stderr'])
new = list_pkgs()
return __salt__['pkg_resource.find_changes'](old, new)
@ -624,7 +639,7 @@ def upgrade(refresh=True):
call = __salt__['cmd.run_all'](cmd)
__context__.pop('pkg.list_pkgs', None)
if call['retcode'] != 0:
return _process_emerge_err(call['stderr'])
return _process_emerge_err(call['stdout'], call['stderr'])
new = list_pkgs()
return __salt__['pkg_resource.find_changes'](old, new)