玩蛇网提供最新Python编程技术信息以及Python资源下载!

python方法恢复整理修改过java包

python 培训

python方法恢复整理修改过java包

#!/usr/bin/env python
# encoding: utf-8

import os
import sys
import re
import shutil

start_re = re.compile(r'^#<--\s*((?:\d){,4}-(?:\d){,2}-(?:\d){,2})')

java_re = re.compile(r'\.java$')
end_tag = r'#-->'
cur_path = os.getcwd()
file = open(os.path.join(os.getcwd(), 'changelog.txt'), 'r')
src_basic_dir = os.getcwd()
dest_basic_dir = os.path.join(os.getcwd(), 'deploy')

deploy_version = None
isend = False
deploy_files = []
#www.iplaypython.com

try:
	for l in file:
		l = l.strip()
		if not deploy_version:
			m = re.search(start_re, l)
			if m:
				deploy_version = m.group(1)

				if deploy_version:
					dest_basic_dir = os.path.join(dest_basic_dir, deploy_version.replace('-',''))
					continue
			
		if l == end_tag:
			isend = True
			break

		if not isend:
			deploy_files.append(l)

	for f in deploy_files:
		f = f.replace('\\', '/')
		
		if f.startswith(r'src/'):
			
			f = re.sub(re.compile(r'^src/'), r'build/', f)
			f = re.sub(java_re, '.class', f)
			src_file = os.path.join(src_basic_dir, f).replace('\\', '/')
			dest_file = os.path.join(dest_basic_dir, re.sub(re.compile(r'^build/'), r'WEB-INF/classes/', f)).replace('\\', '/')
		else:
			src_file = os.path.join(src_basic_dir, f).replace('\\', '/')
			dest_file = os.path.join(dest_basic_dir, re.sub(re.compile(r'^(\w+?)/'), '', f) ).replace('\\', '/')
		
		dest_dir = os.path.dirname(dest_file)
		if not os.path.exists(dest_dir):
			os.makedirs(dest_dir)
		if not os.path.isfile(dest_file):
			print src_file + " --> " + dest_file + "----------new"
		else:
			print src_file + " --> " + dest_file + "----------overwrite"
		print "=============================="
		shutil.copy2(src_file, dest_file)
	sys.exit(-1)

except KeyboardInterrupt:
	print '~ ...'

    sys.exit(0)

玩蛇网原创,转载请注明文章出处和来源网址:http://www.iplaypython.com/code/other/o2466.html



微信公众号搜索"玩蛇网Python之家"加关注,每日最新的Python资讯、图文视频教程可以让你一手全掌握。强烈推荐关注!

微信扫描下图可直接关注

玩蛇网Python新手QQ群,欢迎加入: ① 240764603 玩蛇网Python新手群
文章发布日期:2016-04-07 15:09 玩蛇网 www.iplaypython.com

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
相关文章推荐
别人正在看
特别推荐
去顶部去底部