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 p = os.path.abspath(os.path.join(package, filename))
00092 with open(p, 'w') as f:
00093 f.write(contents.encode('utf-8'))
00094 print "Created package file", p
00095 print "\nPlease edit %s/manifest.xml and mainpage.dox to finish creating your package"%package
00096
00097 def roscreatepkg_main():
00098 from optparse import OptionParser
00099 parser = OptionParser(usage="usage: %prog <package-name> [dependencies...]", prog=NAME)
00100 options, args = parser.parse_args()
00101 if not args:
00102 parser.error("you must specify a package name and optionally also list package dependencies")
00103 package = args[0]
00104
00105 if not roslib.names.is_legal_resource_base_name(package):
00106 parser.error("illegal package name: %s\nNames must start with a letter and contain only alphanumeric characters\nand underscores."%package)
00107
00108
00109 depends = args[1:]
00110 uses_roscpp = 'roscpp' in depends
00111 uses_rospy = 'rospy' in depends
00112
00113 for d in depends:
00114 try:
00115 roslib.packages.get_pkg_dir(d)
00116 except roslib.packages.InvalidROSPkgException:
00117 print >> sys.stderr, "ERROR: dependency [%s] cannot be found"%d
00118 sys.exit(1)
00119 depends = u''.join([u' <depend package="%s"/>\n'%d for d in depends])
00120
00121 if not on_ros_path(os.getcwd()):
00122 print >> sys.stderr, '!'*80+"\nWARNING: current working directory is not on ROS_PACKAGE_PATH!\nPlease update your ROS_PACKAGE_PATH environment variable.\n"+'!'*80
00123 if type(package) == str:
00124 package = package.decode('utf-8')
00125 create_package(package, author_name(), depends, uses_roscpp=uses_roscpp, uses_rospy=uses_rospy)
00126
00127 if __name__ == "__main__":
00128 roscreatepkg_main()