implemented PortInstaller
This commit is contained in:
parent
1cde210544
commit
01df7d4638
|
@ -346,3 +346,49 @@ class PipInstaller(InstallerAPI):
|
|||
ret_list.append( pkg_row[0])
|
||||
return ret_list
|
||||
|
||||
class PortInstaller(InstallerAPI):
|
||||
"""
|
||||
An implementation of the InstallerAPI for use on macports systems.
|
||||
"""
|
||||
def __init__(self, arg_dict):
|
||||
packages = arg_dict.get("packages", "")
|
||||
if type(packages) == type("string"):
|
||||
packages = packages.split()
|
||||
|
||||
self.packages = packages
|
||||
print 'packages: ' + `self.packages`
|
||||
|
||||
def get_packages_to_install(self):
|
||||
return list(set(self.packages) - set(self.port_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"
|
||||
script = "#!/bin/bash\n#Packages %s\nsudo port 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 port_detect(self, pkgs):
|
||||
"""
|
||||
Given a list of package, return the list of installed packages.
|
||||
"""
|
||||
ret_list = []
|
||||
cmd = ['port', 'installed']
|
||||
cmd.extend(pkgs)
|
||||
pop = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(std_out, std_err) = pop.communicate()
|
||||
pkg_list = std_out.split('\n')
|
||||
for pkg in pkg_list:
|
||||
pkg_row = pkg.split()
|
||||
if len(pkg_row) == 3 and pkg_row[0] in pkgs and pkg_row[2] =='(active)':
|
||||
ret_list.append( pkg_row[0])
|
||||
return ret_list
|
||||
|
|
|
@ -45,8 +45,9 @@ def port_detect(p):
|
|||
class Osx(roslib.os_detect.Osx, rosdep.base_rosdep.RosdepBaseOS):
|
||||
def __init__(self):
|
||||
self.installers = {}
|
||||
#FIXME: I guess that there should be something like:
|
||||
#self.installers['port'] = rosdep.installers.PortInstaller
|
||||
self.installers['pip'] = rosdep.installers.PipInstaller
|
||||
self.installers['port'] = rosdep.installers.PortInstaller
|
||||
self.installers['default'] = rosdep.installers.PortInstaller
|
||||
|
||||
def strip_detected_packages(self, packages):
|
||||
return [p for p in packages if not port_detect(p)]
|
||||
|
|
Loading…
Reference in New Issue