00001 00002 import os 00003 import sys 00004 import shutil 00005 import utils 00006 00007 def get_cpp_templates(package): 00008 template_dir = os.path.join(os.path.dirname(__file__),'templates', 'cpp') 00009 templates = {} 00010 templates['mainpage.dox'] = utils.read_template(os.path.join(template_dir,'mainpage.dox')) 00011 templates['CMakeLists.txt'] = utils.read_template(os.path.join(template_dir,'CMakeLists.txt')) 00012 templates['package.xml'] = utils.read_template(os.path.join(template_dir,'package.xml')) 00013 templates[os.path.join('include',package,package+'.hpp')] = utils.read_template(os.path.join(template_dir,'include','PACKAGE_NAME','package_name.hpp')) 00014 templates[os.path.join('src','lib','CMakeLists.txt')] = utils.read_template(os.path.join(template_dir,'src','lib','CMakeLists.txt')) 00015 templates[os.path.join('src','lib',package+'.cpp')] = utils.read_template(os.path.join(template_dir,'src','lib','package_name.cpp')) 00016 templates[os.path.join('src','CMakeLists.txt')] = utils.read_template(os.path.join(template_dir,'src','CMakeLists.txt')) 00017 templates[os.path.join('src','main.cpp')] = utils.read_template(os.path.join(template_dir,'src','main.cpp')) 00018 return templates 00019 00020 def create_cpp_package_directory(package): 00021 p = os.path.abspath(package) 00022 os.makedirs(p) 00023 print("Created package directory " + p) 00024 os.makedirs(os.path.join(p,"src")) 00025 print("Created package directory " + os.path.join(p,"src")) 00026 os.makedirs(os.path.join(p,"src","lib")) 00027 print("Created package directory " + os.path.join(p,"src","lib")) 00028 os.makedirs(os.path.join(p,"include")) 00029 print("Created package directory " + os.path.join(p,"include")) 00030 os.makedirs(os.path.join(p,"include",package)) 00031 print("Created package directory " + os.path.join(p,"include",package)) 00032 00033 def get_py_templates(package): 00034 template_dir = os.path.join(os.path.dirname(__file__),'templates', 'py') 00035 templates = {} 00036 templates['mainpage.dox'] = utils.read_template(os.path.join(template_dir,'mainpage.dox')) 00037 templates['CMakeLists.txt'] = utils.read_template(os.path.join(template_dir,'CMakeLists.txt')) 00038 templates['package.xml'] = utils.read_template(os.path.join(template_dir,'package.xml')) 00039 templates[os.path.join('scripts',package)] = utils.read_template(os.path.join(template_dir,'scripts','PACKAGE_NAME')) 00040 templates[os.path.join('src',package,'__init__.py')] = utils.read_template(os.path.join(template_dir,'src','PACKAGE_NAME','__init__.py')) 00041 return templates 00042 00043 def create_py_package_directory(package): 00044 p = os.path.abspath(package) 00045 os.makedirs(p) 00046 print("Created package directory " + p) 00047 os.makedirs(os.path.join(p,"scripts")) 00048 print("Created package directory " + os.path.join(p,"scripts")) 00049 os.makedirs(os.path.join(p,"src")) 00050 print("Created package directory " + os.path.join(p,"src")) 00051 os.makedirs(os.path.join(p,"src",package)) 00052 print("Created package directory " + os.path.join(p,"src",package)) 00053 00054 def get_common_templates(package): 00055 template_dir = os.path.join(os.path.dirname(__file__),'templates', 'common') 00056 templates = {} 00057 templates['mainpage.dox'] = utils.read_template(os.path.join(template_dir,'mainpage.dox')) 00058 templates['CMakeLists.txt'] = utils.read_template(os.path.join(template_dir,'CMakeLists.txt')) 00059 templates['package.xml'] = utils.read_template(os.path.join(template_dir,'package.xml')) 00060 return templates 00061 00062 def create_common_package_directory(package): 00063 p = os.path.abspath(package) 00064 os.makedirs(p) 00065 print("Created package directory " + p) 00066 00067 def create_winros_catkin_package(): 00068 (package, depends) = utils.parse_arguments([]) 00069 if 'roscpp' in depends: 00070 create_cpp_package_directory(package) 00071 templates = get_cpp_templates(package) 00072 elif 'rospy' in depends: 00073 create_py_package_directory(package) 00074 templates = get_py_templates(package) 00075 else: 00076 create_common_package_directory(package) 00077 templates = get_common_templates(package) 00078 package_depends = ''.join([' <depend package="%s"/>\n'%d for d in depends]) 00079 cmake_depends = ''.join(['%s '%d for d in depends]) 00080 for filename, template in templates.iteritems(): 00081 contents = utils.instantiate_template(template, package, package, utils.author_name(), package_depends, cmake_depends) 00082 try: 00083 p = os.path.abspath(os.path.join(package, filename)) 00084 f = open(p, 'w') 00085 f.write(contents.encode('utf-8')) 00086 print "Created package file", p 00087 finally: 00088 f.close() 00089 print "\nPlease edit package.xml, mainpage.dox and CMakeLists.txt to finish creating your package."