#!/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()
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。