成都网站建设设计

将想法与焦点和您一起共享

python更新游戏程序

#!/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()

网站栏目:python更新游戏程序
当前路径:http://chengdu.cdxwcx.cn/article/jpchoe.html