00001 
00002 
00003 
00004 import sys, os
00005 
00006 if len(sys.argv) < 2:
00007   print >> sys.stderr, "this version only supports 'find', 'list', and 'list-names'"
00008   exit(1);
00009 
00010 command = sys.argv[1]
00011 
00012 if not 'ROS_ROOT' in os.environ:
00013   print >> sys.stderr, "ROS_ROOT is not defined in the environment"
00014   exit(1)
00015 s = [ os.environ['ROS_ROOT'] ]  
00016 if 'ROS_PACKAGE_PATH' in os.environ:
00017   s += os.environ['ROS_PACKAGE_PATH'].split(':')
00018 
00019 pkgs = { }
00020 
00021 while len(s) > 0:
00022   p = s.pop()
00023   if os.path.exists(os.path.join(p, 'manifest.xml')): 
00024     pkgs[os.path.basename(p)] = p
00025   else: 
00026     for child in os.listdir(p):
00027       c = os.path.join(p, child)
00028       if os.path.isfile(c) or os.path.islink(c) or os.path.basename(c)[0] == '.':
00029         continue 
00030       if os.path.exists(os.path.join(c, 'rospack_nosubdirs')):
00031         continue 
00032       
00033       s.append(c)
00034 
00035 if command == 'list':
00036   for k, v in pkgs.iteritems():
00037     print "%s %s" % (k, v)
00038 elif command == 'list-names':
00039   for k, v in pkgs.iteritems():
00040     print k
00041 elif command == 'find':
00042   if len(sys.argv) < 3:
00043     print >> sys.stderr, "syntax: rospack find PACKAGE"
00044     exit(1)
00045   if sys.argv[2] in pkgs:
00046     print pkgs[sys.argv[2]]
00047 else:
00048   print >> sys.stderr, "rospack lite, python style!\nsupported commands:\nrospack find PACKAGE\nrospack list\nrospack list-names\n"
00049