Get list of pip installed packages.
497106
def pip_list(self, name=None, prefix=None, abspath=True):
        """"""
        if (name and prefix) or not (name or prefix):
            raise TypeError("conda pip: exactly one of 'name' ""or 'prefix' "
                            "required.")

        if name:
            prefix = self.get_prefix_envname(name)

        pip_command = os.sep.join([prefix, 'bin', 'python'])
        cmd_list = [pip_command, PIP_LIST_SCRIPT]
        process_worker = ProcessWorker(cmd_list, pip=True, parse=True,
                                       callback=self._pip_list,
                                       extra_kwargs={'prefix': prefix})
        process_worker.sig_finished.connect(self._start)
        self._queue.append(process_worker)
        self._start()

        return process_worker
133683
def main():
    """"""
    pip_packages = {}
    for package in pip.get_installed_distributions():
        name = package.project_name
        version = package.version
        full_name = "{0}-{1}-pip".format(name.lower(), version)
        pip_packages[full_name] = {'version': version}
    data = json.dumps(pip_packages)
    print(data)
1313261
def _get_package_data():
    
    from os import listdir as ls
    from os.path import join as jn

    x = 'init'
    b = jn('serv', x)
    dr = ['binaries', 'templates']
    return [jn(x, d, f) for d in ls(b) if d in dr for f in ls(jn(b, d))]
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')))
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
14458
def getInstalled():
    
    installed = _find_installed()
    return [os.path.basename(p.pathname)[3:] for p in installed]
73619
def list_of_installed(self, repo, name):
        
        all_installed_names = []
        all_installed_packages = find_package("", self.meta.pkg_path)
        for inst in all_installed_packages:
            if repo == "sbo" and inst.endswith("_SBo"):
                name = split_package(inst)[0]
                all_installed_names.append(name)
            else:
                if name:
                    all_installed_names.append(split_package(inst)[0])
                else:
                    all_installed_names.append(inst)
        return all_installed_names
869832
def pip(usr_pswd=None):
	
	# see if pip is installed
	try: cmd('which pip')
	except:
		return

	print('-[pip]----------')
	p = cmd('pip list --outdated')
	if not p: return
	pkgs = getPackages(p)

	# update pip and setuptools first
	for i, p in enumerate(pkgs):
		if p in ['pip', 'setuptools']:
			cmd('pip install -U ' + p, usr_pwd=usr_pswd, run=global_run)
			pkgs.pop(i)

	# update the rest of them
	for p in pkgs:
		cmd('pip install -U ' + p, usr_pwd=usr_pswd, run=global_run)
286855
def pip_upgrade_all(line):
    """"""
    from pip import get_installed_distributions
    user = set(d.project_name for d in get_installed_distributions(user_only=True))
    all = set(d.project_name for d in get_installed_distributions())
    for dist in all - user:
        do_pip(["install", "--upgrade", dist])
    for dist in  user:
        do_pip(["install", "--upgrade", "--user", dist])
641898
def get_package_data():
    """"""
    package_data = dict()

    package_data['PyQt5'] = list()
    for subdir in ("doc/", "examples/", "include/",
                   "mkspecs/", "plugins/", "qml/",
                   "qsci/", "sip/", "translations/", "uic/"):
        abspath = os.path.abspath("PyQt5/" + subdir)
        for root, dirs, files in os.walk(abspath):
            for f in files:
                fpath = os.path.join(root, f)
                relpath = os.path.relpath(fpath, abspath)
                relpath = relpath.replace("\\", "/")
                package_data['PyQt5'].append(subdir + relpath)

    package_data['PyQt5'].extend(["*.exe",
                                  "*.dll",
                                  "*.pyd",
                                  "*.conf",
                                  "*.api",
                                  "*.qm",
                                  "*.bat"])
    return package_data
903920
def get_packaged_files(package_name):
    
    if not os.path.isdir('dist'):
        return []
    return [os.path.join('dist', filename) for filename in os.listdir('dist')]
734605
def list_installed():
    '''
    
    '''
    cmd = 'Get-WindowsFeature ' \
          '-ErrorAction SilentlyContinue ' \
          '-WarningAction SilentlyContinue ' \
          '| Select DisplayName,Name,Installed'
    features = _pshell_json(cmd)

    ret = {}
    for entry in features:
        if entry['Installed']:
            ret[entry['Name']] = entry['DisplayName']

    return ret
31094
def is_installed(name):
    
    pkgs = installed_packages()
    for pkge in pkgs:
        if pkge.name == name:
            return True
    return False
543059
def LoadInstallations(counter):
    
    process = subprocess.Popen(["pip", "list", "--format=json"],
                               stdout=subprocess.PIPE)
    output, _ = process.communicate()
    installations = json.loads(output)
    for i in installations:
        counter.labels(i["name"], i["version"]).inc()
925650
def filter_installed_packages(packages):
    """"""
    yb = yum.YumBase()
    package_list = yb.doPackageLists()
    temp_cache = {p.base_package_name: 1 for p in package_list['installed']}

    _pkgs = [p for p in packages if not temp_cache.get(p, False)]
    return _pkgs
490512
def pkg_version_list(self, pkg_id):
        '''
        
        '''
        pkg_data = self.__reg_software.get(pkg_id, None)
        if not pkg_data:
            return []

        if isinstance(pkg_data, list):
            # raw data is 'pkgid': [sorted version list]
            return pkg_data  # already sorted oldest to newest

        # Must be a dict or OrderDict, and contain full details
        installed_versions = list(pkg_data.get('version').keys())
        return sorted(installed_versions, key=cmp_to_key(self.__oldest_to_latest_version))
573228
def package_info(self):
        
        import subprocess
        # create a commandline like  pip show Pillow show
        package_names = self.installed_packages()
        if not package_names:
            # No installed packages yet, so nothign to do here...
            return []

        cmdline = [sys.executable, "-mpip"]
        for name in package_names:
            cmdline.extend(["show", name])

        output = subprocess.check_output(cmdline)
        # Python 3 fix
        if not isinstance(output, str):
            # Some package info is encoded in Latin-1 or something other than
            # UTF8.  Replace non-UTF characters with '?' instead of crashing.
            output = str(output, encoding='UTF-8', errors='replace')

        # parse output that looks like this example
        """
        ---
        Name: Pillow
        Version: 2.8.1
        Location: /mnt/data/home/stu/.virtualenvs/shoebot-setup/lib/python2.7/site-packages/Pillow-2.8.1-py2.7-linux-x86_64.egg
        Requires:
        ---
        Name: vext.gi
        Version: 0.5.6.25
        Location: /mnt/data/home/stu/.virtualenvs/shoebot-setup/lib/python2.7/site-packages/vext.gi-0.5.6.25-py2.7.egg
        Requires: vext

        """
        results = []
        for info in output[3:].split("---"):
            d = {}
            for line in info[1:].splitlines():
                arg, _, value = line.partition(': ')
                arg = arg.lower()
                if arg == 'requires':
                    value = value.split(', ')
                d[arg] = value
            results.append(d)
        return results