catkinize_this.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import rospy
00004 from xml.dom import minidom
00005 import subprocess
00006 import os.path
00007 
00008 found = {}
00009 
00010 def get_root(package):
00011     p = subprocess.Popen(['rospack', 'find', package], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00012     out, err = p.communicate()
00013     return out.strip()
00014 
00015 def is_catkinized(package, root=None):
00016     if package in found:
00017         return found[package]
00018 
00019     if root is None:
00020         root = get_root(package)
00021     if root=='':
00022         found[package] = None
00023         return None
00024     if os.path.exists('%s/package.xml'%root):
00025         found[package] = True
00026         return True
00027     elif os.path.exists('%s/manifest.xml'%root):
00028         found[package] = False
00029         return False
00030     else:
00031         found[package] = None
00032         return None
00033 
00034 def get_links(name):
00035     if not os.path.exists(name):
00036         return []
00037     xmldoc = minidom.parse(name)
00038     if 'package.xml' in name:
00039         builds = xmldoc.getElementsByTagName('build_depend')
00040         runs = xmldoc.getElementsByTagName('run_depend')
00041         return [item.firstChild.nodeValue for item in builds+runs]
00042     elif 'manifest.xml' in name:
00043         itemlist = xmldoc.getElementsByTagName('depend') 
00044         return [item.attributes['package'].value for item in itemlist]
00045     else:
00046         None
00047 
00048 def check_status(package, depth=0, dlimit=0):
00049     root = get_root(package)
00050     is_cat = is_catkinized(package, root)
00051     if is_cat:
00052         links = get_links('%s/package.xml'%root)
00053     elif is_cat==False:
00054         links = get_links('%s/manifest.xml'%root)
00055     else:
00056         return
00057 
00058     s = "%s%s"%(" "*depth, package)
00059     print s, " "*(50-len(s)), "CATKIN" if is_cat else "ROSPACK"
00060 
00061     if depth < dlimit:
00062         for p2 in links:
00063             if p2 not in found:
00064                 check_status(p2, depth+1, dlimit)
00065         
00066     
00067 import sys
00068 limit = 0
00069 for arg in sys.argv[1:]:
00070     if '--n' in arg:
00071         limit = int(arg[3:])
00072 for arg in sys.argv[1:]:
00073     check_status(arg, dlimit=limit)
00074 


catkinize_this
Author(s): David V. Lu!!
autogenerated on Thu Jun 6 2019 22:02:22