Пример #1
0
def main():

	svn_args = arg.repos_args("svn")
	if svn_args == "-m":
		os.system("svn st | grep '^M' | awk '{print $2}'")
	elif svn_args == "-d":
		os.system("svn st | grep '^!' | awk '{print $2}'")
	elif svn_args == "-o":
		os.system("svn st | grep '^?' | awk '{print $2}'")
	# Clean all svn repos at current path
	elif svn_args == "-c":
		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 " + r + " | grep '^M' | awk '{print $2}' | xargs svn revert ")
			cmd.tryit("svn st " + 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":
		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")

	sys.exit(0)
Пример #2
0
	def wmakefile(self, project_dict):
		# 开始写文件
		printf.status("write include makefile ...")
		file_name = project_dict[glb.project_path] + "/" + self.makefile
		fp = open(file_name, 'w')
		printf.silence("file - " + file_name)

		# 添加项目名称到makefile
		if project_dict.has_key(glb.project_name):
			fp.write("# 项目名称\n" + "PROJECT = " + project_dict[glb.project_name] + "\n")

		# 添加源码路径到makefile
		if project_dict.has_key(glb.source_path):
			fp.write("# 源码路径\n" + "SRC_DIR = " + project_dict[glb.source_path] + "\n")

		# 添加安装路径到makefile
		if project_dict.has_key(glb.installe_path):
			fp.write("# 安装路径\n" + "EXEC_DIR = " + project_dict[glb.installe_path] + "\n")

		# 添加补丁路径到makefile
		if project_dict.has_key(glb.patch_path):
			fp.write("# 补丁路径\n" + "PATCH_DIR = " + project_dict[glb.patch_path] + "\n")
			fp.write("# 补丁标志\n" + "PATCH_FLAG = " + glb.patch_flag + "\n")

		# 添加开源路径到makefile
		if project_dict.has_key(glb.repos):
			fp.write("# 开源路径\n" + "REPOS = " + project_dict[glb.repos] + "\n")
		
		# 写文件完成
		fp.close()

		return
Пример #3
0
	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
Пример #4
0
	def patch_args(self):
		printf.status("parse args ...")
		try:
			opts, args = getopt.getopt(sys.argv[1:], "hf:a:ulo:", ["help"])
		except getopt.GetoptError , err:
			printf.warn(str(err)) # will print something like "option -a not recognized"
			self.patch_usage()
			sys.exit(1)
Пример #5
0
	def mkdev(self):
		printf.status("make dev ...")
		for x in range(0, len(self.mkdevDict)):
			if not os.path.isdir(self.mkdevDict[x][0]):
				cmd.do("mkdir -p " + self.mkdevDict[x][0])
			command = self.mkdevDict[x][1] + self.mkdevDict[x][0] \
			+ "/" + self.mkdevDict[x][2] + self.mkdevDict[x][3]
			cmd.do(command)
		return
Пример #6
0
	def is_patched(self):
		## 补丁标志文件
		patch_flag_file = self.in_path + "/" + glb.patch_flag
		if os.path.exists(patch_flag_file):
			printf.status("可以去除补丁。")
			return 1
		else:
			printf.status("可以打上补丁。")
			return 0
Пример #7
0
	def hostip(self):
		host_ip = ""
		ips_get = "/sbin/ifconfig | grep -i \"inet addr:\" | awk {'print $2'} | sed -ne 's/addr://p'"
		ips     = commands.getoutput(ips_get)
		ipsList = ips.split("\n")
		for i in ipsList:
			if i.startswith("127."):
				continue
			else:
				host_ip = i
		printf.status("Host IP - " + host_ip)
		return host_ip
Пример #8
0
	def pop(self):
		if len(self.timestack) == 0:
			printf.error(os.path.abspath(__file__) + ": len(timestack) is 0")
			sys.exit(1)
		data      = time.timestack.pop()
		now       = datetime.now()
		timer     = now - data[1]
		str_timer = " - " + str(timer.seconds/3600) + 'h:' \
		            + str(timer.seconds%3600/60) + 'm:' \
		            + str(timer.seconds%60) + 's'
		printf.status(data[0] + str_timer)
		return
Пример #9
0
def main():
	# start links
	printf.reset()
	time.push(os.path.abspath(__file__))
	links_args = arg.links_args()
	
	# Judge source folder
	if not os.path.isdir(links_args['-s']):
		printf.error("No a dir - " + links_args['-s'])
	if not os.path.isdir(links_args['-d']):
		cmd.do("mkdir -p " + links_args['-d'])
	links_args['-s'] = os.path.abspath(links_args['-s'])

	# create folder and link for file
	printf.status("links ...")
	for root, dirs, files in os.walk(links_args['-s']):		
		# set filter
		if '.git' in dirs:
			dirs.remove('.git')  # don't visit .git directories
		if '.svn' in dirs:
			dirs.remove('.svn')  # don't visit .svn directories

		# Create folder
		current_folder = root.replace(links_args['-s'], "")
		new_folder     = links_args['-d'] + "/" + current_folder
		cmd_mkdir = "mkdir -p " + "\"" + new_folder + "\""
		os.system(cmd_mkdir)
		sys.stdout.write('\r' + current_folder)
		sys.stdout.flush()
		#print "\r\n", cmd_mkdir
		#raw_input("Press ENTER to exit")

		# link for files
		for f in files:
			source_file = "\"" + root       + "/" + f + "\""
			link_file   = "\"" + new_folder + "/" + f + "\""
			cmd_ln = "ln -sf " + source_file + " " + link_file
			os.system(cmd_ln)
			#print "\r\n", cmd_ln
		size = len(current_folder)
		sys.stdout.write('\r' + ' '*size)
		sys.stdout.flush()

	# done.
	print ""
	printf.status("links done.")

	# end links
	time.pop()
	sys.exit(0)
Пример #10
0
	def modify(self, filename, flag, content):
		# judge
		fp = open(filename, "r")
		for line in fp:
			if flag in line:
				fp.close()
				printf.status("With [" + flag + "] already.")
				sys.exit(0)
		fp.close()

		# modify
		fp = open(filename, "a")
		fp.write(content)
		fp.close()
		printf.status("Write [" + flag + "] success.")

		return
def main():
	printf.reset()

	# judge config
	fp = open(bashrc_file,"r")
	for line in fp:
		if config_flag in line:
			fp.close()
			printf.status("Config env for buildsys already.")
			sys.exit(0)
	fp.close()

	# modify .bashrc
	fp = open(bashrc_file,"a")
	fp.write(env_content)
	fp.close()
	printf.status("Config env for buildsys success.")

	sys.exit(0)
Пример #12
0
def main():
	# Judge args
	printf.reset()
	if len(sys.argv) != 3:
		printf.silence("Usage:")
		printf.silence(sys.argv[0] + " [input file] [output file]")
		sys.exit(1)
	if not os.path.isfile(sys.argv[1]):
		printf.error("Not a file - " + sys.argv[1])

	# print env
	printf.status("All env ...")
	for x in range(0, len(env_name_dict)):
		printf.silence(env_name_dict[x] + " = " + os.environ[env_name_dict[x]])

	# copy and replace
	cmd.do("cp -f " + sys.argv[1] + " " + sys.argv[2])
	for x in range(0, len(env_name_dict)):
		replace = "sed -i \'s" + "|$(" + env_name_dict[x] + ")|" + os.environ[env_name_dict[x]] + "|g\' " + sys.argv[2]
		cmd.do(replace)

	sys.exit(0)
Пример #13
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)
Пример #14
0
    def send(self):
        smtpserver = smtplib.SMTP(self.smtp, self.port)
        smtpserver.set_debuglevel(True)
        printf.status("smtpserver - ehlo")
        smtpserver.ehlo()
        printf.status("smtpserver - starttls")
        smtpserver.starttls()
        printf.status("smtpserver - ehlo")
        smtpserver.ehlo
        printf.status("smtpserver - login")
        smtpserver.login(self.me, self.pwd)
        
        msg            = MIMEMultipart('alternative')
        msg['Subject'] = self.subject
        msg['From']    = self.me
        msg['To']      = "亲的"
        HTML_BODY      = MIMEText(self.info, 'html')
        msg.attach(HTML_BODY)
        printf.status("smtpserver - sendmail")
        smtpserver.sendmail(self.me, self.to, msg.as_string())
        smtpserver.quit()

        return
Пример #15
0
def main():
    printf.reset()
    printf.status("deploy html ...")

    # walk
    for root, dirs, files in os.walk(os.getcwd()):
        for f in files:
            if f.split(".")[-1].upper() == "MD":
                of = root + "/" + f
                nf = root + "/" + f[0:len(f) - 2] + "html"
                command = "pandoc -s -S " + of + " -o " + nf
                cmd.do(command)
    # copy
    if not os.path.isdir(apache_path):
        printf.error("Error path: " + apache_path)
    command = "cp -rf * " + apache_path
    cmd.do(command)

    #delete
    command = "find " + apache_path + " -name \"*.md\" | xargs rm -f"
    cmd.do(command)

    sys.exit(0)
Пример #16
0
	def patch(self, _a):
		global patch_cmd
		patch_cnt = 0
		
		if _a == 0:
			printf.silence("执行对源码打上补丁 ...")
			if self.is_patched() == 1:
				printf.warn("warnning: 源码已打上补丁!")
				return
			end_flag = ""
		else:
			printf.silence("执行对源码去除补丁 ...")
			if self.is_patched() == 0:
				printf.warn("warnning: 源码已去除补丁!")
				return
			end_flag = " -R"

		# 补丁类表
		patch_list = []
		patch_list.extend(glob.glob(self.out_path + "/*" + glb.patch_filetype))
		# 处理所有补丁
		for i in patch_list:
			# git和svn产生的补丁路径不一样,区别对待
			if i.find("git-") != -1:
				level = self.cmd_git['level']
			else:
				level = patch_cmd['level']
			patch_cnt = patch_cnt + 1
			cmd.do("patch -d " + self.top_path + level + i + end_flag)

		# 完成操作退出
		printf.status("Total patch: " + str(patch_cnt))
		if patch_cnt == 0 and _a == 0:
			self.create_flag(0)
		else:
			self.create_flag(not _a)
Пример #17
0
def main():
	# start send
	printf.reset()
	
	time.push(os.path.abspath(__file__))

	# loop send mail
	current = 0
	scnt    = 0
	fcnt    = 0
	onetime = 16
	cmd.do("rm -f number.py*")
	cmd.do("random_number.py")
	fp = open("send_done", 'w')
	fp.close()
	import number
	maxcnt  = number.array_len/onetime
	while 1:
		if scnt > maxcnt:
			break
		pos0 = scnt * onetime
		pos1 = pos0 + onetime
		if pos1 > number.array_len:
			pos1 = number.array_len
		send.to      = number.name_array[pos0:pos1]
		send.me      = data.me[current]
		send.pwd     = data.pwd
		send.smtp    = data.smtp[current]
		send.port    = data.port[current]
		send.subject = data.subject
		send.info    = data.info
		printf.status(data.me[current])
		try:
			send.send()
			scnt = scnt + 1
			printf.status("sucess to send - " + str(scnt))
			printf.status("fail to send - " + str(fcnt))
			fp = open("send_done", 'a')
			fp.write(str(scnt) + " - " + str(send.to) + "\n")
			fp.close()
		except:
			fcnt = fcnt + 1
			current = current + 1  # change email user name
			if current >= len(data.me):
				current = 0 # again
			printf.warn("sucess to send - " + str(scnt))
			printf.warn("fail to send - " + str(fcnt))
			systime.sleep(3)

	# end send
	fp.close()
	time.pop()
	printf.silence("send done.")

	sys.exit(0)
Пример #18
0
def main():

	svn_args = arg.repos_args("git")
	if svn_args == "-m":
		os.system("git status -s | grep '^ M' | awk '{print $2}'")
	elif svn_args == "-d":
		os.system("git status -s | grep '^ D' | awk '{print $2}'")
	elif svn_args == "-o":
		os.system("git status -s | grep '^??' | awk '{print $2}'")	
	elif svn_args == "-s":
		printf.status("Remote URL:")
		os.system("git remote -v")
		printf.status("Remote Branches: ")
		os.system("git branch -r")
		if os.path.isfile(".git/config"):
			printf.status("== Configuration .git/config")
			os.system("cat .git/config")
		printf.status("== Most Recent Commit")
		os.system("git --no-pager log --max-count=1")

	sys.exit(0)
Пример #19
0
	def hostmac(self):
		import uuid
		hostmac = ':'.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0,8*6,8)][::-1])
		printf.status("Host MAC - " + hostmac)
		return hostmac
Пример #20
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
Пример #21
0
	def change(self, new_path):
		if not os.path.isdir(new_path):
			printf.error(new_path + " - " + " not a path !")
		printf.status("change path: " + new_path)
		os.chdir(new_path)
		return
Пример #22
0
	def push(self):
		self.pathstack.append(os.getcwd())
		printf.status("path push - " + os.getcwd())
		return
Пример #23
0
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)
Пример #24
0
def main():
	global num_min, num_max, same, active, total, out, name_arra

	printf.reset()
	time.push(os.path.abspath(__file__))

	printf.status("write file ...")
	fp = open(out, 'w')

	random.seed()
	for i in range(total):
		name = str(random.randrange(num_min, num_max))
		if name in name_array:
			same  = same + 1
			printf.status("same: " + name)
		else:
			active = active + 1
			name_array.append("\"" + str(name) + "@qq.com" + "\"")
	printf.status("same:   "  + str(same))
	printf.status("active: "  + str(active))
	printf.status("total:  " + str(total))
	printf.status("len(name_array): " + str(len(name_array)))

	fp.write("array_len  = " + str(active) + "\n")
	fp.write("name_array = [\n")
	for i in range(len(name_array)):
		fp.write(name_array[i] + ",")
		if((i+1)%16 == 0):
			fp.write("\n")
	fp.write("]\n")

	fp.close()
	time.pop()
	sys.exit(0)
Пример #25
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()
Пример #26
0
	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)
Пример #27
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