示例#1
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
示例#2
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)
示例#3
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)
示例#4
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)
示例#5
0
	def pop(self):
		if len(self.pathstack) == 0:
			printf.error(os.path.abspath(__file__) + ": len(pathstack) is 0")
			sys.exit(1)
		self.change(self.pathstack.pop())
		return
示例#6
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
示例#7
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()
示例#9
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