def list_pkgs(versions_as_list=False, **kwargs):
 versions_as_list = salt.utils.is_true(versions_as_list)
 if any([salt.utils.is_true(kwargs.get(x)) for x in ('removed', 'purge_desired')]):
  return {}
 if ('pkg.list_pkgs' in __context__):
  if versions_as_list:
   return __context__['pkg.list_pkgs']
  else:
   ret = copy.deepcopy(__context__['pkg.list_pkgs'])
   __salt__['pkg_resource.stringify'](ret)
   return ret
 ret = {}
 cmd = ['port', 'installed']
 out = salt.utils.mac_utils.execute_return_result(cmd)
 for line in out.splitlines():
  try:
   (name, version_num, active) = re.split('\\s+', line.lstrip())[0:3]
   version_num = version_num[1:]
  except ValueError:
   continue
  if ((not LIST_ACTIVE_ONLY) or (active == '(active)')):
   __salt__['pkg_resource.add_pkg'](ret, name, version_num)
 __salt__['pkg_resource.sort_pkglist'](ret)
 __context__['pkg.list_pkgs'] = copy.deepcopy(ret)
 if (not versions_as_list):
  __salt__['pkg_resource.stringify'](ret)
 return ret

def list_pkgs ( versions_as_list = False , ** kwargs ) : versions_as_list = salt . utils . is_true ( versions_as_list ) if any ( [ salt . utils . is_true ( kwargs . get ( x ) ) for x in ( 'removed' , 'purge_desired' ) ] ) : return { } if ( 'pkg.list_pkgs' in __context__ ) : if versions_as_list : return __context__ [ 'pkg.list_pkgs' ] else : ret = copy . deepcopy ( __context__ [ 'pkg.list_pkgs' ] ) __salt__ [ 'pkg_resource.stringify' ] ( ret ) return ret ret = { } cmd = [ 'port' , 'installed' ] out = salt . utils . mac_utils . execute_return_result ( cmd ) for line in out . splitlines ( ) : try : ( name , version_num , active ) = re . split ( '\\s+' , line . lstrip ( ) ) [ 0 : 3 ] version_num = version_num [ 1 : ] except ValueError : continue if ( ( not LIST_ACTIVE_ONLY ) or ( active == '(active)' ) ) : __salt__ [ 'pkg_resource.add_pkg' ] ( ret , name , version_num ) __salt__ [ 'pkg_resource.sort_pkglist' ] ( ret ) __context__ [ 'pkg.list_pkgs' ] = copy . deepcopy ( ret ) if ( not versions_as_list ) : __salt__ [ 'pkg_resource.stringify' ] ( ret ) return ret
list the packages currently installed in a dict:: {<package_name>: <version>} cli example: .