os
- 獲取當前路徑 : os.getcwd()
- 獲取某個目錄下所有文件:os.listdir(file_path)
- 根據(jù)字符串創(chuàng)建目錄:os.makedirs(local_pod)
- 獲取系統(tǒng)Home目錄路徑:os.environ['HOME']
- 切換目錄:os.chdir(example_path)
- 執(zhí)行終端命令(shell、git、pod 等):os.system('sh pod_framework_mode.sh')
7.從一個命令打開一個管道:current_repo_current_branchs = os.popen('git symbolic-ref --short -q HEAD').readlines()
- 刪除文件:os.remove(current_file_path)
- 通過在目錄樹中游走輸出在目錄中的文件名,向上或者向下: for root, dirs, files in os.walk(file_dir):
os.path
- 將一個路徑拆分為 名字 和 后綴:(name, ext) = os.path.splitext(file),if ext == '.podspec'
- 將多個字符串拼接在一起組成一個路徑:example_path = os.path.join(current_path, main_module_name, 'Example')
- 判斷某個目錄是否存在:if os.path.exists(local_pod) is not True:
- 判斷某個路徑是否是文件:if os.path.isfile(file_or_folder):
- 判斷某個路徑是否是文件夾:if os.path.isdir(file_or_folder):
sys
- 獲取執(zhí)行命令時帶的參數(shù):args = sys.argv[1:]
- 系統(tǒng)推出:sys.exit()
string
- 判斷一個字符串是否包含一個子字符串:if ext == '.podspec' and string.find(file, 'Protocol') == -1:
- 將字符串轉為大寫或小寫:if string.lower(name) == 'y' or string.lower(name) == 'yes' or name == '':
- 判斷一個字符串是否包含一個子字符串:if string.find(line, module_name) != -1:
shutil
- 復制文件到目的目錄:shutil.copy(file_or_folder, destination)
- 將目錄下文件全部刪除:shutil.rmtree(destination)
- 復制文件夾:shutil.copytree(file_path, current_file_path)
- 復制文件:shutil.copyfile(file_path, current_file_path)
from distutils.dir_util import copy_tree:
- 將某個路徑下所有文件復制到另外一個路徑下:copy_tree(path, backup_path)
datetime
- 獲取當前時間:current_date = datetime.now()
- 將當前時間轉為相應格式:date_str = current_date.strftime('%y年%m月%d日')
subprocess
- 關閉 Xcode :subprocess.call(['osascript', '-e', 'tell application "Xcode" to quit'])
系統(tǒng)內置
- 獲取控制臺輸入字符串: name = raw_input(bcolors.WARNING + '確認要拷貝代碼到git目錄下?\n確定?請輸入(Y/N)\n' + bcolors.ENDC)
- 打印字符串:print(bcolors.HEADER + '開始執(zhí)行注入模式>>>>\n' + bcolors.ENDC)
- 打開文件:open(pod_file, 'r')
- 讀取文件內容:file_handler.readlines()
- 將內容寫到文件里面去:out.writelines(content)
- 獲取數(shù)組指定元素index:index = content.index(line)
- 查找字符串里面指定字符串位置:path_index = str.find('path =>')
- 查找字符串指定位置后面某個字符串的index:module_start = str.find(''', path_index) + 1
- 根據(jù)兩個index獲取子字符串:module_path = str[module_start: module_end]
10.數(shù)組元素個數(shù):if len(current_repo_current_branchs) > 0:
11.將字符串以某個字符為間隔轉為數(shù)組:remotes_origin_branch_arr = remotes_origin_branch.split('/') - 字符串替換某個字符為其他字符:branch = remotes_origin_branch_arr[2].replace('\n', '')
- 數(shù)組后面追加元素:manifest_all_branch.append(branch.strip())
- 移除字符串頭尾指定的字符(默認為空格或換行符)或字符序列:if manifest_branch.strip() not in manifest_all_branch:
- 刪除數(shù)組元素:del list[len(list) - 1]
- 數(shù)組替換:file_contents=file_contents.replace(old_import, new_import)
Git 相關
- 獲取當前倉庫當前分支:git symbolic-ref --short -q HEAD
- git 倉庫根目錄:git rev-parse --show-toplevel