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 ##############################################################################
00034 # Imports
00035 ##############################################################################
00036 
00037 import sys
00038 import os
00039 import urllib2
00040 
00041 ##############################################################################
00042 # Private Functions
00043 ##############################################################################
00044 
00045 def generate_setup_bat_text():
00046     # overlay or standard
00047     text =  """
00048 REM This is a file auto-generated to assist in a usable win-ros
00049 REM command line environment.
00050 """
00051     home_drive = os.environ['HOMEDRIVE']
00052     program_files = home_drive + r'\Program Files'
00053     program_files_x86 = home_drive + r'\Program Files (x86)'
00054     windows_sdk_env = program_files + r'\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd';
00055     visual_studio_ten_env = program_files + r'\Microsoft Visual Studio 10.0\VC\vcvarsall.bat';
00056     visual_studio_ten_env_x86 = program_files_x86 + r'\Microsoft Visual Studio 10.0\VC\vcvarsall.bat';
00057     wordpad_path = program_files + r'\Windows NT\Accessories\wordpad.exe';
00058     wordpad_path_x86 = program_files_x86 + r'\Windows NT\Accessories\wordpad.exe';
00059     notepp_path = program_files + r'\Notepad++\notepad++.exe';
00060     notepp_path_x86 = program_files_x86 + r'\Notepad++\notepad++.exe';
00061     
00062     text += "\n"
00063     text += "@REM Utility variables\n"
00064     if os.path.isfile(wordpad_path):
00065         text += '@doskey wordpad="'+wordpad_path+'" $1\n'
00066     else:
00067         text += '@doskey wordpad="'+wordpad_path_x86+'" $1\n'
00068     if os.path.isfile(notepp_path):
00069         text += '@doskey notepp="'+notepp_path+'" $1\n'
00070     elif os.path.isfile(notepp_path_x86):
00071         text += '@doskey notepp="'+notepp_path_x86+'" $1\n'
00072     else:
00073         text += '@REM doskey notepp="'+notepp_path+'" $1\n'
00074     text += "\n"
00075     if os.path.isfile(windows_sdk_env):
00076         text += "@REM Environment settings for Windows SDK\n"
00077         text += '@call "' + windows_sdk_env + '" /x86 /Release\n'
00078         text += "@REM The sdk is the default generator for winros,\n"
00079         text += "@REM To use visual studio, uncomment one of the following.\n"
00080         text += '@REM "' + visual_studio_ten_env + '" x86\n'
00081         text += '@REM "' + visual_studio_ten_env_x86 + '" x86\n'
00082     elif os.path.isfile(visual_studio_ten_env):
00083         text += "@REM Environment settings for Visual Studio\n"
00084         text += '@call "' + visual_studio_ten_env + '" x86\n'
00085         text += '@REM call "' + windows_sdk_env + '" /x86 /Release\n'
00086     elif os.path.isfile(visual_studio_ten_env_x86):
00087         text += "@REM Environment settings for Visual Studio\n"
00088         text += '@call "' + visual_studio_ten_env_x86 + '" x86\n'
00089         text += '@REM call "' + windows_sdk_env + '" /x86 /Release\n'
00090     else:
00091         text += "@REM Could not find windows sdk or visual studio, please\n"
00092         text += "@REM install and configure by hand [Windows SDK/Visual Studio]\n"
00093         text += '@REM call "' + windows_sdk_env + '" /x86 /Release\n'
00094         text += '@REM "' + visual_studio_ten_env + '" x86\n'
00095         text += '@REM "' + visual_studio_ten_env_x86 + '" x86\n'
00096     text += '@REM Colours are a god awful ugly canary yellow or vomit green\n'
00097     text += '@color 7\n'
00098     text += "\n"
00099     return text
00100 
00101 ##############################################################################
00102 # Public Functions
00103 ##############################################################################
00104 
00105 
00106 def write_setup_bat(base_path):
00107     text = generate_setup_bat_text()
00108     setup_path = os.path.join(base_path, 'setup.bat')
00109     with open(setup_path, 'w') as f:
00110         f.write(text)
00111 
00112 
00113 def write_toplevel_cmake(base_path, toplevel_cmake_url):
00114 
00115     u = urllib2.urlopen( toplevel_cmake_url )
00116     local_file = open(os.path.join(base_path, 'CMakeLists.txt'), 'w')
00117     local_file.write(u.read())
00118     local_file.close()
00119 
00120 
00121 def is_invalid_workspace(src_path):
00122     '''
00123       Checks for source directory and source CMakeLists.txt.
00124       
00125       @return Error string if not valid, otherwise None
00126     '''
00127     error_str = None
00128     if not os.path.isdir(src_path):
00129         error_str = "[no %s]"% src_path
00130     if not os.path.isfile(os.path.join(src_path, 'CMakeLists.txt')):
00131         # Could copy it in from src/catkin/cmake/toplevel.cmake instead of aborting
00132         error_str = "[no %s/CMakeLists.txt]"% src_path
00133     if error_str:
00134         return "+++ invalid workspace %s. Create a source workspace with 'winros_init_workspace'."%error_str
00135     return None


win_python_build_tools
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:09:59