35 from __future__
import print_function
45 from rospkg
import ResourceNotFound
46 from rospkg
import RosPack
47 from rospkg
import on_ros_path
49 NAME =
'roscreate-pkg' 54 templates[
'CMakeLists.txt'] =
read_template(
'CMakeLists.tmpl')
62 return template % locals()
65 def create_package(package, author, depends, uses_roscpp=False, uses_rospy=False):
66 p = os.path.abspath(package)
68 print(
'%s already exists, aborting' % p, file=sys.stderr)
72 print(
'Created package directory', p)
76 cpp_path = os.path.join(p,
'include', package)
79 print(
'Created include directory', cpp_path)
80 cpp_path = os.path.join(p,
'src')
82 print(
'Created cpp source directory', cpp_path)
88 py_path = os.path.join(p,
'src')
91 print(
'Created python source directory', py_path)
97 for filename, template
in templates.items():
99 p = os.path.abspath(os.path.join(package, filename))
100 with open(p,
'w')
as f:
101 f.write(contents.encode(
'utf-8'))
102 print(
'Created package file', p)
103 print(
'\nPlease edit %s/manifest.xml and mainpage.dox to finish creating your package' % package)
107 from optparse
import OptionParser
108 parser = OptionParser(usage=
'usage: %prog <package-name> [dependencies...]', prog=NAME)
109 options, args = parser.parse_args()
111 parser.error(
'you must specify a package name and optionally also list package dependencies')
114 if not roslib.names.is_legal_resource_base_name(package):
115 parser.error(
'illegal package name: %s\nNames must start with a letter and contain only alphanumeric characters\nand underscores.' % package)
119 uses_roscpp =
'roscpp' in depends
120 uses_rospy =
'rospy' in depends
126 except ResourceNotFound:
127 print(
'ERROR: dependency [%s] cannot be found' % d, file=sys.stderr)
130 depends =
u''.join([
u' <depend package="%s"/>\n' % d
for d
in depends])
132 if not on_ros_path(os.getcwd()):
133 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)
134 if type(package) == str:
135 package = package.decode(
'utf-8')
def instantiate_template(template, package, brief, description, author, depends)
def create_package(package, author, depends, uses_roscpp=False, uses_rospy=False)