示例#1
0
	def git_add_remote_args(self):
		try:
			opts, args = getopt.getopt(sys.argv[1:], "hu:pn:", ["help"])
		except getopt.GetoptError , err:
			printf.warn(str(err)) # will print something like "option -a not recognized"
			self.git_add_remote_usage()
			sys.exit(1)
示例#2
0
	def mk_chk_ini_args(self):
		try:
			opts, args = getopt.getopt(sys.argv[1:], "hp:f:m", ["help"])
		except getopt.GetoptError , err:
			printf.warn(str(err)) # will print something like "option -a not recognized"
			self.mk_chk_ini_usage()
			sys.exit(1)
示例#3
0
	def repos_args(self, repos):
		try:
			opts, args = getopt.getopt(sys.argv[1:], "hmdobsrp:", ["help"])
		except getopt.GetoptError , err:
			printf.warn(str(err)) # will print something like "option -a not recognized"
			self.repos_usage(repos)
			sys.exit(1)
示例#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 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)
示例#6
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")
示例#7
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)
示例#8
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 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()
示例#10
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)