Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 文件夹说明
参考案例
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions log/asscet_log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"asscet_name": [{"time": "", "episode": "", "asscet_typ": ""}], "Gitar": [{"time": "20191001", "episode": "Ep00", "asscet_typ": "pro"}], "Sword": [{"time": "20191001", "episode": "Ep00", "asscet_typ": "pro"}], "Frank": [{"time": "20191001", "episode": "EP01", "asscet_typ": "cha"}], "Timer": [{"time": "20191001", "episode": "EP01", "asscet_typ": "pro"}], "Jungle": [{"time": "20191001", "episode": "EP05", "asscet_typ": "env"}], "Arrow": [{"time": "20191025", "episode": "ep03", "asscet_typ": "pro"}, {"time": "20191028", "episode": "ep03", "asscet_typ": "pro"}]}
1 change: 1 addition & 0 deletions log/receive_log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"time": {"episode": ["asscet_name"]}, "20191001": {"Ep00": ["Ep00_Gitar_pro.ma", "Ep00_sword_pro.ma"], "EP01": ["EP01_frank_cha.ma", "EP01_Timer_pro.ma"], "EP05": ["EP05_jungle_env.ma"]}, "20191025": {"ep03": ["ep03_arrow_pro.ma"]}, "20191028": {"ep03": ["ep03_arrow_pro.ma"]}}
118 changes: 118 additions & 0 deletions script/TDS_file_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*-
# .@FileName:TDS_file_class
# @Date....:2019-10-17 23:43
# ..:XingLian
"""
对象属性:接收路径,项目路径,log路径
对象方法:查看接收的文件,记录log,转存到项目路径,备份文件
"""
import json
import os
import re
import shutil

from script.find_file import get_files_list_fun


class FileOI:
def __init__(self):
self.input_path = r'Z:\example\project\Inbox'
self.object_path = r'Z:\Project\TDC\Asset'
self.log_path = r'Z:\log'

def find_asscet(self, data):
re_str = r'ep\d{2}_[a-z]+_(?:env|cha|pro)\.ma'
file_list = [i for i in get_files_list_fun(rf'{self.input_path}\{data}') if re.search(re_str, i, re.I)]
return file_list

def filename_to_list(self, file_name):
*_, data, _, _, episode, asscet, asscet_typ, _ = re.split(r'/|_|(?:\.ma$)', file_name)
asscet = 'Prop' if asscet == 'pro' else asscet.title()
return data, episode, asscet, asscet_typ

def creat_log(self, log_typ=1):
if log_typ == 1:
log_name = 'asscet'
else:
log_name = 'receive'
log_json = rf'{self.log_path}\{log_name}_log.json'
if os.path.exists(log_json):
with open(log_json, 'r') as f:
log_dict = json.load(f)
else:
f = open(log_json, 'w')
f.close()
asscet_dic = {'asscet_name': [{'time': '', 'episode': '', 'asscet_typ': ''}]}
log_dic = {'time': {'episode': ['asscet_name']}}
log_dict = asscet_dic if log_name == 'asscet' else log_dic
with open(log_json, 'w') as f:
json.dump(log_dict, f)
return log_dict

def creat_asscet_log(self,file_name):
data, episode, asscet, asscet_typ = self.filename_to_list(file_name)
log_json = rf'{self.log_path}\asscet_log.json'
log_dict = self.creat_log()
if not log_dict.get(asscet, False):
log_dict[asscet] = [{'time': data, 'episode': episode, 'asscet_typ': asscet_typ}]
else:
log_dict[asscet].append({'time': data, 'episode': episode, 'asscet_typ': asscet_typ})
with open(log_json, 'w') as f:
json.dump(log_dict, f)

def creat_time_log(self, file_name):
data, episode, asscet, asscet_typ = self.filename_to_list(file_name)
log_json = rf'{self.log_path}\receive_log.json'
log_dict = self.creat_log(0)

if not log_dict.get(data, False):
log_dict[data] = {episode: [file_name.split('/')[-1]]}
else:
if not log_dict[data].get(episode, False):
log_dict[data][episode] = [file_name.split('/')[-1]]
else:
log_dict[data][episode].append(file_name.split('/')[-1])
with open(log_json, 'w') as f:
json.dump(log_dict, f)

def copy_file(self, file_name):
data, episode, asscet, asscet_typ = self.filename_to_list(file_name)
log_json = rf'{self.log_path}\asscet_log.json'
with open(log_json, 'r') as f:
log_dict = json.load(f)

asscet_list = log_dict[asscet]
if len(asscet_list) == 1:
if not os.path.exists(rf'{self.object_path}\{asscet_typ}\{asscet}'):
os.makedirs(rf'{self.object_path}\{asscet_typ}\{asscet}\backup')
shutil.copyfile(file_name, rf'{self.object_path}\{asscet_typ}\{asscet}\{asscet}.ma')
else:
backup_file = asscet_list[-2]
data_o, episode_o, asscet_typ_o = backup_file
back_dir = rf'v{len(asscet_list)-2:0>3}_{data_o}'
os.makedirs(rf'{self.object_path}\{asscet_typ}\{asscet}\backup\{back_dir}')
os.rename(rf'{self.object_path}\{asscet_typ}\{asscet}\{asscet}.ma',
rf'{self.object_path}\{asscet_typ}\{asscet}\backup\{back_dir}\{episode_o}_{asscet}_{asscet_typ_o}.ma')
shutil.copyfile(file_name, rf'{self.object_path}\{asscet_typ}\{asscet}\{asscet}.ma')


if __name__ == '__main__':
foo = FileOI()
foo.input_path = r'Z:\example\project\Inbox'
foo.log_path = r'Z:\log'
foo.object_path = r'Z:\Project\TDC\Asset'
receive_json = rf'{foo.log_path}\receive_log.json'
if os.path.exists(receive_json):
os.remove(receive_json)
asscet_json = rf'{foo.log_path}\asscet_log.json'
if os.path.exists(asscet_json):
os.remove(asscet_json)
data = os.listdir(foo.input_path)
for i in data:
file_list = foo.find_asscet(i)
print(rf'{i} 共接收了{len(file_list)}个文件')
for file_name in file_list:
print(file_name.split('/')[-1])
foo.creat_asscet_log(file_name)
foo.creat_time_log(file_name)
foo. copy_file(file_name)
4 changes: 4 additions & 0 deletions script/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# .@FileName:__init__
# @Date....:2019-10-04 10:37
# ..:XingLian
81 changes: 81 additions & 0 deletions script/ara_asscet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# -*- coding: gbk -*-
# .@FileName:shot_num_list
# @Date....:2019-08-20 10:06
# ..:XingLian
# ��������ʲ�

import os
import re
import time
import shutil
import _winreg
import json


a = '''
'''.split()

def get_desktop():
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders')
return _winreg.QueryValueEx(key, "Desktop")[0]


asspath = {'chr': ['cfx', 'rig', 'srf', 'mod'], 'prp': ['rig', 'srf', 'mod'],
'env': ['mod', 'srf'], 'veh': ['rig', 'srf', 'mod']}
fold = {'rig': 'rigging', 'srf': 'surface', 'mod': 'model'}
desk = get_desktop()


f = open(r'C:\Users\zhangying.BUXI\Desktop\version.json', 'w')
for asstyp in asspath: # ���α���chr��prp���ʲ�
allname = os.listdir('I:\\bproject\\wts\\publish\\asset\\{}'.format(asstyp))
ass_typ_dic = {}
for name in allname: # tohr
name_verse = {}
typDic = {}
for loctyp in asspath[asstyp]: # ���α���ÿ���ʲ��Ļ���
verlist = []
if loctyp == 'cfx':
versepath = 'I:\\bproject\\wts\\publish\\asset\\{}\\{}\\{}'.format(asstyp, name, loctyp)
# versepath
if os.path.exists(versepath):
verselist = os.listdir(versepath)
verselist_hair = []
verselist_cloth = []
verselist_cfx = []

for each in verselist:
findhair = re.findall('{}.cfx.hair.v\d{{3}}$'.format(name), each)
# findhair
if findhair:
verselist_hair.append(findhair[0])
findcloth = re.findall('{}.cfx.cloth.v\d{{3}}$'.format(name), each)
if findcloth:
verselist_cloth.append(findcloth[0])
verselist_hair.sort(key=lambda x: x[-3:])
verselist_cloth.sort(key=lambda x: x[-3:])
if verselist_hair :
verselist_cfx.append(verselist_hair[-1])
if verselist_cloth:
verselist_cfx.append(verselist_cloth[-1])
if verselist_cfx:
verlist.append(verselist_cfx)

else:
versepath = 'I:\\bproject\\wts\\publish\\asset\\{0}\\{1}\\{2}'.format(asstyp, name, loctyp,
fold[loctyp])
if os.path.exists(versepath):
verselist = os.listdir(versepath)
for each in verselist:
verlists = re.findall('{}.{}.{}.v\d{{3}}'.format(name, loctyp, fold[loctyp]), each)
if verlists:
verlist.append(verlists[0])

verlist.sort(key=lambda x: x[-3:])
if verlist:
typDic[loctyp] = verlist[-1]
name_verse[name] = typDic
ass_typ_dic[asstyp] = name_verse
json.dump(ass_typ_dic,f,ensure_ascii=False)
f.write('\n')
95 changes: 95 additions & 0 deletions script/creat_input_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*-
# .@FileName:creat_input_log
# @Date....:2019-10-04 07:28
# ..:XingLian
# import datetime
"""
创建两个json文件记录资产信息,
一个以资产名称为索引,记录版本信息,
一个以文件接收日期为索引,记录当天接收文件的内容
为了查找文件两种检索方式都不需要以遍历所有资产的方式进行


import json
import os
import re


# 接收日期文件夹,接收文件存放绝对路径,log路径
def record_input_log(data, ipath, log_path):
# 判断asscet_log是否存在
# 如果存在,读取内容,如果不存在,创建一个
asscet_json = rf'{log_path}\asscet_log.json'
if os.path.exists(asscet_json):
with open(asscet_json, 'r') as f:
assect_dict = json.load(f)
else:
f = open(asscet_json, 'w')
f.close()
assect_dict = {'asscet_name': [{'time': '', 'episode': '', 'asscet_typ': ''}]}

# 判断receive_log是否存在
# 如果存在,读取内容,如果不存在,创建一个
receive_json = rf'{log_path}\receive_log.json'
if os.path.exists(receive_json):
with open(receive_json, 'r') as f:
time_dict = json.load(f)
else:
f = open(receive_json, 'w')
f.close()
# 字典格式
time_dict = {'time': {'episode': ['asscet_name']}}

# 依次向下遍历,获取资产名称
episode_list = os.listdir(rf'{ipath}\{data}')
for episode in episode_list:
asscet_list = os.listdir(rf'{ipath}\{data}\{episode}')
for asscet_dir in asscet_list:
print(rf'{ipath}\{data}\{episode}\{asscet_dir}')
asscet_name = os.listdir(rf'{ipath}\{data}\{episode}\{asscet_dir}')[0]

# 正则匹配,防止有多余垃圾文件
file_name = re.search(r'ep\d{2}_[a-z]+_(?:env|cha|pro)\.ma', asscet_name, re.I).group()
# 切割资产名称,获取资产版本信息存储到列表
episode, asscet, asscet_typ, _ = re.split(r'_|.ma', file_name)
asscet = asscet.title()
# 更新time_dict,将获得的资产放在对应集数下的list
time_dict.setdefault(data, {episode: []})
# print(time_dict)
# time_dict[data][episode].append(file_name)
# 更新assect_dict,判断版本
if not assect_dict.get(asscet, False):
# 如果资产不存在,增加键值对,将资产复制到对应的项目目录中
assect_dict[asscet] = [{'time': data, 'episode': episode, 'asscet_typ': asscet_typ}]
os.makedirs(rf'Z:\Project\TDC\Asset\{asscet_typ}\{asscet}\backup')
os.rename(rf'{ipath}\{data}\{episode}\{asscet_dir}\{file_name}',
rf'Z:\Project\TDC\Asset\{asscet_typ}\{asscet}\{asscet}.ma')
else:
# 如果资产不存在,增加版本,将资产升版本,并备份旧版本
backup_file = assect_dict[asscet][-1]
assect_dict[asscet].append({'time': data, 'episode': episode, 'asscet_typ': asscet_typ})
os.makedirs(rf'Z:\Project\TDC\Asset\{asscet_typ}\{asscet}\backup\data')
os.rename(rf'Z:\Project\TDC\Asset\{asscet_typ}\{asscet}\{asscet}.ma',
rf'Z:\Project\TDC\Asset\{asscet_typ}\{asscet}\backup\{asscet}.ma')
os.rename(rf'{ipath}\{data}\{episode}\{asscet_dir}\{file_name}',
rf'Z:\Project\TDC\Asset\{asscet_typ}\{asscet}\{asscet}.ma')
# 将新的字典写入json中
with open(asscet_json, 'w') as f:
json.dump(assect_dict, f)
with open(receive_json, 'w') as f:
json.dump(time_dict, f)


if __name__ == '__main__':

ipath = r'Z:\example\project\Inbox'
log_path = r'Z:\log'
receive_json = rf'{log_path}\receive_log.json'
if os.path.exists(receive_json):
os.remove(receive_json)
asscet_json = rf'{log_path}\asscet_log.json'
if os.path.exists(asscet_json):
os.remove(asscet_json)
data = os.listdir(ipath)

"""
28 changes: 28 additions & 0 deletions script/file_zip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# coding: gbk
import os
import winreg

# ��winrar���뻷������
oldenv = os.getenv('path')
os.environ['path'] = '{};Z:\Program Files\WinRAR'.format(oldenv)


# ��ȡ����·��
def get_desktop():
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders')
return winreg.QueryValueEx(key, "Desktop")[0]


# ѹ���ļ�
def zip_file(opath, filename, *ipath):
rar_command = "WinRAR a {0} {1}".format(r'{}\{}.rar'.format(opath, filename), *ipath)
print(rar_command)
if os.system(rar_command) == 0:
print("{} rar �ɹ�".format(filename))
else:
print("{} rar ʧ��".format(filename))




28 changes: 28 additions & 0 deletions script/find_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# .@FileName:get_files_list
# @Date....:2019-10-04 10:52
# ..:XingLian
import os


def get_files_list_fun(file_dir, mode='files'):
files_full_path = []
folders_full_path = []
if os.path.isfile(file_dir):
if mode in ['files']:
files_full_path.append(file_dir.replace('\\', '/'))
return files_full_path
return []
for root, dirs, files in os.walk(file_dir):
# print(root) # 当前目录路径
# print(dirs) # 当前路径下所有子目录
# print(files) # 当前路径下所有非目录子文件
folders_full_path.extend([(root + '\\' + fl).replace('\\', '/') for fl in dirs])
files_full_path.extend([(root + '\\' + f).replace('\\', '/') for f in files])
if mode in ['files']:
return files_full_path
if mode in ['folders']:
return folders_full_path
else:
return files_full_path + folders_full_path

13 changes: 13 additions & 0 deletions script/hash_match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# coding=utf-8
# 导入hashlib模块
import hashlib

def get_hash(file_path, bytes=1024):
# 创建一个md5算法对象
md5_1 = hashlib.md5()
with open(file_path, 'rb') as f:
# 更新文本
md5_1.update(f.read())
# 获取这个文件的MD5值
ret = md5_1.hexdigest()
return ret