Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.log.error("Running port install failed.")
self.log.trace(str(ex))
return False
def update(self, pkgname):
"""
update package with 'port upgrade'
"""
try:
subproc.monitor_process(["port", "upgrade", pkgname], elevate=True, throw=True)
return True
except Exception as ex:
self.log.error("Running port upgrade failed.")
self.log.trace(str(ex))
class Port(ExternCmdPackagerBase):
"""
port install package
"""
name = 'port'
pkgtype = 'port'
def __init__(self):
ExternCmdPackagerBase.__init__(self)
self.packager = ExternalPort(self.log)
def supported(self):
"""
Check if macports is installed
"""
return sysutils.which('port') is not None
"""
return self._run_cmd(pkgname, '-S')
def _run_cmd(self, pkgname, cmd):
"""
Call pacman with cmd.
"""
try:
subproc.monitor_process([self.command, "--noconfirm", cmd, pkgname], elevate=True)
return True
except Exception as ex:
self.log.error("Running `{0} {1}' failed.".format(self.command, cmd))
self.log.trace(str(ex))
return False
class Pacman(ExternCmdPackagerBase):
"""
pacman install xyz
"""
name = 'pacman'
pkgtype = 'pacman'
def __init__(self):
ExternCmdPackagerBase.__init__(self)
self.packager = ExternalPacman(self.log)
def supported(self):
"""
Check if we can even run pacman.
Return True if so.
"""
return self.packager.command is not None
def __init__(self):
ExternCmdPackagerBase.__init__(self)
self.packager = ExternalPort(self.log)
try:
pkg = self.cache[pkgname]
except:
return (False, False)
vers = pkg.versions
first_ver = vers[0].version
ver = re.search(r'(?:\d+:)?(?P[0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+[a-z]+|[0-9]+)', first_ver)
if ver is None:
return (False, pkg.is_installed)
ver = ver.group('ver')
return (ver, pkg.is_installed)
class Apt(ExternCmdPackagerBase):
"""
apt(-get) install xyz
"""
name = 'apt'
pkgtype = 'deb'
def __init__(self):
ExternCmdPackagerBase.__init__(self)
if self.supported():
self.packager = ExternalApt(self.log)
def supported(self):
"""
Check if we're on a Debian/Ubuntu.
Return True if so.
"""
"""
try:
# pkg-config will return non-zero if package does not exist, thus will throw
ver = subproc.check_output(["pkg-config", "--modversion", pkgname], stderr=subprocess.STDOUT).strip()
self.log.debug("Package {0} has version {1} in pkg-config".format(pkgname, ver))
return ver
except subprocess.CalledProcessError:
# This usually means the packet is not installed
return False
except Exception as e:
self.log.error("Running `pkg-config --modversion` failed.")
self.log.trace(str(e))
return False
class PkgConfig(ExternCmdPackagerBase):
"""
Uses pkg-config. Can't really install stuff, but is useful for
finding out if something is already installed.
"""
name = 'pkgconfig'
pkgtype = 'pkgconfig'
def __init__(self):
ExternCmdPackagerBase.__init__(self)
self.packager = ExternalPkgConfig(self.log)
def supported(self):
"""
Check if we can even run 'pkg-config'. Return True if yes.
"""
return sysutils.which('pkg-config') is not None
"""
return self._run_cmd(pkgname, 'update')
def _run_cmd(self, pkgname, cmd):
"""
Call yum or dnf with cmd.
"""
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.trace(str(ex))
return False
class YumDnf(ExternCmdPackagerBase):
"""
yum/dnf install xyz
"""
name = 'yumdnf'
pkgtype = 'rpm'
def __init__(self):
ExternCmdPackagerBase.__init__(self)
self.packager = ExternalYumDnf(self.log)
def supported(self):
"""
Check if we can even run yum or dnf.
Return True if so.
"""
return self.packager.command is not None
def install(self, pkgname):
"""
Call 'brew install pkgname' if we can satisfy the version requirements.
"""
try:
# Need to do some better checking here. Brew does not necessarily need sudo
#sysutils.monitor_process(["sudo", "brew", "", "install", pkg_name])
subproc.monitor_process(["brew", "install", pkgname])
return True
except Exception as e:
#self.log.trace(e)
self.log.error("Running brew install failed.")
return False
class Homebrew(ExternCmdPackagerBase):
"""
brew install xyz
"""
name = 'brew'
pkgtype = 'brew'
def __init__(self):
ExternCmdPackagerBase.__init__(self)
self.packager = ExternalHomebrew(self.log)
def supported(self):
"""
Check if homebrew exists
Return True if so.
"""
return sysutils.which('brew') is not None
else:
pkgname, version_attr = pkgname[0], "__version__"
try:
module = importlib.import_module(pkgname)
self.log.debug("Successfully imported Python module: {0}".format(pkgname))
except ImportError:
self.log.debug("Could not import Python module: {0}".format(pkgname))
return False
try:
version = getattr(module, version_attr)
self.log.debug("Module version: {0}.{1} == {2}".format(pkgname, version_attr, version))
except AttributeError:
return True
return version
class PythonModule(ExternCmdPackagerBase):
"""
Check to see if a Python module is installed.
Can't install stuff, but is useful for finding out if
something is already installed.
"""
name = 'pymod'
pkgtype = 'python'
def __init__(self):
ExternCmdPackagerBase.__init__(self)
self.packager = ExternalPythonModule(self.log)
def supported(self):
" If we're running this, we can always check for Python modules. "
return True