Go to the documentation of this file.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 from __future__ import print_function
00036
00037 NAME='roscreate-pkg'
00038
00039 import os
00040 import sys
00041
00042 import roslib.names
00043
00044 from roscreate.core import read_template, author_name
00045 from rospkg import on_ros_path, RosPack, ResourceNotFound
00046
00047 def get_templates():
00048 templates = {}
00049 templates['CMakeLists.txt'] = read_template('CMakeLists.tmpl')
00050 templates['manifest.xml'] = read_template('manifest.tmpl')
00051 templates['mainpage.dox'] = read_template('mainpage.tmpl')
00052 templates['Makefile'] = read_template('Makefile.tmpl')
00053 return templates
00054
00055 def instantiate_template(template, package, brief, description, author, depends):
00056 return template%locals()
00057
00058 def create_package(package, author, depends, uses_roscpp=False, uses_rospy=False):
00059 p = os.path.abspath(package)
00060 if os.path.exists(p):
00061 print("%s already exists, aborting"%p, file=sys.stderr)
00062 sys.exit(1)
00063
00064 os.makedirs(p)
00065 print("Created package directory", p)
00066
00067 if uses_roscpp:
00068
00069 cpp_path = os.path.join(p, 'include', package)
00070 try:
00071 os.makedirs(cpp_path)
00072 print("Created include directory", cpp_path)
00073 cpp_path = os.path.join(p, 'src')
00074 os.makedirs(cpp_path)
00075 print("Created cpp source directory", cpp_path)
00076 except:
00077
00078 pass
00079 if uses_rospy:
00080
00081 py_path = os.path.join(p, 'src')
00082 try:
00083 os.makedirs(py_path)
00084 print("Created python source directory", py_path)
00085 except:
00086
00087 pass
00088
00089 templates = get_templates()
00090 for filename, template in templates.iteritems():
00091 contents = instantiate_template(template, package, package, package, author, depends)
00092 p = os.path.abspath(os.path.join(package, filename))
00093 with open(p, 'w') as f:
00094 f.write(contents.encode('utf-8'))
00095 print("Created package file", p)
00096 print("\nPlease edit %s/manifest.xml and mainpage.dox to finish creating your package"%package)
00097
00098 def roscreatepkg_main():
00099 from optparse import OptionParser
00100 parser = OptionParser(usage="usage: %prog <package-name> [dependencies...]", prog=NAME)
00101 options, args = parser.parse_args()
00102 if not args:
00103 parser.error("you must specify a package name and optionally also list package dependencies")
00104 package = args[0]
00105
00106 if not roslib.names.is_legal_resource_base_name(package):
00107 parser.error("illegal package name: %s\nNames must start with a letter and contain only alphanumeric characters\nand underscores."%package)
00108
00109
00110 depends = args[1:]
00111 uses_roscpp = 'roscpp' in depends
00112 uses_rospy = 'rospy' in depends
00113
00114 rospack = RosPack()
00115 for d in depends:
00116 try:
00117 rospack.get_path(d)
00118 except ResourceNotFound:
00119 print("ERROR: dependency [%s] cannot be found"%d, file=sys.stderr)
00120 sys.exit(1)
00121
00122 depends = u''.join([u' <depend package="%s"/>\n'%d for d in depends])
00123
00124 if not on_ros_path(os.getcwd()):
00125 print('!'*80+"\nWARNING: current working directory is not on ROS_PACKAGE_PATH!\nPlease update your ROS_PACKAGE_PATH environment variable.\n"+'!'*80, file=sys.stderr)
00126 if type(package) == str:
00127 package = package.decode('utf-8')
00128 create_package(package, author_name(), depends, uses_roscpp=uses_roscpp, uses_rospy=uses_rospy)