Add support for pip list format=columns (#21990)

* Use 'pip list --format=freeze' to simplify output code parse
This commit is contained in:
Rob Nieuwenhuizen 2017-08-08 08:56:04 +02:00 committed by Toshio Kuratomi
parent 49eb81d573
commit 73e19c2ed1

View file

@ -250,7 +250,7 @@ def _get_full_name(name, version=None):
def _get_packages(module, pip, chdir):
'''Return results of pip command to get packages.'''
# Try 'pip list' command first.
command = '%s list' % pip
command = '%s list --format=freeze' % pip
lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
rc, out, err = module.run_command(command, cwd=chdir, environ_update=lang_env)
@ -267,19 +267,8 @@ def _get_packages(module, pip, chdir):
def _is_present(name, version, installed_pkgs, pkg_command):
'''Return whether or not package is installed.'''
for pkg in installed_pkgs:
# Package listing will be different depending on which pip
# command was used ('pip list' vs. 'pip freeze').
if 'list' in pkg_command:
pkg = pkg.replace('(', '').replace(')', '')
if ',' in pkg:
pkg_name, pkg_version, _ = pkg.replace(',', '').split(' ')
else:
pkg_name, pkg_version = pkg.split(' ')
elif 'freeze' in pkg_command:
if '==' in pkg:
pkg_name, pkg_version = pkg.split('==')
else:
continue
if '==' in pkg:
pkg_name, pkg_version = pkg.split('==')
else:
continue