rosdep: #3616 patch from felix_k to support fedora

This commit is contained in:
Ken Conley 2011-09-15 20:32:16 +00:00
parent 40ec1f8426
commit cc38b01ef7
2 changed files with 81 additions and 28 deletions

View File

@ -282,6 +282,63 @@ class AptInstaller(InstallerAPI):
return [version_lock_map[r] for r in ret_list]
class YumInstaller(InstallerAPI):
"""
An implementation of the InstallerAPI for use on yum/fedora style
systems.
"""
def __init__(self, arg_dict):
packages = arg_dict.get("packages", "")
if type(packages) == type("string"):
packages = packages.split()
self.packages = packages
def get_packages_to_install(self):
return list(set(self.packages) - set(self.dpkg_detect(self.packages)))
def check_presence(self):
return len(self.get_packages_to_install()) == 0
def generate_package_install_command(self, default_yes = False, execute = True, display = True):
script = '!#/bin/bash\n#no script'
packages_to_install = self.get_packages_to_install()
if not packages_to_install:
script = "#!/bin/bash\n#No Packages to install"
elif default_yes:
script = "#!/bin/bash\n#Packages %s\nsudo yum install -y "%packages_to_install + ' '.join(packages_to_install)
else:
script = "#!/bin/bash\n#Packages %s\nsudo yum install "%packages_to_install + ' '.join(packages_to_install)
if execute:
return rosdep.core.create_tempfile_from_string_and_execute(script)
elif display:
print "To install packages: %s would have executed script\n{{{\n%s\n}}}"%(packages_to_install, script)
return False
def dpkg_detect(self, pkgs):
"""
Given a list of packages, return the list of installed packages.
"""
ret_list = []
#cmd = ['rpm', '-q', '--qf ""'] # suppress output for installed packages
cmd = ['rpm', '-q', '--qf', '%{NAME}\n'] # output: "pkg_name" for installed, error text for not installed packages
cmd.extend(pkgs)
pop = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(std_out, std_err) = pop.communicate()
out_lines = std_out.split('\n')
for line in out_lines:
# if there is no space, it's not an error text -> it's installed
if line and ' ' not in line:
ret_list.append(line)
return ret_list
class PipInstaller(InstallerAPI):
"""
An implementation of the InstallerAPI for use on debian style

View File

@ -34,40 +34,36 @@ import subprocess
import rosdep.base_rosdep
class YumInstall:
"""This class provides the functions for installing using yum
it's methods partially implement the Rosdep OS api to complement
the roslib.OSDetect API. """
def rpm_detect(self, p):
return subprocess.call(['rpm', '-q', p], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def strip_detected_packages(self, packages):
return [p for p in packages if self.rpm_detect(p)]
def generate_package_install_command(self, packages, default_yes):
if not packages:
return "#No Packages to install"
if default_yes:
return "#Packages\nsudo yum -y install " + ' '.join(packages)
else:
return "#Packages\nsudo yum install " + ' '.join(packages)
###### Fedora SPECIALIZATION #########################
class Fedora(roslib.os_detect.Fedora, YumInstall, rosdep.base_rosdep.RosdepBaseOS):
"""This class provides the Rosdep OS API for by combining the Fedora
OSDetect API and the YumInstall API
"""
class Fedora(roslib.os_detect.Fedora, rosdep.base_rosdep.RosdepBaseOS):
""" This is an implementation of a standard interface for
interacting with rosdep. This defines all Fedora sepecific
methods, including detecting the OS/Version number. As well as
how to check for and install packages."""
def __init__(self):
self.installers = {}
self.installers['yum'] = rosdep.installers.YumInstaller
self.installers['pip'] = rosdep.installers.PipInstaller
self.installers['source'] = rosdep.installers.SourceInstaller
self.installers['default'] = rosdep.installers.YumInstaller
pass
###### END Fedora SPECIALIZATION ########################
###### Rhel SPECIALIZATION #########################
class Rhel(roslib.os_detect.Rhel, YumInstall, rosdep.base_rosdep.RosdepBaseOS):
"""This class provides the Red Hat Enterprise Linux Rosdep OS API
for by combining the RHEL OSDetect API and the YumInstall API
"""
class Rhel(roslib.os_detect.Rhel, rosdep.base_rosdep.RosdepBaseOS):
""" This is an implementation of a standard interface for
interacting with rosdep. This defines all Fedora sepecific
methods, including detecting the OS/Version number. As well as
how to check for and install packages."""
def __init__(self):
self.installers = {}
self.installers['yum'] = rosdep.installers.YumInstaller
self.installers['pip'] = rosdep.installers.PipInstaller
self.installers['source'] = rosdep.installers.SourceInstaller
self.installers['default'] = rosdep.installers.YumInstaller
pass
###### END Rhel SPECIALIZATION ########################