以下是一个简单工具,操作Windows下的文件夹,delete,svn update,move,modify
# Filename: deploy website and SMQ
# 1.delete old files 2.svn update 3.move files 4.modify configurations
import os
import re
source_dir = 'D:\\TMS\\code'
source_dir_website = 'D:\\TMS\\code\\php\\website'
source_dir_smq = 'D:\\TMS\\code\\mobile\\SMQ'
target_dir = 'C:\\wamp\\www'
target_smq_dir = 'C:\\wamp\\www\\SMQ'
delete_command = 'rd %s /s /q'%(target_dir)
mkdir_command = 'md %s '%(target_dir)
mkdir_smq_command = 'md %s '%(target_smq_dir)
svn_command = 'svn update %s'%(source_dir)
mv_website_dir = 'xcopy %s %s /s'%(source_dir_website,target_dir)
mv_smq_dir = 'xcopy %s %s /s'%(source_dir_smq,target_smq_dir)
if os.system(delete_command) == 0:
print ('delete directory', target_dir)
else:
print ('delete directory failed')
if os.system(mkdir_command) == 0:
print ('make directory', target_dir)
else:
print ('make directory failed')
if os.system(mkdir_smq_command) == 0:
print ('make directory', target_smq_dir)
else:
print ('make directory failed')
if os.system(svn_command) == 0:
print ('svn update', source_dir)
else:
print ('svn update failed')
if os.system(mv_website_dir) == 0:
print ('move ', source_dir)
else:
print ('move failed')
if os.system(mv_smq_dir) == 0:
print ('move ', source_dir_smq)
else:
print ('move failed')
config_website = 'C:\\wamp\\www\\Manage\\Conf\\config.php'
config_smq = 'C:\\wamp\\www\\SMQ\\Manage\\Conf\\config.php'
# modify website config files
f = open(config_website, "r+",encoding= 'utf-8')
config_website_bat = ""
stringread = f.readline()
while stringread:
stringread = stringread.replace('db.humanflash.com:8081','localhost:8080')
config_website_bat = config_website_bat + stringread
stringread = f.readline()
f.close()
f_temp = open(config_website, "w",encoding= 'utf-8')
f_temp.write(config_website_bat)
f_temp.close()
f = open(config_smq, "r+",encoding= 'utf-8')
#modify smq config files
config_smq_bat = ""
stringread = f.readline()
while stringread:
stringread = stringread.replace('db.humanflash.com:8081','localhost:8080')
config_smq_bat = config_smq_bat + stringread
stringread = f.readline()
f.close()
f_temp = open(config_smq, "w",encoding= 'utf-8')
f_temp.write(config_smq_bat)
f_temp.close()
# other solution: write new lines to the postion