Last active
October 6, 2015 03:27
-
-
Save Superbil/2927944 to your computer and use it in GitHub Desktop.
Make XCode3 library to XCode.app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# \brief Make XCode3 library to XCode.app | |
# \details This is only work on XCode 4.2+ | |
# \version 0.7 | |
# \date 2012 | |
# \author superbil | |
import os | |
import sys | |
import re | |
import argparse | |
''' | |
Change Log: | |
0.7 增加測試, 修正參數傳入的方式 | |
0.6.1 修正Coding styple | |
0.6 修正使用呼叫的方法 | |
0.5 新增 Simulator 連接 | |
0.4 新增執行目錄檢查 | |
0.3 修正以 argv[1] 當作路徑 | |
0.2 使用 subprocess 執行 shell script | |
0.1 初始基本功能 | |
''' | |
version = '0.7' | |
## \brief | |
# \english | |
# mapping link function from source_path to target_path | |
# \param source_path source link from | |
# \param target_path is target link to | |
# \param math_rule is regular | |
# \param debug is show debug message | |
# \param test_run is run for test | |
# make_link no return vale | |
# \endenglish | |
# | |
# \chinese | |
# 把來源路徑下的子資料夾連接到目標路徑 | |
# \param source_path 來源路徑,會把該路徑下的所有符合 math_rule 的資料做 link | |
# \param target_path 連接的目標路徑 | |
# \param math_rule 符合條件,可以不傳入任何值 | |
# \param debug 顯示除錯訊息 | |
# \param test_run 測試過程 | |
# make_link 不回傳任何值 | |
# \endchinese | |
# \note use '*' must add '\s' before it, like '\s*' | |
## \define 為取得目前 script 資料夾的路徑 | |
pwd = os.getcwd() | |
def make_link(source_path, target_path, math_rule = '\s*', debug=True, | |
test_run=False): | |
# 在測試的時候強制開啟除錯資訊 | |
if test_run: | |
debug=True | |
# 檢查來源路徑是否存在,必需要該目錄下執行 | |
if not os.path.exists(source_path): | |
print "You must run this script on the SDKs folder" | |
exit() | |
if debug: print "Link " + source_path # debug message, link from ... | |
# 列出來源資料夾下的項目 | |
for item in os.listdir(source_path): | |
# 比對是否符合規則 | |
if re.search(math_rule,item): | |
src_item = os.path.join(source_path,item) | |
src = os.path.join(pwd,src_item) | |
dst = os.path.join(xcode_path,target_path,src_item) | |
if debug: | |
print "target path : " + dst # debug message, target is ... | |
if not os.path.exists(dst) or debug: | |
# 顯示路徑是否存在並建立之 | |
if debug: | |
print "make dir " + dst # debug message, make dir | |
if not test_run: | |
os.makedirs(dst) | |
if debug: | |
print src + " -> " + dst # debug message, source -> dest | |
if not test_run: | |
os.symlink(src,dst) | |
if __name__ == "__main__": | |
# setup args parse | |
parser = argparse.ArgumentParser(description='This is only work on XCode 4.2+') | |
parser.add_argument('-d', '--debug', action='store_true', | |
default=False, help='show debug message') | |
parser.add_argument('-v', '--version', action='version', | |
version='%s' % (version), help='version number') | |
parser.add_argument('-t', '--test', action='store_true', | |
default=False, help='test running') | |
parser.add_argument('xcode_path', action='store',help='Xcode path (require)') | |
# magic work here | |
args = parser.parse_args(sys.argv[1:]) | |
v = vars(args) | |
d = v['debug'] | |
if d: | |
print 'input var', v | |
t = v['test'] | |
## \par Get Xcode path | |
# /Applications/Xcode.app/ will use Xcode path with '/Contents/' to /Applications/Xcode.app/ | |
xcode_path = os.path.join(v['xcode_path'] + '/Contents/') | |
## \define 定義錯誤訊息 | |
error_str = "must install Xcode.app 4.2+ first" | |
try: | |
## 檢查 xcode_select_path 路徑是否正確 | |
if not os.path.exists(xcode_path): | |
print "Path is no exist, %s" % (error_str) | |
sys.exit() | |
## xcode_path 沒有設定時,無法使用 | |
except NameError: | |
print "Xcode path is error, %s" % (error_str) | |
sys.exit() | |
if d: | |
print "Get Xcode path at " + xcode_path | |
## \par run mapping path | |
# Pre Path is 'Xcode.app/Contents/' | |
make_link('SDKs','Developer/Platforms/MacOSX.platform/Developer/SDKs', debug=d, test_run=t) | |
make_link('lib','Developer/usr/lib', debug=d, test_run=t) | |
make_link('libexec','Developer/usr/libexec/', debug=d, test_run=t) | |
make_link('bin','Developer/usr/bin/', '\s*4.0\s*', debug=d, test_run=t) | |
make_link('Plug-ins','PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins','\s*4.0\s*', debug=d, test_run=t) | |
make_link('Simulator','Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs', debug=d, test_run=t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment