def do_makes(self): printf.status("build ...") # build all projects for i in build_ini.list_of_dict: printf.silence("build project: " + i[glb.project_name]) project_path = i[glb.project_path] path.push() path.change(project_path) # 缺省无参数 - clean、make、install action_sum = self.build_args['-c'] + self.build_args['-m'] + self.build_args['-i'] # 执行相关make动作之前,先打上补丁 patch_repos.patch_args = {"-f":build_ini.ini, "-p": i[glb.project_name], "-a":0} patch_repos.do_patch() # make others, 执行完后返回 if self.build_args['-x'] != '': self.make_others(i) return # make clean if self.build_args['-c'] == 1 or action_sum == 0: self.make_clean(i) # make if self.build_args['-m'] == 1 or action_sum == 0: self.make(i) # make install if self.build_args['-i'] == 1 or action_sum == 0: self.make_install(i) path.pop() return
def main(): printf.reset() git_add_remote_args = arg.git_add_remote_args() ## list repos for r in os.walk(os.getcwd()).next()[1]: if not str(r).find(".git"): continue # print ini if not git_add_remote_args['-p'] == "": group = str(git_add_remote_args['-u']).split(":")[-1] + str(r).split(".git")[0] print "[group " + group + "]" print "members = @local/gitosis-admin" print "writable = " + group repo = str(git_add_remote_args['-u']).split(":")[-1] + r print "[repo " + repo + "]" print "gitweb = yes" print "description = clone at @ AAAAA/" + r print "" print "#" + "+"*79 continue # push to new remote path.push() path.change(r) command = "git-push-server.sh " + git_add_remote_args['-u'] + r + " " + git_add_remote_args['-n'] cmd.do(command) path.pop() sys.exit(0)
def main(): svn_args = arg.repos_args("svn") if svn_args['-p'] != "": path.push() path.change(svn_args['-p']) if svn_args['-m'] == "true": os.system("svn st --no-ignore | grep '^M' | awk '{print $2}'") elif svn_args['-d'] == "true": os.system("svn st --no-ignore | grep '^!' | awk '{print $2}'") elif svn_args['-o'] == "true": os.system("svn st --no-ignore | grep '^?' | awk '{print $2}'") # Clean all svn repos at current path elif svn_args['-r'] == "true": current_path = os.getcwd() for r in os.walk(current_path).next()[1]: rev = os.popen("svn info " + r + " | awk '/Revision:/ { print $2 }'").read() rev = "-svn" + rev.split("\n")[0] # patch backup cmd.tryit("svn st --no-ignore " + r + " | grep '^M' | awk '{print $2}' | xargs svn revert ") cmd.tryit("svn st --no-ignore " + r + " | grep '^?' | awk '{print $2}' | xargs rm -rf ") cmd.tryit("find " + r + " -name \"*.o\" | xargs rm -f") cmd.tryit("svn up " + r) # backup all svn repos at current path elif svn_args['-b'] == "true": current_path = os.getcwd() for r in os.walk(current_path).next()[1]: rev = os.popen("svn info " + r + " | awk '/Revision:/ { print $2 }'").read() rev = "-svn" + rev.split("\n")[0] cmd.tryit("tar -jcf " + r + rev + ".tar.bz2 " + r) elif svn_args == "-s": printf.status("svn info") os.system("svn info") if svn_args['-p'] != "": path.pop() sys.exit(0)
def do_patch(self): global patch_cmd printf.status("patch ...") # olny list all repos name if self.patch_args.has_key("-l"): if self.patch_args['-l'] != "": printf.status("only for list !") return # patch all projects n = 0 for i in build_ini.list_of_dict: # 只为当前使用的section执行补丁动作 n = n + 1 if self.patch_args.has_key("-o") and self.patch_args['-o'] != "": if self.patch_args['-o'] != str(n): printf.status("no need patch!") continue # 保存当前section的ini参数 self.ini_args = i printf.silence("patch project: " + i[glb.project_name]) # 设置源码路径 if not i.has_key(glb.source_path): printf.warn("warnning: No source path !") continue self.in_path = os.path.abspath(i[glb.source_path]) # 设置源码路径 - 此路径下的非托管文件全部生成补丁 del self.in_all_path[:] # 清除上次的值 for key_search in i: if key_search.find(glb.source_path_all) != -1: value = i[key_search] self.in_all_path.append(os.path.abspath(value)) # 设置补丁路径 if not i.has_key(glb.patch_path): printf.warn("warnning: No patch path !") continue self.out_path = i[glb.patch_path] # 创建补丁路径 if not os.path.isdir(self.out_path): cmd.do("mkdir -p " + self.out_path) # 切换路径 path.push() path.change(self.in_path) # 读取repos类型 if not i.has_key(glb.source_repos): printf.warn("warnning: No source repos !") continue # 设置仓库命令 self.top_path = self.in_path # 默认为根路径 if i[glb.source_repos] == "svn": patch_cmd = self.cmd_svn elif i[glb.source_repos] == "git": patch_cmd = self.cmd_git self.top_path = os.popen("git rev-parse --show-toplevel").read().split("\n")[0] else: printf.error("repos type error - " + i[glb.source_repos]) # 补丁动作 self.action = self.patch_args['-a'] printf.silence("Patch action - " + str(self.action)) if self.action == 0: # 0: 打上补丁 self.patch(0) elif self.action == 1: # 1:去除补丁 self.patch(1) elif self.action == 2: # 2:生成补丁 self.patch_new() # 切回路径 path.pop() return
def patch_new(self): global patch_cmd printf.silence("源码生成补丁 ...") patch_cnt = 0 # 生成单个补丁文件 repos_diff = self.out_path + "/" + self.ini_args[glb.source_repos] + ".diff" fp = codecs.open(repos_diff, "w", "utf-8") fp.close() out_modify = os.popen(patch_cmd['list_modify']).read() # 判断是否需要对非托管文件打补丁 out_untrack = "" if self.patch_args['-u'] == 0: for i in self.in_all_path: # 指定非托管文件打补丁路径,".h"、".c"、".cpp"、".mk" path.push() path.change(i) path_paste = i.replace(self.in_path + "/","") out_untrack_all = os.popen(patch_cmd['list_untrack']).read() path.pop() for i in out_untrack_all.split("\n"): if i == "": continue if i.upper().find(".H") == -1: # 文件过滤 if i.upper().find(".C") == -1: if i.upper().find(".CPP") == -1: if i.upper().find(".MK") == -1: continue out_untrack = out_untrack + path_paste + "/" + i + "\n" else: out_untrack = os.popen(patch_cmd['list_untrack']).read() # 生成修改文件补丁 cmd.do("rm -f " + self.out_path + "/*" + glb.patch_filetype) # 清除老补丁 cmd.do("rm -f " + self.out_path + "/*.diff") # 清除老补丁 patch_list = out_modify.split("\n") printf.status("Modify files: " + str(len(patch_list) - 1)) for i in patch_list: if i == "": continue patch_cnt = patch_cnt + 1 name = self.out_path + "/" + self.ini_args[glb.source_repos] + "-" + i.replace("/","_") + glb.patch_filetype cmd.do(patch_cmd['diff'] + " " + i + " > " + name) cmd.do(patch_cmd['diff'] + " " + i + " >> " + repos_diff) # 生成未托管文件补丁 patch_list = out_untrack.split("\n") printf.status("Untrack files: " + str(len(patch_list) - 1)) for i in patch_list: if i == "" or i.find(glb.patch_flag) != -1: continue patch_cnt = patch_cnt + 1 name = self.out_path + "/" + "git-" + i.replace("/","_") + glb.patch_filetype cmd.tryit("git diff /dev/null " + i + " > " + name) cmd.tryit("git diff /dev/null " + i + " >> " + repos_diff) # 备份新生成的补丁 if os.path.isdir(self.out_path): patch_list_new = [] new_patchs = self.out_path + "/*" + glb.patch_filetype new_diff = self.out_path + "/*.diff" patch_list_new.extend(glob.glob(new_patchs)) if len(patch_list_new) > 0: patch_bak_path = self.out_path + "/" + time.timestamp() cmd.do("mkdir -p " + patch_bak_path) cmd.do("cp " + new_patchs + " " + patch_bak_path) cmd.do("cp " + new_diff + " " + patch_bak_path) # 完成操作退出 printf.status("Total patch: " + str(patch_cnt)) if patch_cnt != 0: self.create_flag(1) else: self.create_flag(0)
def check_out(self, ini): self.ini = ini printf.status("parse ini ...") if not os.path.exists(self.ini): printf.error(self.ini + " is not exsit !") sys.exit(1) # read ini fp = open(self.ini,"r") self.configIni.readfp(fp) fp.close() # parse all sections for opts in self.configIni.options("repos"): # name i = opts.split(".")[0] # path j = os.path.expandvars(self.configIni.get("path", i + ".path")) # repos k = self.configIni.get("repos", opts) self.dict[i] = [j, k] # print check info cnt = 0 chk_one_flg = 0 printf.status("repos status ...") for i in sorted(self.dict): if self.check_args['-o'] != "": if self.check_args['-o'] == i: chk_one_flg = 1 break else: continue cnt = cnt + 1 printf.silence(str(cnt) + " - " + i) repos_path = self.dict[i][0] + "/" + i printf.silence("path - " + repos_path) if os.path.isdir(repos_path): printf.silence("action - update\n") else: printf.silence("action - " + self.dict[i][0] + "\n") # olny list all repos name if self.check_args['-l'] != "": return 0 # judge check one if self.check_args['-o'] != "" and chk_one_flg == 0: printf.error("No <" + self.check_args['-o'] + "> @ " + self.ini) # check out or update cnt = 0 printf.status("check out or update ...") for i in sorted(self.dict): if chk_one_flg == 1: if self.check_args['-o'] != i: continue cnt = cnt + 1 printf.silence(str(cnt) + " - " + i) repos_path = self.dict[i][0] + "/" + i if os.path.isdir(repos_path): printf.silence("action - update\n") path.push() path.change(repos_path) if self.dict[i][1].find("git clone") != -1: printf.silence("git repos") cmd.do("git reset --hard") cmd.do("git pull") elif self.dict[i][1].find("svn co") != -1: printf.silence("svn repos") cmd.do("svn up") else: printf.warn("unkown - " + self.dict[i][1]) path.pop() else: cmd.do("mkdir -p " + self.dict[i][0]) path.push() path.change(self.dict[i][0]) cmd.do(self.dict[i][1]) path.pop()
def main(): git_args = arg.repos_args("git") if git_args['-p'] != "": path.push() path.change(git_args['-p']) if git_args['-m'] == "true": os.system("git status -s | grep '^ M' | awk '{print $2}'") elif git_args['-d'] == "true": os.system("git status -s | grep '^ D' | awk '{print $2}'") elif git_args['-o'] == "true": os.system("git status -s -u | grep '^??' | awk '{print $2}'") #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ elif git_args['-b'] == "true": printf.reset() printf.status("repos backup") current_path = os.getcwd() if(os.path.exists(".git")): printf.status("Top at git repos") else: n = 1 for r in os.walk(current_path).next()[1]: printf.silence("\n" + "+"*80) printf.silence(str(n) + " - " + r) path.change(current_path + "/" + r) n = n + 1 if(not os.path.exists(".git")): printf.warn("Not a git repos - " + r) path.change(current_path) continue rev = os.popen("git rev-parse HEAD").read().split("\n")[0] path.change(current_path) # tar the repos tar = r + "." + rev + ".tar.bz2" if(not os.path.isfile(tar)): cmd.do("tar -jcf " + tar + " " + r) #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ elif git_args['-s'] == "true": #printf.reset() printf.status("repos status") current_path = os.getcwd() if(os.path.exists(".git")): printf.silence("\n" + "+"*80) printf.silence(current_path) cmd.do("git status -su") else: n = 1 for root, dirs, files in os.walk(current_path): if '.git' in dirs: del dirs[:] printf.silence("\n" + "+"*80) printf.silence(str(n) + " - " + root) n = n + 1 path.change(root) info = os.popen("git status -s | grep '^ M' | awk '{print $2}'").read() if(info != ""): printf.silence("-m:") printf.printf(1, info) info = os.popen("git status -s | grep '^ D' | awk '{print $2}'").read() if(info != ""): printf.silence("-d:") printf.printf(1, info) info = os.popen("git status -su | grep '^??' | awk '{print $2}'").read() if(info != ""): printf.silence("-o:") printf.printf(1, info) cmd.do("git status -su") path.change(current_path) #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ elif git_args['-r'] == "true": printf.reset() printf.status("repos revert") current_path = os.getcwd() if(os.path.exists(".git")): revert() else: n = 1 for r in os.walk(current_path).next()[1]: printf.silence("\n" + "+"*80) printf.silence(str(n) + " - " + r) path.change(current_path + "/" + r) revert() path.change(current_path) n = n + 1 if git_args['-p'] != "": path.pop() sys.exit(0)
def do_makes(self): printf.status("build ...") # olny list all repos name if self.build_args['-l'] != "": printf.status("only for list !") return # judge build one build_one_flg = 0 if self.build_args['-o'] != "": n = len(build_ini.list_of_dict) build_one_flg = 1 if int(self.build_args['-o']) > n: printf.error("No project - " + self.build_args['-o']) # build all projects n = 0 for i in build_ini.list_of_dict: n = n + 1 printf.silence("build project: " + i[glb.project_name]) if build_one_flg == 1: if self.build_args['-o'] != str(n): printf.status("no need build!") continue # 判断是否有编译section关键字 if i[glb.project_name].find(glb.build_key) != -1: if i[glb.project_name].find(os.environ['DAVINCI_SDK']) == -1: printf.status("no need build!") continue project_path = i[glb.project_path] path.push() path.change(project_path) # 缺省无参数 - clean、make、install action_sum = self.build_args['-c'] + self.build_args['-m'] + self.build_args['-i'] # 执行相关make动作之前,先打上补丁 patch_repos.patch_args = {"-f":build_ini.ini, "-o": str(n), "-a":0} # 发送标号,从1开始 patch_repos.do_patch() # make others, 执行完后返回 if self.build_args['-x'] != '': self.make_others(i) return # make clean if self.build_args['-c'] == 1 or action_sum == 0: #printf.pause("make clean ...") self.make_clean(i) # make if self.build_args['-m'] == 1 or action_sum == 0: #printf.pause("make ...") self.make(i) # make install if self.build_args['-i'] == 1 or action_sum == 0: #printf.pause("make install ...") self.make_install(i) path.pop() return