Return a list of all installed kernels.

    CLI Example:

    .. code-block:: bash

        salt '*' kernelpkg.list_installed
350648
def list_installed():
    '''
    
    '''
    pkg_re = re.compile(r'^{0}-[\d.-]+-{1}$'.format(
        _package_prefix(), _kernel_type()))
    pkgs = __salt__['pkg.list_pkgs'](versions_as_list=True)
    if pkgs is None:
        pkgs = []

    result = list(filter(pkg_re.match, pkgs))
    if result is None:
        return []

    prefix_len = len(_package_prefix()) + 1

    if six.PY2:
        return sorted([pkg[prefix_len:] for pkg in result], cmp=_cmp_version)
    else:
        return sorted([pkg[prefix_len:] for pkg in result], key=functools.cmp_to_key(_cmp_version))
1229131
def list_packages(self, installed=True, notinstalled=True):
        """"""

        self.profile = Profile()

        # Classify packages
        installed_packages = []
        notinstalled_packages = []

        for package in self.packages:
            data = {
                'name': package,
                'version': None,
                'description': self.packages.get(package).get('description')
            }
            if package in self.profile.packages:
                data['version'] = self.profile.get_package_version(
                    package, self.get_package_release_name(package))
                installed_packages += [data]
            else:
                notinstalled_packages += [data]

        # Print tables
        terminal_width, _ = click.get_terminal_size()

        if installed and installed_packages:

            # - Print installed packages table
            click.echo('\nInstalled packages:\n')

            PACKAGELIST_TPL = ('{name:20} {description:30} {version:<8}')

            click.echo('-' * terminal_width)
            click.echo(PACKAGELIST_TPL.format(
                name=click.style('Name', fg='cyan'), version='Version',
                description='Description'))
            click.echo('-' * terminal_width)

            for package in installed_packages:
                click.echo(PACKAGELIST_TPL.format(
                    name=click.style(package.get('name'), fg='cyan'),
                    version=package.get('version'),
                    description=package.get('description')))

        if notinstalled and notinstalled_packages:

            # - Print not installed packages table
            click.echo('\nNot installed packages:\n')

            PACKAGELIST_TPL = ('{name:20} {description:30}')

            click.echo('-' * terminal_width)
            click.echo(PACKAGELIST_TPL.format(
                name=click.style('Name', fg='yellow'),
                description='Description'))
            click.echo('-' * terminal_width)

            for package in notinstalled_packages:
                click.echo(PACKAGELIST_TPL.format(
                    name=click.style(package.get('name'), fg='yellow'),
                    description=package.get('description')))
1166581
def list_targets():
        
        targets = []
        obj = {
            'pyocd_version' : __version__,
            'version' : { 'major' : 1, 'minor' : 2 },
            'status' : 0,
            'targets' : targets
            }

        for name in TARGET.keys():
            s = Session(None) # Create empty session
            t = TARGET[name](s)
            d = {
                'name' : name,
                'vendor' : t.vendor,
                'part_families' : t.part_families,
                'part_number' : t.part_number,
                'source': 'pack' if hasattr(t, '_pack_device') else 'builtin',
                }
            if t._svd_location is not None:
                svdPath = t._svd_location.filename
                if isinstance(svdPath, six.string_types) and os.path.exists(svdPath):
                    d['svd_path'] = svdPath
            targets.append(d)
        
        # Add targets from cmsis-pack-manager cache.
        for dev in pack_target.ManagedPacks.get_installed_targets():
            try:
                targets.append({
                    'name' : dev.part_number.lower(),
                    'part_families' : dev.families,
                    'part_number' : dev.part_number,
                    'vendor' : dev.vendor,
                    'source' : 'pack',
                    })
            except KeyError:
                pass

        return obj
218445
def filter_installed_packages(packages):
    """"""
    cache = apt_cache()
    _pkgs = []
    for package in packages:
        try:
            p = cache[package]
            p.current_ver or _pkgs.append(package)
        except KeyError:
            log('Package {} has no installation candidate.'.format(package),
                level='WARNING')
            _pkgs.append(package)
    return _pkgs
172459
def list_upgrades(refresh=False, root=None, **kwargs):  # pylint: disable=W0613
    '''
    
    '''
    upgrades = {}
    cmd = ['pacman', '-S', '-p', '-u', '--print-format', '%n %v']

    if root is not None:
        cmd.extend(('-r', root))

    if refresh:
        cmd.append('-y')

    call = __salt__['cmd.run_all'](cmd,
                                   python_shell=False,
                                   output_loglevel='trace')

    if call['retcode'] != 0:
        comment = ''
        if 'stderr' in call:
            comment += call['stderr']
        if 'stdout' in call:
            comment += call['stdout']
        if comment:
            comment = ': ' + comment
        raise CommandExecutionError('Error listing upgrades' + comment)
    else:
        out = call['stdout']

    for line in salt.utils.itertools.split(out, '\n'):
        try:
            pkgname, pkgver = line.split()
        except ValueError:
            continue
        if pkgname.lower() == 'downloading' and '.db' in pkgver.lower():
            # Antergos (and possibly other Arch derivatives) add lines when pkg
            # metadata is being downloaded. Because these lines, when split,
            # contain two columns (i.e. 'downloading community.db...'), we will
            # skip this line to keep it from being interpreted as an upgrade.
            continue
        upgrades[pkgname] = pkgver
    return upgrades
1088956
def list_upgrades(refresh=True, **kwargs):  # pylint: disable=W0613
    '''
    
    '''
    if salt.utils.data.is_true(refresh):
        refresh_db()
    upgrades = {}
    lines = __salt__['cmd.run_stdout'](
        '/opt/csw/bin/pkgutil -A --parse').splitlines()
    for line in lines:
        comps = line.split('\t')
        if comps[2] == "SAME":
            continue
        if comps[2] == "not installed":
            continue
        upgrades[comps[0]] = comps[1]
    return upgrades
1101108
def output_kernels(gandi, flavor, name_list, justify=14):
    
    output_line(gandi, 'flavor', flavor, justify)
    for name in name_list:
        output_line(gandi, 'version', name, justify)
881785
def get_installed_distributions(skip=stdlib_pkgs):
    
    return [d for d in pkg_resources.working_set
            if d.key not in skip]
642152
def list_repos(**kwargs):
    '''
    
    '''
    _check_apt()
    repos = {}
    sources = sourceslist.SourcesList()
    for source in sources.list:
        if _skip_source(source):
            continue
        repo = {}
        repo['file'] = source.file
        repo['comps'] = getattr(source, 'comps', [])
        repo['disabled'] = source.disabled
        repo['enabled'] = not repo['disabled']  # This is for compatibility with the other modules
        repo['dist'] = source.dist
        repo['type'] = source.type
        repo['uri'] = source.uri.rstrip('/')
        repo['line'] = salt.utils.pkg.deb.strip_uri(source.line.strip())
        repo['architectures'] = getattr(source, 'architectures', [])
        repos.setdefault(source.uri, []).append(repo)
    return repos
896602
def find_kernel_specs(self):
        """"""
        # let real installed kernels overwrite envs with the same name:
        # this is the same order as the get_kernel_spec way, which also prefers
        # kernels from the jupyter dir over env kernels.
        specs = self.find_kernel_specs_for_envs()
        specs.update(super(EnvironmentKernelSpecManager,
                           self).find_kernel_specs())
        return specs
604280
def find_packages(root_directory: str = '.') -> t.List[str]:
    """"""
    exclude = ['test*', 'test.*'] if ('bdist_wheel' in sys.argv or 'bdist' in sys.argv) else []
    packages_list = setuptools.find_packages(root_directory, exclude=exclude)
    return packages_list
290867
def installed_packages(self):
        
        packages = []
        CMDLINE = [sys.executable, "-mpip", "freeze"]
        try:
            for package in subprocess.check_output(CMDLINE) \
                    .decode('utf-8'). \
                    splitlines():
                for comparator in ["==", ">=", "<=", "<", ">"]:
                    if comparator in package:
                        # installed package names usually look like Pillow==2.8.1
                        # ignore others, like external packages that pip show
                        # won't understand
                        name = package.partition(comparator)[0]
                        packages.append(name)
        except RuntimeError as e:
            if logger.isEnabledFor(logging.DEBUG):
                logger.debug("Exception checking existing packages.")
                logger.debug("cmdline: %s", CMDLINE)
                ex_type, ex, tb = sys.exc_info()
                traceback.print_tb(tb)
                logger.debug()
        return packages
98176
def list_pkgs(*packages, **kwargs):
    '''
    
    '''
    pkgs = {}
    cmd = ['rpm']
    if kwargs.get('root'):
        cmd.extend(['--root', kwargs['root']])
    cmd.extend(['-q' if packages else '-qa',
                '--queryformat', r'%{NAME} %{VERSION}\n'])
    if packages:
        cmd.extend(packages)
    out = __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False)
    for line in salt.utils.itertools.split(out, '\n'):
        if 'is not installed' in line:
            continue
        comps = line.split()
        pkgs[comps[0]] = comps[1]
    return pkgs
335980
def find_installed_packages(self):
        
        list_command = subprocess.Popen(self.list_command, shell=True, stdout=subprocess.PIPE)
        stdout, stderr = list_command.communicate()
        if list_command.returncode != 0:
            raise SystemDependencyError("The command to list the installed system packages failed! ({command})",
                                        command=self.list_command)
        installed_packages = sorted(stdout.decode().split())
        logger.debug("Found %i installed system package(s): %s", len(installed_packages), installed_packages)
        return installed_packages
926667
def list_states(self, saltenv):
        '''
        
        '''
        states = set()
        for path in self.file_list(saltenv):
            if salt.utils.platform.is_windows():
                path = path.replace('\\', '/')
            if path.endswith('.sls'):
                # is an sls module!
                if path.endswith('/init.sls'):
                    states.add(path.replace('/', '.')[:-9])
                else:
                    states.add(path.replace('/', '.')[:-4])
        return sorted(states)
1212625
def kernel_modules(attrs=None, where=None):
    '''
    
    '''
    if __grains__['os_family'] in ['RedHat', 'Debian']:
        return _osquery_cmd(table='kernel_modules', attrs=attrs, where=where)
    return {'result': False, 'comment': 'Only available on Red Hat or Debian based systems.'}
764696
def kernel_version(self):
        
        result = self.shell.execute(self.commands.kernel_version.value)
        stdout = self.shell.decode(result['stdout'])
        stderr = self.shell.decode(result['stderr'])
        return stdout