示例#1
0
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)
示例#2
0
	def create_flag(self, yes): # yes = 1: create, yes = 0: delete
		## 补丁标志文件
		patch_flag_file = self.in_path + "/" + glb.patch_flag
		if yes == 1:
			cmd.do("touch " + patch_flag_file)
		else:
			cmd.do("rm -f " + patch_flag_file)
示例#3
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
示例#4
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)
示例#5
0
def main():
	printf.reset()

	path = "/home/git/repositories/"
	configs_list = os.popen("find " + path + " -name config").read().split("\n")
	for i in sorted(configs_list):
		if i != "":
			file_name = i.split(path)[1].replace(".git", "").replace("/", "-").replace("-config", ".config")
			command = "ln -sf " + i + " " + file_name
			cmd.do(command)

	sys.exit(0)
示例#6
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)
示例#7
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)
示例#8
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)
示例#9
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)
示例#10
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
示例#11
0
	def make_install(self, project_dict):
		wfile.wmakefile(project_dict)
		cmd.do("make install")
		return
示例#12
0
	def make(self, project_dict):
		wfile.wmakefile(project_dict)
		cmd.do("make all")
		return
示例#13
0
	def make_clean(self, project_dict):
		wfile.wmakefile(project_dict)
		cmd.do("make clean")
		return
示例#14
0
	def make_others(self, project_dict):
		wfile.wmakefile(project_dict)
		cmd.do("make others " + "prjs=\"" + self.build_args['-x'] + "\"")
		return
示例#15
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)
示例#16
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)
示例#17
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()