00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 import roslib; roslib.load_manifest('roscreate')
00037
00038 NAME='roscreate-pkg'
00039
00040 import os
00041 import sys
00042 import roslib.packages
00043
00044 from roscreate.core import read_template, author_name, on_ros_path
00045
00046 def get_templates():
00047 templates = {}
00048 templates['CMakeLists.txt'] = read_template('CMakeLists.tmpl')
00049 templates['manifest.xml'] = read_template('manifest.tmpl')
00050 templates['mainpage.dox'] = read_template('mainpage.tmpl')
00051 templates['Makefile'] = read_template('Makefile.tmpl')
00052 return templates
00053
00054 def instantiate_template(template, package, brief, description, author, depends):
00055 return template%locals()
00056
00057 def create_package(package, author, depends, uses_roscpp=False, uses_rospy=False):
00058 p = os.path.abspath(package)
00059 if os.path.exists(p):
00060 print >> sys.stderr, "%s already exists, aborting"%p
00061 sys.exit(1)
00062
00063 os.makedirs(p)
00064 print "Created package directory", p
00065
00066 if uses_roscpp:
00067
00068 cpp_path = os.path.join(p, 'include', package)
00069 try:
00070 os.makedirs(cpp_path)
00071 print "Created include directory", cpp_path
00072 cpp_path = os.path.join(p, 'src')
00073 os.makedirs(cpp_path)
00074 print "Created cpp source directory", cpp_path
00075 except:
00076
00077 pass
00078 if uses_rospy:
00079
00080 py_path = os.path.join(p, 'src')
00081 try:
00082 os.makedirs(py_path)
00083 print "Created python source directory", py_path
00084 except:
00085
00086 pass
00087
00088 templates = get_templates()
00089 for filename, template in templates.iteritems():
00090 contents = instantiate_template(template, package, package, package, author, depends)
00091 try:
00092 p = os.path.abspath(os.path.join(package, filename))
00093 f = open(p, 'w')
00094 f.write(contents)
00095 print "Created package file", p
00096 finally:
00097 f.close()
00098 print "\nPlease edit %s/manifest.xml and mainpage.dox to finish creating your package"%package
00099
00100 def roscreatepkg_main():
00101 from optparse import OptionParser
00102 parser = OptionParser(usage="usage: %prog <package-name> [dependencies...]", prog=NAME)
00103 options, args = parser.parse_args()
00104 if not args:
00105 parser.error("you must specify a package name and optionally also list package dependencies")
00106 package = args[0]
00107
00108 if not roslib.names.is_legal_resource_base_name(package):
00109 parser.error("illegal package name: %s\nNames must start with a letter and contain only alphanumeric characters\nand underscores."%package)
00110
00111
00112 depends = args[1:]
00113 uses_roscpp = 'roscpp' in depends
00114 uses_rospy = 'rospy' in depends
00115
00116 for d in depends:
00117 try:
00118 roslib.packages.get_pkg_dir(d)
00119 except roslib.packages.InvalidROSPkgException:
00120 print >> sys.stderr, "ERROR: dependency [%s] cannot be found"%d
00121 sys.exit(1)
00122 depends = ''.join([' <depend package="%s"/>\n'%d for d in depends])
00123
00124 if not on_ros_path(os.getcwd()):
00125 print >> sys.stderr, '!'*80+"\nWARNING: current working directory is not on ROS_PACKAGE_PATH!\nPlease update your ROS_PACKAGE_PATH environment variable.\n"+'!'*80
00126 create_package(package, author_name(), depends, uses_roscpp=uses_roscpp, uses_rospy=uses_rospy)
00127
00128 if __name__ == "__main__":
00129 roscreatepkg_main()