示例#1
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
示例#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 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)
示例#4
0
def main():

	# start patch
	time.push(os.path.abspath(__file__))

	# check out the project
	check_repos.check_args = arg.check_args()
	ini = os.getcwd() + "/" + check_repos.check_args['-f']
	check_repos.check_out(ini)

	# end patch
	time.pop()
	printf.silence("check out done.")
	sys.exit(0)
示例#5
0
def main():
	# start build
	printf.reset()
	time.push(os.path.abspath(__file__))

	# build the project
	make.build_args  = arg.build_args()
	ini = os.getcwd() + "/" + glb.build_ini
	build_ini.parse(ini)
	make.do_makes()

	# end build
	time.pop()
	printf.silence("build done.")
	sys.exit(0)
示例#6
0
def main():

	# start upload
	printf.reset()
	time.push(os.path.abspath(__file__))

	# check out the project
	upload_repos.upload_args = arg.upload_args()
	ini = upload_repos.upload_args['-f']
	upload_repos.upload(ini)

	# end upload
	time.pop()
	printf.silence("upload done.")
	sys.exit(0)
示例#7
0
def main():

	# start check
	printf.reset()
	time.push(os.path.abspath(__file__))

	# check out the project
	check_repos.check_args = arg.check_args()
	ini = check_repos.check_args['-f']
	check_repos.check_out(ini)

	# end check
	time.pop()
	printf.silence("check out done.")
	sys.exit(0)
示例#8
0
def main():

	# start patch
	time.push(os.path.abspath(__file__))

	# patch the project
	patch_repos.patch_args = arg.patch_args()
	ini = os.getcwd() + "/" + patch_repos.patch_args['-f']
	build_ini.parse(ini)
	patch_repos.do_patch()

	# end patch
	time.pop()
	printf.silence("patch done.")
	sys.exit(0)
示例#9
0
def main():
	# start build
	printf.reset()
	time.push(os.path.abspath(__file__))

	# build the project
	make.build_args  = arg.build_args()
	if make.build_args['-f'] == '':
		ini = os.getcwd() + "/" + glb.build_ini
	else:
		ini = make.build_args['-f']
	build_ini.parse(ini)
	make.do_makes()

	# end build
	time.pop()
	printf.silence("[" + str(datetime.now()) + "]: build done.")
	sys.exit(0)
示例#10
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)
示例#11
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)
示例#12
0
def revert():
	if(not os.path.exists(".git")):
		printf.warn("Not a git repos !")
		return

	git_cmd = "git status -s | grep '^ M' | awk '{print $2}'"
	info = os.popen(git_cmd).read()
	if(info != ""):
		printf.silence("revert -m:")
		os.system(git_cmd + " | xargs git checkout")

	git_cmd = "git status -s | grep '^ D' | awk '{print $2}'"
	info = os.popen(git_cmd).read()
	if(info != ""):
		printf.silence("revert -d:")
		os.system(git_cmd + " | xargs git checkout")

	git_cmd = "git status -s | grep '^??' | awk '{print $2}'"
	info = os.popen(git_cmd).read()
	if(info != ""):
		printf.silence("revert -o:")
		os.system(git_cmd + " | xargs rm -rf")
示例#13
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
示例#14
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
示例#15
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)
示例#16
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()
示例#17
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)