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


winros_create_pkg
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:14:40