Python小试

以下是一个简单工具,操作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 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值