Show packages which are already installed if adaquate

This commit is contained in:
Joshua Harlow
2012-08-27 13:19:34 -07:00
parent 0db085a661
commit 83330ed10d
7 changed files with 70 additions and 94 deletions

View File

@@ -18,7 +18,7 @@ from pkg_resources import Requirement
from anvil import shell as sh
FREEZE_CMD = ['pip-python', 'freeze', '--local']
FREEZE_CMD = ['freeze', '--local']
# Cache of whats installed - 'uncached' as needed
_installed_cache = None
@@ -29,8 +29,9 @@ def uncache():
_installed_cache = None
def _list_installed():
(stdout, _stderr) = sh.execute(*FREEZE_CMD)
def _list_installed(pip_how):
cmd = [pip_how] + FREEZE_CMD
(stdout, _stderr) = sh.execute(*cmd)
installed = []
for line in stdout.splitlines():
line = line.strip()
@@ -52,8 +53,8 @@ def _list_installed():
return installed
def is_installed(name):
whats_there = get_installed()
def is_installed(pip_how, name):
whats_there = get_installed(pip_how)
for req in whats_there:
if not (name.lower() == req.project_name.lower()):
continue
@@ -61,19 +62,20 @@ def is_installed(name):
return False
def get_installed():
def get_installed(pip_how):
global _installed_cache
if _installed_cache is None:
_installed_cache = _list_installed()
_installed_cache = _list_installed(pip_how)
return _installed_cache
def is_adequate_installed(name, version):
whats_there = get_installed()
def is_adequate_installed(pip_how, name, version):
whats_there = get_installed(pip_how)
for req in whats_there:
if not (name.lower() == req.project_name.lower()):
continue
if not version:
return True
return version in req
return False
return req
if version in req:
return req
return None

View File

@@ -52,7 +52,7 @@ def is_adequate_installed(name, version):
ignore_case=True, patterns=[name])
whats_installed = pkg_obj.installed
if not whats_installed:
return False
return None
# Compare whats installed to a fake package that will
# represent what might be installed...
fake_pkg = PackageObject()
@@ -61,5 +61,5 @@ def is_adequate_installed(name, version):
fake_pkg.version = str(version)
for installed_pkg in whats_installed:
if installed_pkg.verGE(fake_pkg):
return True
return False
return installed_pkg
return None

View File

@@ -17,7 +17,6 @@
from anvil import log as logging
from anvil import packager as pack
from anvil import shell as sh
from anvil import utils
from anvil.packaging.helpers import pip_helper
@@ -39,17 +38,12 @@ class Packager(pack.Packager):
def _get_pip_command(self):
return self.distro.get_command_config('pip')
def _compare_against_installed(self, pkg):
name = pkg['name']
version = pkg.get('version')
def _anything_there(self, pkg):
# Anything with options always gets installed
options = pkg.get('options')
if options:
return pack.DO_INSTALL
if pip_helper.is_adequate_installed(name, version):
return pack.ADEQUATE_INSTALLED
else:
return pack.DO_INSTALL
if 'options' in pkg:
return None
return pip_helper.is_adequate_installed(self._get_pip_command(),
pkg['name'], pkg.get('version'))
def _execute_pip(self, cmd):
pip_cmd = self._get_pip_command()
@@ -76,8 +70,7 @@ class Packager(pack.Packager):
def _remove(self, pip):
# Versions don't seem to matter here...
name = self._make_pip_name(pip['name'], None)
if not pip_helper.is_installed(name):
return pack.NOT_EXISTENT
if not pip_helper.is_installed(self._get_pip_command(), name):
return
cmd = ['uninstall'] + PIP_UNINSTALL_CMD_OPTS + [name]
self._execute_pip(cmd)
return pack.REMOVED_OK

View File

@@ -36,14 +36,8 @@ class YumPackager(pack.Packager):
else:
return str(name)
def _compare_against_installed(self, pkg):
name = pkg['name']
version = pkg.get('version')
if yum_helper.is_installed(name, version) or \
yum_helper.is_adequate_installed(name, version):
return pack.ADEQUATE_INSTALLED
else:
return pack.DO_INSTALL
def _anything_there(self, pkg):
return yum_helper.is_adequate_installed(pkg['name'], pkg.get('version'))
def _execute_yum(self, cmd, **kargs):
yum_cmd = YUM_CMD + cmd
@@ -66,9 +60,8 @@ class YumPackager(pack.Packager):
def _remove(self, pkg):
name = pkg['name']
if not yum_helper.is_installed(name, version=None):
return pack.NOT_EXISTENT
return
if self._remove_special(name, pkg):
return pack.REMOVED_OK
return
cmd = YUM_REMOVE + [self._format_pkg_name(name, pkg.get("version"))]
self._execute_yum(cmd)
return pack.REMOVED_OK