예제 #1
0
파일: apt.py 프로젝트: Audioholic11/pybombs
 def get_available_version(self, pkgname):
     """
     Check which version is available.
     """
     if self.cache:
         self.log.obnoxious("Checking apt for `{0}'".format(pkgname))
         (ver, is_installed) = self.check_cache(pkgname)
         if ver:
             self.log.debug("Package {0} has version {1} in repositories".format(pkgname, ver))
         return ver
     else:
         try:
             self.log.obnoxious("Checking {0} for `{1}'".format(self.searchcmd, pkgname))
             ver = subproc.match_output(
                 [self.searchcmd, "show", pkgname],
                 r'Version: (?:\d+:)?(?P<ver>[0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+|[0-9]+).*\n',
                 'ver'
             )
             if ver is None:
                 return False
             if ver:
                 self.log.debug("Package {0} has version {1} in repositories".format(pkgname, ver))
             return ver
         except subprocess.CalledProcessError:
             # Could be an issue, but most likely it means the package doesn't exist.
             self.log.debug(
                 "{cmd} show {pkg} failed.".format(cmd=self.searchcmd, pkg=pkgname)
             )
     return False
예제 #2
0
파일: apt.py 프로젝트: ckuethe/pybombs
 def get_available_version(self, pkgname):
     """
     Check which version is available.
     """
     if self.cache:
         self.log.obnoxious("Checking apt for `{0}'".format(pkgname))
         (ver, is_installed) = self.check_cache(pkgname)
         if ver:
             self.log.debug("Package {0} has version {1} in repositories".format(pkgname, ver))
         return ver
     else:
         try:
             self.log.obnoxious("Checking {0} for `{1}'".format(self.searchcmd, pkgname))
             ver = subproc.match_output(
                 [self.searchcmd, "show", pkgname],
                 r'Version: (?:\d+:)?(?P<ver>[0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+|[0-9]+).*\n',
                 'ver'
             )
             if ver is None:
                 return False
             if ver:
                 self.log.debug("Package {0} has version {1} in repositories".format(pkgname, ver))
             return ver
         except subprocess.CalledProcessError:
             self.log.error("Error running {0} show. This shouldn't happen. Probably a bug.".format(pkgname))
     return False
예제 #3
0
파일: cmd.py 프로젝트: ferhat1234/proje
 def get_installed_version(self, command):
     """
     Run command, see if it works. If the output has a version number in
     x.y.z format, return that. If it doesn't, but the command ran, return
     True. If it fails, return False. ezpz.
     """
     try:
         # If this fails, it almost always throws.
         # NOTE: the split is to handle multi-argument commands. There's
         # cases where this is not intended, e.g. it won't handle arguments
         # with spaces! But currently this is preferable to running the
         # command in a shell.
         ver = subproc.match_output(
             command.split(),
             r'(?P<ver>[0-9]+\.[0-9]+(\.[0-9]+)?)',
             'ver'
         )
         if ver is None:
             self.log.debug("Could run, but couldn't find a version number.")
             return True
         self.log.debug("Found version number: {0}".format(ver))
         return ver
     except (subprocess.CalledProcessError, OSError):
         # We'll assume it's not installed
         return False
     except Exception as e:
         self.log.error("Running `{0}` failed.".format(command))
         self.log.obnoxious(str(e))
     return False
예제 #4
0
파일: apt.py 프로젝트: ClassOdUa/pybombs
 def get_installed_version(self, pkgname):
     """
     Use dpkg (or python-apt) to determine and return the currently installed version.
     If pkgname is not installed, return None.
     """
     if self.cache:
         (ver, is_installed) = self.check_cache(pkgname)
         if is_installed:
             self.log.debug("Package {0} has version {1} installed".format(pkgname, ver))
         return ver if is_installed else False
     else:
         try:
             ver = subproc.match_output(
                 ["dpkg", "-s", pkgname],
                 r'^Version: (?:\d+:)?(?P<ver>[0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+|[0-9]+)',
                 'ver'
             )
             if ver is None:
                 self.log.debug("Looks like dpkg -s can't find package {pkg}. This is most likely a bug.".format(pkg=pkgname))
                 return False
             self.log.debug("Package {0} has version {1} installed".format(pkgname, ver))
             return ver
         except subprocess.CalledProcessError:
             # This usually means the packet is not installed -- not a problem.
             return False
         except Exception as e:
             self.log.error("Running dpkg -s failed.")
             self.log.obnoxious(str(e))
     return False
예제 #5
0
파일: pacman.py 프로젝트: gnuradio/pybombs
 def get_installed_version(self, pkgname):
     """
     Return the currently installed version. If pkgname is not installed,
     return None.
     """
     try:
         # '-Qi' will return non-zero if package does not exist, thus will throw
         # Output is sth like local/<pkgname> x.x.x.x-x
         ver = subproc.match_output(
             [self.command, "-Qi", pkgname],
             r'Version[ ]*: (?P<ver>[0-9,.]*)',
             'ver'
         )
         if ver is None:
             self.log.debug("Looks like pacman -Qi can't find package {pkg}".format(pkg=pkgname))
             return False
         self.log.debug("Package {0} has version {1}".format(pkgname, ver))
         return ver
     except subprocess.CalledProcessError:
         # This usually means the packet is not installed
         return False
     except Exception as ex:
         self.log.error("Parsing `{0} -Qi` failed.".format(self.command))
         self.log.trace(str(ex))
     return False
예제 #6
0
 def get_installed_version(self, pkgname):
     """
     Use dpkg (or python-apt) to determine and return the currently installed version.
     If pkgname is not installed, return None.
     """
     if self.cache:
         (ver, is_installed) = self.check_cache(pkgname)
         if is_installed:
             self.log.debug("Package {0} has version {1} installed".format(
                 pkgname, ver))
         return ver if is_installed else False
     else:
         try:
             ver = subproc.match_output([
                 "dpkg", "-s", pkgname
             ], r'^Version: (?:\d+:)?(?P<ver>[0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+|[0-9]+)',
                                        'ver')
             if ver is None:
                 self.log.debug(
                     "Looks like dpkg -s can't find package {pkg}. This is most likely a bug."
                     .format(pkg=pkgname))
                 return False
             self.log.debug("Package {0} has version {1} installed".format(
                 pkgname, ver))
             return ver
         except subprocess.CalledProcessError:
             # This usually means the packet is not installed -- not a problem.
             return False
         except Exception as e:
             self.log.error("Running dpkg -s failed.")
             self.log.obnoxious(str(e))
     return False
예제 #7
0
 def get_available_version(self, pkgname):
     """
     Return a version that we can install through this package manager.
     """
     try:
         ver = subproc.match_output(
             [self.command, "info", pkgname],
             r'^Version\s+:\s+(?P<ver>.*$)',
             'ver',
             env=utils.dict_merge(os.environ, {'LC_ALL': 'C'}),
         )
         if ver is None:
             return False
         self.log.debug("Package {0} has version {1} in {2}".format(
             pkgname, ver, self.command))
         return ver
     except subprocess.CalledProcessError as ex:
         # This usually means the package was not found, so don't worry
         self.log.obnoxious(
             "`{0} info' returned non-zero exit status.".format(
                 self.command))
         self.log.obnoxious(str(ex))
         return False
     except Exception as ex:
         self.log.error("Error parsing {0} info".format(self.command))
         self.log.error(str(ex))
     return False
예제 #8
0
파일: apt.py 프로젝트: ClassOdUa/pybombs
 def get_available_version(self, pkgname):
     """
     Check which version is available.
     """
     if self.cache:
         self.log.obnoxious("Checking apt for `{0}'".format(pkgname))
         (ver, is_installed) = self.check_cache(pkgname)
         if ver:
             self.log.debug("Package {0} has version {1} in repositories".format(pkgname, ver))
         return ver
     else:
         try:
             self.log.obnoxious("Checking {0} for `{1}'".format(self.searchcmd, pkgname))
             ver = subproc.match_output(
                 [self.searchcmd, "show", pkgname],
                 r'Version: (?:\d+:)?(?P<ver>[0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+|[0-9]+).*\n',
                 'ver'
             )
             if ver is None:
                 return False
             if ver:
                 self.log.debug("Package {0} has version {1} in repositories".format(pkgname, ver))
             return ver
         except subprocess.CalledProcessError:
             # Could be an issue, but most likely it means the package doesn't exist.
             self.log.debug(
                 "{cmd} show {pkg} failed.".format(cmd=self.searchcmd, pkg=pkgname)
             )
     return False
예제 #9
0
 def get_available_version(self, pkgname):
     """
     Check which version is available.
     """
     if self.cache:
         self.log.obnoxious("Checking apt for `{0}'".format(pkgname))
         (ver, is_installed) = self.check_cache(pkgname)
         if ver:
             self.log.debug(
                 "Package {0} has version {1} in repositories".format(
                     pkgname, ver))
         return ver
     else:
         try:
             self.log.obnoxious("Checking {0} for `{1}'".format(
                 self.searchcmd, pkgname))
             ver = subproc.match_output([
                 self.searchcmd, "show", pkgname
             ], r'Version: (?:\d+:)?(?P<ver>[0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+|[0-9]+).*\n',
                                        'ver')
             if ver is None:
                 return False
             if ver:
                 self.log.debug(
                     "Package {0} has version {1} in repositories".format(
                         pkgname, ver))
             return ver
         except subprocess.CalledProcessError:
             self.log.error(
                 "Error running {0} show. This shouldn't happen. Probably a bug."
                 .format(pkgname))
     return False
예제 #10
0
 def get_installed_version(self, pkgname):
     """
     Return the currently installed version. If pkgname is not installed,
     return None.
     """
     try:
         # '-Qi' will return non-zero if package does not exist, thus will throw
         # Output is sth like local/<pkgname> x.x.x.x-x
         ver = subproc.match_output([self.command, "-Si", pkgname],
                                    r'Version[ ]*: (?P<ver>[0-9,.]*)',
                                    'ver')
         if ver is None:
             self.log.debug(
                 "Looks like pacman -Qi can't find package {pkg}".format(
                     pkg=pkgname))
             return False
         self.log.debug("Package {} has version {}".format(pkgname, ver))
         return ver
     except subprocess.CalledProcessError:
         # This usually means the packet is not installed
         return False
     except Exception as ex:
         self.log.error("Parsing `{0} -Qi` failed.".format(self.command))
         self.log.obnoxious(str(ex))
     return False
예제 #11
0
파일: pip.py 프로젝트: ferhat1234/proje
 def get_available_version(self, pkgname):
     """
     See if 'pip search' finds our package.
     """
     try:
         output_match = subproc.match_output(
             ["pip", "search", pkgname],
             r'^\b{pkg}\b'.format(pkg=pkgname),
         )
         return bool(output_match)
     except subproc.CalledProcessError:
         return False
     except Exception as ex:
         self.log.error("Error running `pip search {0}`".format(pkgname))
         self.log.debug(ex)
     return False
예제 #12
0
파일: pip.py 프로젝트: NinjaComics/pybombs
 def get_available_version(self, pkgname):
     """
     See if 'pip search' finds our package.
     """
     try:
         output_match = subproc.match_output(
             ["pip", "search", pkgname],
             r'^\b{pkg}\b'.format(pkg=pkgname),
         )
         return bool(output_match)
     except subproc.CalledProcessError:
         return False
     except Exception as ex:
         self.log.error("Error running `pip search {0}`".format(pkgname))
         self.log.debug(ex)
     return False
예제 #13
0
 def get_available_version(self, pkgname):
     """
     Check which version is available in apt-cache.
     """
     try:
         self.log.obnoxious("Checking apt-cache for `{0}'".format(pkgname))
         ver = subproc.match_output(
             ["apt-cache", "showpkg", pkgname],
             r'Versions: \n(?:\d+:)?(?P<ver>[0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+|[0-9]+).*\n',
             'ver'
         )
         if ver is None:
             return False
         if ver:
             self.log.debug("Package {} has version {} in apt-cache".format(pkgname, ver))
         return ver
     except subprocess.CalledProcessError:
         self.log.error("Error running apt-cache showpkg. This shouldn't happen. Probably a bug.")
     return False
예제 #14
0
 def get_available_version(self, pkgname):
     """
     Check which version is available in apt-cache.
     """
     try:
         self.log.obnoxious("Checking apt-cache for `{0}'".format(pkgname))
         ver = subproc.match_output([
             "apt-cache", "showpkg", pkgname
         ], r'Versions: \n(?:\d+:)?(?P<ver>[0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+|[0-9]+).*\n',
                                    'ver')
         if ver is None:
             return False
         if ver:
             self.log.debug("Package {} has version {} in apt-cache".format(
                 pkgname, ver))
         return ver
     except subprocess.CalledProcessError:
         self.log.error(
             "Error running apt-cache showpkg. This shouldn't happen. Probably a bug."
         )
     return False
예제 #15
0
파일: pacman.py 프로젝트: gnuradio/pybombs
 def get_available_version(self, pkgname):
     """
     Return a version that we can install through this package manager.
     """
     try:
         ver = subproc.match_output(
             [self.command, "-Si", pkgname],
             r'Version[ ]*: (?P<ver>[0-9,.]*)',
             'ver'
         ) or False
         if ver:
             self.log.debug("Package {0} has version {1} in {2}".format(pkgname, ver, self.command))
         return ver
     except subprocess.CalledProcessError as ex:
         # This usually means the package was not found, so don't worry
         self.log.trace("`{0} -Si' returned non-zero exit status.".format(self.command))
         self.log.trace(str(ex))
         return False
     except Exception as ex:
         self.log.error("Error parsing {0} -Si".format(self.command))
         self.log.error(str(ex))
     return False
예제 #16
0
파일: pacman.py 프로젝트: yueyz818/pybombs
 def get_available_version(self, pkgname):
     """
     Return a version that we can install through this package manager.
     """
     try:
         ver = subproc.match_output([self.command, "-Si", pkgname],
                                    r'Version[ ]*: (?P<ver>[0-9,.]*)',
                                    'ver') or False
         if ver:
             self.log.debug("Package {0} has version {1} in {2}".format(
                 pkgname, ver, self.command))
         return ver
     except subprocess.CalledProcessError as ex:
         # This usually means the package was not found, so don't worry
         self.log.trace("`{0} -Si' returned non-zero exit status.".format(
             self.command))
         self.log.trace(str(ex))
         return False
     except Exception as ex:
         self.log.error("Error parsing {0} -Si".format(self.command))
         self.log.error(str(ex))
     return False
예제 #17
0
파일: yum.py 프로젝트: NinjaComics/pybombs
 def get_available_version(self, pkgname):
     """
     Return a version that we can install through this package manager.
     """
     try:
         ver = subproc.match_output(
             [self.command, "info", pkgname],
             r'^Version\s+:\s+(?P<ver>.*$)',
             'ver'
         )
         if ver is None:
             return False
         self.log.debug("Package {} has version {} in {}".format(pkgname, ver, self.command))
         return ver
     except subprocess.CalledProcessError as ex:
         # This usually means the package was not found, so don't worry
         self.log.obnoxious("`{0} info' returned non-zero exit status.".format(self.command))
         self.log.obnoxious(str(ex))
         return False
     except Exception as ex:
         self.log.error("Error parsing {0} info".format(self.command))
         self.log.error(str(ex))
     return False