#!/usr/bin/python
# Filename: generate_skqs2any.py
import sys
import os
def gen_file(in_file, out_file, bookname):
in_f = file(in_file)
out_f= file(out_file, ‘w‘)
src = in_f.read()
out_f.write(src.replace(‘bencaogangmu‘, bookname))
in_f.close()
out_f.close()
def gen_dir( src_path, dst_path, bookname ):
#print ‘gen_dir(‘+src_path+‘,‘+dst_path+‘,‘+bookname+‘)‘
if not os.path.exists( src_path ):
return
print ‘ ...processing ‘+dst_path
if os.path.isdir( src_path ):
if not os.path.exists( dst_path ):
os.mkdir(dst_path)
for t_file in os.listdir(src_path):
gen_dir( os.path.join(src_path, t_file), os.path.join(dst_path, t_file), bookname )
elif os.path.isfile( src_path ):
gen_file(src_path, dst_path, bookname)
def print_help():
print ‘‘‘\
This program generate another skqs project from an existed skqs project.
Options include:
generate_skqs2any.py --version : Prints the version number
generate_skqs2any.py --help : Display this help
generate_skqs2any.py bookname [template_prj_path]: ‘‘‘
if len(sys.argv) < 2:
print ‘No action specified.‘
print_help()
sys.exit()
if sys.argv[1].startswith(‘--‘):
option = sys.argv[1][2:]
# fetch sys.argv[1] but without the first two characters
if option == ‘version‘:
print ‘Version 0.92‘
elif option == ‘help‘:
print_help()
else:
print ‘Unknown option.‘
print_help()
sys.exit()
elif sys.argv[1].startswith(‘-‘):
option = sys.argv[1][1:]
# fetch sys.argv[1] but without the first two characters
if option == ‘v‘:
print ‘Version 0.92‘
elif option == ‘h‘:
print_help()
else:
print ‘Unknown option.‘
print_help()
sys.exit()
else:
bookname = sys.argv[1]
print ‘ ==== bookname : ‘+bookname
if len(sys.argv) < 3:
template_prj_path = os.path.join( os.getcwd(), ‘skqs2bencaogangmu‘ )
else:
template_prj_path = sys.argv[2]
new_prj_path = os.path.join( os.getcwd(), ‘skqs2‘+bookname )
gen_dir( template_prj_path, new_prj_path, bookname )
java_src_path = new_prj_path + ‘/src/com/tonybook/skqs2bencaogangmu‘
java_dst_path = new_prj_path + ‘/src/com/tonybook/skqs2‘+bookname
if os.path.exists( java_src_path ):
os.rename( java_src_path, java_dst_path)