winros_init_workspace.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2013, Yujin Robot, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Yujin Robot nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 
00033 from __future__ import print_function
00034 import sys
00035 import os
00036 import os.path
00037 import win_ros
00038 import argparse
00039 import wstool.wstool_cli
00040 from rosinstall.helpers import ROSInstallException
00041 from rosinstall.common import MultiProjectException
00042 
00043 def parse_args():
00044     parser = argparse.ArgumentParser(description="\
00045         Prepares a win-ros workspace:\n\n\
00046   1. Prepares a multi-vcs workspace with wstool \n\
00047   2. Populates with pre-specified win-ros source sets if requested\n\
00048   3. Prepares a convenience setup.bat",
00049         epilog="See http://www.ros.org/wiki/win_python_build_tools for details.",
00050         formatter_class=argparse.RawTextHelpFormatter )
00051     group = parser.add_mutually_exclusive_group()
00052     group.add_argument('--sdk-stable', action='store_true',  # default is true
00053                         help='populate with the sdk stable sources [false]')
00054     group.add_argument('--sdk-unstable', action='store_true',  # default is true
00055                         help='populate with the sdk unstable sources [false]')
00056     group.add_argument('--comms-stable', action='store_true',  # default is true
00057                         help='populate with the comms stable sources [false]')
00058     group.add_argument('--comms-unstable', action='store_true',  # default is true
00059                         help='populate with the comms unstable sources [false]')
00060     parser.add_argument('path', type=str, default=".",
00061                    help='base path for the workspace')
00062     return parser.parse_args()
00063 
00064 def populate(base_path, rosinstall_file_uri):
00065     '''
00066       @param rosinstall_file_uri : the uri for the rosinstall file
00067       @param distro : whether it is win_ros.STABLE or win_ros.UNSTABLE 
00068     '''
00069     wstool_arguments = ['wstool', 
00070                         'merge', 
00071                         rosinstall_file_uri,
00072                         "--target-workspace=%s"%os.path.join(base_path, 'src')
00073                         ]
00074     wstool.wstool_cli.wstool_main(wstool_arguments)
00075     wstool_arguments = ['wstool', 
00076                         'update', 
00077                         "--target-workspace=%s"%os.path.join(base_path, 'src')
00078                         ]
00079     wstool.wstool_cli.wstool_main(wstool_arguments)
00080 
00081 if __name__ == "__main__":
00082     args = parse_args()
00083     if os.path.isabs(args.path):
00084        base_path = args.path
00085     else:
00086         base_path = os.path.abspath(args.path)
00087     if not os.path.isdir(base_path):
00088         os.mkdir(base_path)
00089     os.mkdir(os.path.join(base_path, 'src'))
00090     wstool_arguments = ['wstool', 'init', os.path.join(base_path, 'src')]
00091     try:
00092         wstool.wstool_cli.wstool_main(wstool_arguments)
00093     except ROSInstallException as e:
00094         sys.stderr.write("ERROR in wstool: %s\n" % str(e))
00095         sys.exit(1)
00096     except MultiProjectException as e:
00097         sys.stderr.write("ERROR in config: %s\n" % str(e))
00098         sys.exit(1)
00099     text = win_ros.write_setup_bat(base_path)
00100     distro = win_ros.STABLE  # default
00101     if args.sdk_stable:
00102         populate(base_path, 'https://raw.github.com/ros-windows/win_ros/groovy-devel/msvc_groovy.rosinstall')
00103         #populate(base_path, 'https://raw.github.com/ros-windows/win_ros/groovy-devel/msvc_unstable.rosinstall')
00104     if args.sdk_unstable:
00105         populate(base_path, 'https://raw.github.com/ros-windows/win_ros/groovy-devel/msvc_unstable.rosinstall')
00106         distro = win_ros.UNSTABLE
00107     if args.comms_stable:
00108         #populate(base_path, 'https://raw.github.com/ros-windows/win_ros/groovy-devel/msvc_groovy_comms.rosinstall')
00109         populate(base_path, 'https://raw.github.com/ros-windows/win_ros/groovy-devel/msvc_unstable_comms.rosinstall')
00110     if args.comms_unstable:
00111         populate(base_path, 'https://raw.github.com/ros-windows/win_ros/groovy-devel/msvc_unstable_comms.rosinstall')
00112         distro = win_ros.UNSTABLE
00113     win_ros.write_toplevel_cmake(os.path.join(base_path, 'src'), distro)


win_python_build_tools
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:23:48