十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
#!/usr/bin/env python
#coding:utf-8
import os
import re
import sys
import shutil
import zipfile
import datetime
time = datetime.datetime.now()
folderName = time.strftime("%Y%m%d%H%M")
dm_path = '/data/bz-tw-and/'
package_path = '/data/update/bz_new/'
after_zip = '.zip'
package_name = ''
temp = 'temp/'
def update():
num = []
for filename in os.listdir(package_path):
if filename[-4:] == after_zip:
z = zipfile.ZipFile(package_path+filename,'r')
z.extractall(package_path)
z.close
for qu_name in os.listdir(dm_path):
if re.match('s\d+',qu_name):
backup_dm = dm_path+qu_name+'/_scripts'
now_dm = dm_path+qu_name+'/scripts'
if os.path.exists(backup_dm) and os.path.exists(now_dm):
shutil.rmtree(backup_dm)
os.rename(now_dm,backup_dm)
else:
if os.path.exists(now_dm):
os.rename(now_dm,backup_dm)
shutil.copytree(package_path+ 'scripts',now_dm)
os.remove(now_dm+'/Config.lua')
shutil.copyfile(dm_path + qu_name+'/Config.lua',now_dm+'/Config.lua')
num.append(qu_name[1:])
num = list(map(int,num))
num = sorted(num)
for name in num:
print('\033[31ms%s\033[0m已经更新完成...'% name)
if not os.path.exists(package_path+temp):
os.mkdir(package_path+temp)
os.mkdir(package_path+temp+folderName)
for filename in os.listdir(package_path):
if filename != 'temp':
shutil.move(package_path +filename,package_path + temp + folderName)
update()