def list_pkgs(versions_as_list=False, **kwargs):
    '''
    List the filesets/rpm packages currently installed as a dict:

    .. code-block:: python

        {'<package_name>': '<version>'}

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_pkgs
    '''
    ret = {}
    versions_as_list = salt.utils.data.is_true(versions_as_list)
    # not yet implemented or not applicable
    if any([salt.utils.data.is_true(kwargs.get(x))
            for x in ('removed', 'purge_desired')]):
        return ret

    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

    # cmd returns information colon delimited in a single linei, format
    #   Package Name:Fileset:Level:State:PTF Id:Fix State:Type:Description:
    #       Destination Dir.:Uninstaller:Message Catalog:Message Set:
    #       Message Number:Parent:Automatic:EFIX Locked:Install Path:Build Date
    # Example:
    #   xcursor:xcursor-1.1.7-3:1.1.7-3: : :C:R:X Cursor library: :\
    #       /bin/rpm -e xcursor: : : : :0: :(none):Mon May  8 15:18:35 CDT 2017
    #   bos:bos.rte.libcur:7.1.5.0: : :C:F:libcurses Library: : : : : : :0:0:/:1731
    #
    # where Type codes: F -- Installp Fileset, P -- Product, C -- Component,
    #                   T -- Feature, R -- RPM Package
    cmd = '/usr/bin/lslpp -Lc'
    lines = __salt__['cmd.run'](
            cmd,
            python_shell=False).splitlines()

    for line in lines:
        if line.startswith('#'):
            continue

        comps = line.split(':')
        if len(comps) < 7:
            continue

        if 'R' in comps[6]:
            name = comps[0]
        else:
            name = comps[1]     # use fileset rather than rpm package

        version_num = comps[2]
        __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 ) : ret = { } versions_as_list = salt . utils . data . is_true ( versions_as_list ) if any ( [ salt . utils . data . is_true ( kwargs . get ( x ) ) for x in ( 'removed' , 'purge_desired' ) ] ) : return ret 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 cmd = '/usr/bin/lslpp -Lc' lines = __salt__ [ 'cmd.run' ] ( cmd , python_shell = False ) . splitlines ( ) for line in lines : if line . startswith ( '#' ) : continue comps = line . split ( ':' ) if len ( comps ) < 7 : continue if 'R' in comps [ 6 ] : name = comps [ 0 ] else : name = comps [ 1 ] version_num = comps [ 2 ] __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 filesets/rpm packages currently installed as a dict:

    .. code-block:: python

        {'<package_name>': '<version>'}

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.list_pkgs