def _get_upgradable(backtrack=3):
 cmd = ['emerge', '--ask', 'n', '--backtrack', '{0}'.format(backtrack), '--pretend', '--update', '--newuse', '--deep', '@world']
 call = __salt__['cmd.run_all'](cmd, output_loglevel='trace', python_shell=False)
 if (call['retcode'] != 0):
  msg = 'Failed to get upgrades'
  for key in ('stderr', 'stdout'):
   if call[key]:
    msg += (': ' + call[key])
    break
  raise CommandExecutionError(msg)
 else:
  out = call['stdout']
 rexp = re.compile('(?m)^\\[.+\\] ([^ ]+/[^ ]+)-([0-9]+[^ ]+).*$')
 keys = ['name', 'version']
 _get = (lambda l, k: l[keys.index(k)])
 upgrades = rexp.findall(out)
 ret = {}
 for line in upgrades:
  name = _get(line, 'name')
  version_num = _get(line, 'version')
  ret[name] = version_num
 return ret

def _get_upgradable ( backtrack = 3 ) : cmd = [ 'emerge' , '--ask' , 'n' , '--backtrack' , '{0}' . format ( backtrack ) , '--pretend' , '--update' , '--newuse' , '--deep' , '@world' ] call = __salt__ [ 'cmd.run_all' ] ( cmd , output_loglevel = 'trace' , python_shell = False ) if ( call [ 'retcode' ] != 0 ) : msg = 'Failed to get upgrades' for key in ( 'stderr' , 'stdout' ) : if call [ key ] : msg += ( ': ' + call [ key ] ) break raise CommandExecutionError ( msg ) else : out = call [ 'stdout' ] rexp = re . compile ( '(?m)^\\[.+\\] ([^ ]+/[^ ]+)-([0-9]+[^ ]+).*$' ) keys = [ 'name' , 'version' ] _get = ( lambda l , k : l [ keys . index ( k ) ] ) upgrades = rexp . findall ( out ) ret = { } for line in upgrades : name = _get ( line , 'name' ) version_num = _get ( line , 'version' ) ret [ name ] = version_num return ret
utility function to get upgradable packages sample return data: { pkgname: 1 .