Example #1
0
 def _package_install(self,
                      pkgname,
                      comparator=">=",
                      required_version=None,
                      update=False):
     """
     Call 'pip install pkgname' if we can satisfy the version requirements.
     """
     try:
         self.log.debug("Calling `pip install {pkg}'".format(pkg=pkgname))
         command = [sysutils.which('pip'), "install"]
         if update:
             command.append('--upgrade')
         command.append(pkgname)
         subproc.monitor_process(command, elevate=True)
         self.load_install_cache()
         installed_version = PIP_INSTALLED_CACHE.get(pkgname)
         self.log.debug("Installed version for {pkg} is: {ver}.".format(
             pkg=pkgname, ver=installed_version))
         if installed_version is None:
             return False
         if required_version is None:
             return True
         print required_version, comparator, installed_version
         return vcompare(comparator, installed_version, required_version)
     except Exception as e:
         self.log.error("Running pip install failed.")
         self.log.error(str(e))
     return False
Example #2
0
 def _package_install(self, pkg_name, comparator=">=", required_version=None):
     """
     Call 'apt-get install pkgname' if we can satisfy the version requirements.
     """
     available_version = self.get_version_from_apt_cache(pkg_name)
     if available_version is False or (required_version is not None and not vcompare(comparator, available_version, required_version)):
         return False
     try:
         subproc.monitor_process(["apt-get", "-y", "install", pkg_name], elevate=True)
     except:
         self.log.error("Running apt-get install failed.")
         return False
     installed_version = self.get_version_from_dpkg(pkg_name)
     if installed_version is False or (required_version is not None and not vcompare(comparator, installed_version, required_version)):
         return False
     return True
Example #3
0
 def _package_exists(self, pkgname, comparator=">=", required_version=None):
     """
     See if an installable version of pkgname matches the version requirements.
     """
     available_version = self.get_available_version_from_pkgr(pkgname)
     if required_version is not None and not vcompare(comparator, available_version, required_version):
         return False
     return available_version
Example #4
0
 def _package_exists(self, pkgname, comparator=">=", required_version=None):
     """
     See if an installable version of pkgname matches the version requirements.
     """
     available_version = self.get_available_version_from_pkgr(pkgname)
     if required_version is not None and not vcompare(
             comparator, available_version, required_version):
         return False
     return available_version
Example #5
0
 def _package_installed(self, pkgname, comparator=">=", required_version=None):
     """
     See if the installed version of pkgname matches the version requirements.
     """
     installed_version = self.get_installed_version_from_pkgr(pkgname)
     if not installed_version:
         return False
     if required_version is None:
         return True
     return vcompare(comparator, installed_version, required_version)
Example #6
0
 def _package_exists(self, pkg_name, comparator=">=", required_version=None):
     """
     Check if `pkg_name` is installable through this packager.
     Return type same as 'exists()'.
     """
     available_version = self.packager.get_available_version(pkg_name)
     if available_version is False \
             or (required_version is not None and not vcompare(comparator, available_version, required_version)):
         return False
     return available_version
Example #7
0
 def _package_installed(self, pkgname, comparator=">=", required_version=None):
     """
     See if the installed version of pkgname matches the version requirements.
     """
     installed_version = self.get_version_from_pkgconfig(pkgname)
     if not installed_version:
         return False
     if required_version is None or vcompare(comparator, installed_version, required_version):
         return True
         self.log.debug("Package {pkg} found by pkg-config.".format(pkg=pkgname))
     return False
Example #8
0
 def _package_installed(self,
                        pkg_name,
                        comparator=">=",
                        required_version=None):
     """
     See if the installed version of pkgname matches the version requirements.
     """
     installed_version = self.get_version_from_dpkg(pkg_name)
     if not installed_version:
         return False
     if required_version is None:
         return True
     return vcompare(comparator, installed_version, required_version)
Example #9
0
 def _package_exists(self,
                     pkg_name,
                     comparator=">=",
                     required_version=None):
     """
     Check if `pkg_name` is installable through this packager.
     Return type same as 'exists()'.
     """
     available_version = self.packager.get_available_version(pkg_name)
     if available_version is False \
             or (required_version is not None and not vcompare(comparator, available_version, required_version)):
         return False
     return available_version
Example #10
0
 def _package_install(self, pkgname, comparator=">=", required_version=None, cmd="install"):
     """
     Call 'COMMAND install pkgname' if we can satisfy the version requirements.
     """
     available_version = self.get_available_version_from_pkgr(pkgname)
     if required_version is not None and not vcompare(comparator, available_version, required_version):
         return False
     try:
         subproc.monitor_process([self.command, "-y", cmd, pkgname], elevate=True)
         return True
     except Exception as ex:
         self.log.error("Running `{0} install' failed.".format(self.command))
         self.log.obnoxious(str(ex))
     return False
Example #11
0
 def _package_installed(self, pkg_name, comparator=">=", required_version=None):
     """
     Queries the current package mananger to see if a package is installed.
     Return type same as 'installed()'.
     """
     installed_version = self.packager.get_installed_version(pkg_name)
     if not installed_version:
         return False
     if required_version is None:
         return True
     try:
         return vcompare(comparator, installed_version, required_version)
     except TypeError:
         return False
Example #12
0
 def _package_installed(self, pkgname, comparator=">=", required_version=None):
     """
     See if the installed version of pkgname matches version requirements.
     """
     installed_version = self.get_version_from_command(pkgname)
     if not installed_version:
         return False
     if required_version is None:
         return True
     if installed_version is True:
         return False
     if vcompare(comparator, installed_version, required_version):
         self.log.debug("Package {pkg} found via command line.".format(pkg=pkgname))
         return True
     return False
Example #13
0
 def _package_install(self, pkg_name, comparator=">=", required_version=None):
     """
     Installs a specific package through the current package manager.
     This is typically called by install() to do the actual package
     install call.
     Returns False if the version comparison fails.
     """
     if not self._package_exists(pkg_name, comparator, required_version):
         return False
     if not self.packager.install(pkg_name):
         return False
     installed_version = self.packager.get_installed_version(pkg_name)
     if installed_version is False \
             or (required_version is not None and not vcompare(comparator, installed_version, required_version)):
         return False
     return True
Example #14
0
 def _package_update(self, pkg_name, comparator=">=", required_version=None):
     """
     Updates a specific package through the current package manager.
     This is typically called by update() to do the actual package
     update call.
     Return type same as 'update()'.
     """
     if not self._package_exists(pkg_name, comparator, required_version):
         return False
     if not self.packager.update(pkg_name):
         return False
     installed_version = self.packager.get_installed_version(pkg_name)
     if installed_version is False \
             or (required_version is not None and not vcompare(comparator, installed_version, required_version)):
         return False
     return True
Example #15
0
 def _package_installed(self,
                        pkgname,
                        comparator=">=",
                        required_version=None):
     """
     See if the installed version of pkgname matches the version requirements.
     """
     installed_version = self.get_version_from_pkgconfig(pkgname)
     if not installed_version:
         return False
     if required_version is None or vcompare(comparator, installed_version,
                                             required_version):
         return True
         self.log.debug(
             "Package {pkg} found by pkg-config.".format(pkg=pkgname))
     return False
Example #16
0
 def _package_installed(self,
                        pkg_name,
                        comparator=">=",
                        required_version=None):
     """
     Queries the current package mananger to see if a package is installed.
     Return type same as 'installed()'.
     """
     installed_version = self.packager.get_installed_version(pkg_name)
     if not installed_version:
         return False
     if required_version is None:
         return True
     try:
         return vcompare(comparator, installed_version, required_version)
     except TypeError:
         return False
Example #17
0
 def _package_install(self,
                      pkg_name,
                      comparator=">=",
                      required_version=None):
     """
     Call 'apt-get install pkgname' if we can satisfy the version requirements.
     """
     available_version = self.get_version_from_apt_cache(pkg_name)
     if required_version is not None and not vcompare(
             comparator, available_version, required_version):
         return False
     try:
         subproc.monitor_process(["apt-get", "-y", "install", pkg_name],
                                 elevate=True)
         return True
     except:
         self.log.error("Running apt-get install failed.")
     return False
Example #18
0
 def _package_installed(self,
                        pkgname,
                        comparator=">=",
                        required_version=None):
     """
     See if the installed version of pkgname matches the version requirements.
     """
     global PIP_INSTALLED_CACHE
     if PIP_INSTALLED_CACHE is None:
         self.load_install_cache()
     installed_version = PIP_INSTALLED_CACHE.get(pkgname)
     if not installed_version:
         return False
     if required_version is None or vcompare(comparator, installed_version,
                                             required_version):
         self.log.debug(
             "Package {pkg} already installed by pip.".format(pkg=pkgname))
         return True
     return False
Example #19
0
 def _package_install(self,
                      pkg_name,
                      comparator=">=",
                      required_version=None):
     """
     Installs a specific package through the current package manager.
     This is typically called by install() to do the actual package
     install call.
     Returns False if the version comparison fails.
     """
     if not self._package_exists(pkg_name, comparator, required_version):
         return False
     if not self.packager.install(pkg_name):
         return False
     installed_version = self.packager.get_installed_version(pkg_name)
     if installed_version is False \
             or (required_version is not None and not vcompare(comparator, installed_version, required_version)):
         return False
     return True
Example #20
0
 def _package_installed(self,
                        pkgname,
                        comparator=">=",
                        required_version=None):
     """
     See if the installed version of pkgname matches version requirements.
     """
     installed_version = self.get_version_from_command(pkgname)
     if not installed_version:
         return False
     if required_version is None:
         return True
     if installed_version is True:
         return False
     if vcompare(comparator, installed_version, required_version):
         self.log.debug(
             "Package {pkg} found via command line.".format(pkg=pkgname))
         return True
     return False
Example #21
0
 def _package_update(self,
                     pkg_name,
                     comparator=">=",
                     required_version=None):
     """
     Updates a specific package through the current package manager.
     This is typically called by update() to do the actual package
     update call.
     Return type same as 'update()'.
     """
     if not self._package_exists(pkg_name, comparator, required_version):
         return False
     if not self.packager.update(pkg_name):
         return False
     installed_version = self.packager.get_installed_version(pkg_name)
     if installed_version is False \
             or (required_version is not None and not vcompare(comparator, installed_version, required_version)):
         return False
     return True
Example #22
0
 def _package_install(self,
                      pkgname,
                      comparator=">=",
                      required_version=None,
                      cmd='install'):
     """
     Call 'COMMAND install pkgname' if we can satisfy the version requirements.
     """
     available_version = self.get_available_version_from_pkgr(pkgname)
     if required_version is not None and not vcompare(
             comparator, available_version, required_version):
         return False
     try:
         subproc.monitor_process([self.command, "-y", cmd, pkgname],
                                 elevate=True)
         return True
     except Exception as ex:
         self.log.error("Running `{0} install' failed.".format(
             self.command))
         self.log.obnoxious(str(ex))
     return False