rosdep: #3223 partial patch for py3k support

This commit is contained in:
Ken Conley 2011-08-11 19:44:04 +00:00
parent d85adcabe1
commit 15768fa06e
2 changed files with 63 additions and 63 deletions

View File

@ -32,7 +32,7 @@
#Library and command-line tool for calculating rosdeps.
#"""
from __future__ import with_statement
from __future__ import print_function
import roslib.rospack
import roslib.stacks
@ -90,8 +90,8 @@ class YamlCache:
self._yaml_cache[path] = yaml.load(yaml_text)
return self._yaml_cache[path]
except yaml.YAMLError, exc:
print >> sys.stderr, "Failed parsing yaml while processing %s\n"%path, exc
except yaml.YAMLError as exc:
print("Failed parsing yaml while processing %s\n"%path, exc, file=sys.stderr)
#sys.exit(1) # not a breaking error
self._yaml_cache[path] = {}
return {}
@ -159,12 +159,12 @@ class YamlCache:
if type(os_specific) == type({}): # detected a map
for k in os_specific.keys():
if not k in self.installers:
print "Invalid identifier found [%s] when processing rosdep %s. \n{{{\n%s\n}}}\n"%(k, rosdep_name, os_specific)
print("Invalid identifier found [%s] when processing rosdep %s. \n{{{\n%s\n}}}\n"%(k, rosdep_name, os_specific))
return False # If the map doesn't have a valid installer key reject it, it must be a version key
# return the map
return os_specific
else:
print "Unknown formatting of os_specific", os_specific
print("Unknown formatting of os_specific", os_specific)
return False
@ -176,12 +176,12 @@ def create_tempfile_from_string_and_execute(string_script, path= tempfile.gettem
fh = tempfile.NamedTemporaryFile('w', delete=False)
fh.write(string_script)
fh.close()
print "Executing script below with cwd=%s\n{{{\n%s\n}}}\n"%(path, string_script)
print("Executing script below with cwd=%s\n{{{\n%s\n}}}\n"%(path, string_script))
try:
os.chmod(fh.name, 0700)
result = subprocess.call(fh.name, cwd=path)
except OSError, ex:
print "Execution failed with OSError:", ex
except OSError as ex:
print("Execution failed with OSError:", ex)
#print "Return code ", result
finally:
@ -189,7 +189,7 @@ def create_tempfile_from_string_and_execute(string_script, path= tempfile.gettem
os.remove(fh.name)
if "ROSDEP_DEBUG" in os.environ:
print "Return code was:", result
print("Return code was:", result)
return result == 0
@ -235,9 +235,9 @@ class RosdepLookupPackage:
try:
rosdep_dependent_packages = ros_package_proxy.depends([package])[package]
#print "package", package, "needs", rosdep_dependent_packages
except KeyError, ex:
print "Depends Failed on package", ex
print " The errors was in ", ros_package_proxy.depends([package])
except KeyError as ex:
print("Depends Failed on package", ex)
print(" The errors was in ", ros_package_proxy.depends([package]))
rosdep_dependent_packages = []
#print "Dependents of", package, rosdep_dependent_packages
rosdep_dependent_packages.append(package)
@ -248,35 +248,34 @@ class RosdepLookupPackage:
stack = None
try:
stack = roslib.stacks.stack_of(p)
except roslib.packages.InvalidROSPkgException, ex:
print >> sys.stderr, "Failed to find stack for package [%s]"%p
pass
except roslib.packages.InvalidROSPkgException as ex:
print("Failed to find stack for package [%s]"%p, file=sys.stderr)
if stack:
try:
paths.add( os.path.join(roslib.stacks.get_stack_dir(stack), "rosdep.yaml"))
if "ROSDEP_DEBUG" in os.environ:
print "loading rosdeps from", os.path.join(roslib.stacks.get_stack_dir(stack), "rosdep.yaml")
except AttributeError, ex:
print "Stack [%s] could not be found"%(stack)
print("loading rosdeps from", os.path.join(roslib.stacks.get_stack_dir(stack), "rosdep.yaml"))
except AttributeError as ex:
print("Stack [%s] could not be found"%(stack))
for s in self.yaml_cache.get_rosstack_depends(stack):
try:
paths.add( os.path.join(roslib.stacks.get_stack_dir(s), "rosdep.yaml"))
except AttributeError, ex:
print "Stack [%s] dependency of [%s] could not be found"%(s, stack)
except AttributeError as ex:
print("Stack [%s] dependency of [%s] could not be found"%(s, stack))
else:
try:
paths.add( os.path.join(roslib.packages.get_pkg_dir(p), "rosdep.yaml"))
if "ROSDEP_DEBUG" in os.environ:
print "Package fallback, no parent stack found for package %s: loading rosdeps from"%p, os.path.join(roslib.packages.get_pkg_dir(p), "rosdep.yaml")
except roslib.packages.InvalidROSPkgException, ex:
print("Package fallback, no parent stack found for package %s: loading rosdeps from"%p, os.path.join(roslib.packages.get_pkg_dir(p), "rosdep.yaml"))
except roslib.packages.InvalidROSPkgException as ex:
print >> sys.stderr, "Failed to load rosdep.yaml for package [%s]:%s"%(p, ex)
pass
for path in paths:
yaml_in = self.parse_yaml(path)
self._insert_map(yaml_in, path)
if "ROSDEP_DEBUG" in os.environ:
print "rosdep loading from file: %s got"%path, yaml_in
print("rosdep loading from file: %s got"%path, yaml_in)
#print "built map", self.rosdep_map
# Override with ros_home/rosdep.yaml if present
@ -295,14 +294,13 @@ class RosdepLookupPackage:
if override:
print >>sys.stderr, "ROSDEP_OVERRIDE: %s being overridden with %s from %s"%(key, yaml_dict[key], source_path)
print( "ROSDEP_OVERRIDE: %s being overridden with %s from %s"%(key, yaml_dict[key], source_path), file=sys.stderr)
self.rosdep_source[key].append("Overriding with "+source_path)
self.rosdep_map[key] = rosdep_entry
else:
if self.rosdep_map[key] == rosdep_entry:
self.rosdep_source[key].append(source_path)
#print >> sys.stderr, "DEBUG: Same key found for %s: %s"%(key, self.rosdep_map[key])
pass
else:
cache_p = self.yaml_cache.get_os_from_yaml(key, yaml_dict[key], source_path)
raise RosdepException("""QUITTING: due to conflicting rosdep definitions, please resolve this conflict.
@ -330,7 +328,7 @@ Rules for %s do not match:
if rosdep in self.rosdep_map:
return self.rosdep_map[rosdep]
else:
print >> sys.stderr, "Failed to find rosdep %s for package %s on OS:%s version:%s"%(rosdep, self.package, self.os_name, self.os_version)
print("Failed to find rosdep %s for package %s on OS:%s version:%s"%(rosdep, self.package, self.os_name, self.os_version), file=sys.stderr)
return False
@ -388,7 +386,7 @@ class Rosdep:
failed_rosdeps = []
start_time = time.time()
if "ROSDEP_DEBUG" in os.environ:
print "Generating package list and scripts for %d packages. This may take a few seconds..."%len(self.packages)
print("Generating package list and scripts for %d packages. This may take a few seconds..."%len(self.packages))
if rdlp_cache == None:
rdlp_cache = {}
@ -406,7 +404,7 @@ class Rosdep:
if specific:
if type(specific) == type({}):
if "ROSDEP_DEBUG" in os.environ:
print "%s NEW TYPE, SKIPPING"%r
print("%s NEW TYPE, SKIPPING"%r)
elif len(specific.split('\n')) == 1:
for pk in specific.split():
native_packages.append(pk)
@ -419,11 +417,11 @@ class Rosdep:
if not self.robust:
raise RosdepException("ABORTING: Rosdeps %s could not be resolved"%failed_rosdeps)
else:
print >> sys.stderr, "WARNING: Rosdeps %s could not be resolved"%failed_rosdeps
print("WARNING: Rosdeps %s could not be resolved"%failed_rosdeps, file=sys.stderr)
time_delta = (time.time() - start_time)
if "ROSDEP_DEBUG" in os.environ:
print "Done loading rosdeps in %f seconds, averaging %f per rosdep."%(time_delta, time_delta/len(self.packages))
print("Done loading rosdeps in %f seconds, averaging %f per rosdep."%(time_delta, time_delta/len(self.packages)))
return (list(set(native_packages)), list(set(scripts)))
@ -444,13 +442,13 @@ class Rosdep:
native_packages, scripts = self.get_packages_and_scripts(rdlp_cache=rdlp_cache)
num_scripts = len(scripts)
if num_scripts > 0:
print "Found %d scripts. Cannot check scripts for presence. rosdep check will always fail."%num_scripts
print("Found %d scripts. Cannot check scripts for presence. rosdep check will always fail."%num_scripts)
failure = False
if display == True:
for s in scripts:
print "Script:\n{{{\n%s\n}}}"%s
except RosdepException, e:
print >> sys.stderr, "error in processing scripts", e
print("Script:\n{{{\n%s\n}}}"%s)
except RosdepException as e:
print("error in processing scripts", e, file=sys.stderr)
for r, packages in self.get_rosdeps(self.packages).iteritems():
# use first package for lookup rule
@ -500,7 +498,7 @@ class Rosdep:
@return If the install was successful
"""
if "ROSDEP_DEBUG" in os.environ:
print "Processing rosdep %s in install_rosdep method"%rosdep_name
print("Processing rosdep %s in install_rosdep method"%rosdep_name)
rosdep_dict = rdlp.lookup_rosdep(rosdep_name)
if not rosdep_dict:
return False
@ -508,7 +506,7 @@ class Rosdep:
installer = None
if type(rosdep_dict) != type({}):
if "ROSDEP_DEBUG" in os.environ:
print "OLD TYPE BACKWARDS COMPATABILITY MODE", rosdep_dict
print("OLD TYPE BACKWARDS COMPATABILITY MODE", rosdep_dict)
if len(rosdep_dict.split('\n')) > 1:
@ -524,13 +522,13 @@ class Rosdep:
else:
modes = rosdep_dict.keys()
if len(modes) != 1:
print "ERRROR: only one mode allowed, rosdep %s has mode %s"%(rosdep_name, modes)
print("ERROR: only one mode allowed, rosdep %s has mode %s"%(rosdep_name, modes))
return False
else:
mode = modes[0]
if "ROSDEP_DEBUG" in os.environ:
print "rosdep mode:", mode
print("rosdep mode:", mode)
installer = self.osi.get_os().get_installer(mode)
if not installer:
@ -542,12 +540,12 @@ class Rosdep:
# Check if it's already there
if my_installer.check_presence():
if "ROSDEP_DEBUG" in os.environ:
print "rosdep %s already present"%rosdep_name
print("rosdep %s already present"%rosdep_name)
return True
else:
if "ROSDEP_DEBUG" in os.environ:
print "rosdep %s not detected. It will be installed"%rosdep_name
print("rosdep %s not detected. It will be installed"%rosdep_name)
# Check for dependencies
@ -559,13 +557,13 @@ class Rosdep:
result = my_installer.generate_package_install_command(default_yes, execute, display)
if result:
print "successfully installed %s"%rosdep_name
print("successfully installed %s"%rosdep_name)
if not my_installer.check_presence():
print "rosdep %s failed check-presence-script after installation"%rosdep_name
print("rosdep %s failed check-presence-script after installation"%rosdep_name)
return False
elif execute:
print "Failed to install %s!"%rosdep_name
print("Failed to install %s!"%rosdep_name)
return result
def depdb(self, packages):

View File

@ -32,6 +32,8 @@
#Library and command-line tool for calculating rosdeps.
#"""
from __future__ import print_function
import roslib; roslib.load_manifest("rosdep")
import roslib.stacks
@ -111,7 +113,7 @@ def main():
valid_stacks = [s for s in roslib.stacks.list_stacks() if s in rdargs]
if len(rejected_packages) > 0:
print "Warning: could not identify %s as a package"%rejected_packages
print("Warning: could not identify %s as a package"%rejected_packages)
if len(verified_packages) == 0 and len(valid_stacks) == 0:
parser.error("No Valid Packages or stacks listed as arguments")
@ -122,17 +124,17 @@ def main():
### Find all dependencies
try:
r = core.Rosdep(verified_packages, robust=options.robust)
except roslib.os_detect.OSDetectException, ex:
print "rosdep ABORTING. Failed to detect OS: %s"%ex
except roslib.os_detect.OSDetectException as ex:
print("rosdep ABORTING. Failed to detect OS: %s"%ex)
return 1
except roslib.exceptions.ROSLibException, ex:
print "rosdep ABORTING: %s"%ex
except roslib.exceptions.ROSLibException as ex:
print("rosdep ABORTING: %s"%ex)
return 1
if options.verbose:
print "Detected OS: " + r.osi.get_name()
print "Detected Version: " + r.osi.get_version()
print("Detected OS: " + r.osi.get_name())
print("Detected Version: " + r.osi.get_version())
try:
if command == "generate_bash" or command == "satisfy":
@ -140,47 +142,47 @@ def main():
if not missing_packages:
return 0
else:
print "The following rosdeps are not installed but are required", missing_packages
print("The following rosdeps are not installed but are required", missing_packages)
return 1
elif command == "install":
error = r.install(options.include_duplicates, options.default_yes)
if error:
print >> sys.stderr, "rosdep install ERROR:\n%s"%error
print("rosdep install ERROR:\n%s"%error, file=sys.stderr)
return 1
else:
print "All required rosdeps installed successfully"
print("All required rosdeps installed successfully")
return 0
except core.RosdepException, e:
print >> sys.stderr, "ERROR: %s"%e
except core.RosdepException as e:
print("ERROR: %s"%e, file=sys.stderr)
return 1
try:
if command == "depdb":
print r.depdb(verified_packages)
print(r.depdb(verified_packages))
return 0
elif command == "what_needs":
print '\n'.join(r.what_needs(rdargs))
print('\n'.join(r.what_needs(rdargs)))
return 0
elif command == "where_defined":
print r.where_defined(rdargs)
print(r.where_defined(rdargs))
return 0
elif command == "check":
return_val = 0
missing_packages = r.check()
if len(rejected_packages) > 0:
print >> sys.stderr, "Arguments %s are not packages"%rejected_packages
print("Arguments %s are not packages"%rejected_packages, file=sys.stderr)
return_val = 1
if len(missing_packages) == 0:
print "All required rosdeps are installed"
print("All required rosdeps are installed")
return 0
else:
print "The following rosdeps were not installed", missing_packages
print("The following rosdeps were not installed", missing_packages)
return 1
except core.RosdepException, e:
print >> sys.stderr, str(e)
except core.RosdepException as e:
print(str(e), file=sys.stderr)
return 1