egret version tool

# -*- coding: UTF8 -*-
#版本控制文件生成 
import time
import datetime
import os
import tkinter as tk
from tkinter import filedialog
import json
#獲取文件的大小,結果保留兩位小數,單位爲MB'''
def get_FileSize(filePath):
	filePath = str(filePath)
	fsize = os.path.getsize(filePath)
	fsize = fsize / float(1024*1024)
	return round(fsize,2)
#獲取文件的訪問時間
def get_FileAccessTime(filePath):
	filePath = str(filePath)
	t = os.path.getatime(filePath)
	return TimeStampToTime(t)	
#獲取文件的創建時間	
def get_FileCreateTime(filePath):
	filePath = str(filePath)
	t = os.path.getctime(filePath)
	return TimeStampToTime(t)	
#把時間戳轉化爲時間: 1479264792 to 2016-11-16 10:53:12	
def TimeStampToTime(timestamp):
	timeSturct = time.localtime(timestamp)
	return time.strftime('%Y-%m-%d %H:%M:%S',timeSturct)
#獲取文件的修改時間
def get_FileModifyTime(filePath):
	filePath = str(filePath)
	t = os.path.getmtime(filePath)
	return str(t)
root = tk.Tk()
root.withdraw()
#filepath = filedialog.askopenfilenames(title)
#打開對話框,選擇文件夾
folderpath = filedialog.askdirectory()
print(folderpath) 
path = folderpath
g=os.walk(path)
#獲取所有資源的當前最新修改時間
conDict={}	
#f = path+"./resourceversion.txt"
#print(path)
#file = open(f,'w')
for path,dir_list,file_list in g:
	for file_name in file_list:
		newpath = os.path.join(path,file_name).split('resource\\')[1].replace("\\","/")
		#過濾文件
		if(newpath.endswith('.png')|newpath.endswith('.jpg')|newpath.endswith('.fnt')):
			newFileName = file_name.replace(".","_")	
			info = newpath +","+get_FileModifyTime(os.path.join(path,file_name)).replace(".","")+";"
			conDict[newFileName] = get_FileModifyTime(os.path.join(path,file_name)).replace(".","")
			print(info)
			#file.write(info+"\n")		
	#for dir_name in dir_list:
		#print("文件夾"+os.path.join(path,dir_name))
#file.close()	
print("=================")	
#寫入default.res.json文件
defResJson = folderpath+"./default.res.json"	
resJsonFile = open(defResJson,"r+")
#print(resJsonFile.read())
resJson = json.load(resJsonFile)
for dict in resJson["resources"]:
	print(dict["name"])
	if(dict["name"] in conDict):
		newUrl = dict["url"]	
		if("?v=" in newUrl):
			newUrls = newUrl.split("?v=")
			print("newUrls:"+newUrls[0])
			#更新版本號
			dict["url"] = newUrls[0]+"?v="+conDict[dict["name"]]
		else:
    		#第一次添加版本號	
			dict["url"] = dict["url"]+"?v="+conDict[dict["url"]]
			print("firstV:"+dict["url"])
	
for dict in resJson["resources"]:
	print(dict["url"])
#轉成json字符串,並且格式化換行	
txt = json.dumps(resJson,indent=4)
#清空文本
resJsonFile.seek(0)
resJsonFile.truncate()
#寫入json
resJsonFile.write(txt)
resJsonFile.close()		

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章