From 117f0345c8d1c7bd42de346e649ff0fbca0e66e2 Mon Sep 17 00:00:00 2001 From: xiely Date: Sun, 27 Oct 2019 11:25:57 +0800 Subject: [PATCH 1/5] add a new file --- core/Asset_IO_tool.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 core/Asset_IO_tool.py diff --git a/core/Asset_IO_tool.py b/core/Asset_IO_tool.py new file mode 100644 index 0000000..1a3d864 --- /dev/null +++ b/core/Asset_IO_tool.py @@ -0,0 +1,18 @@ +# coding=utf-8 +import os +asset_types = {'pro': 'Pro', + 'cha': 'Cha', + 'env': 'Env'} +asset_names = {} +input_dir = r'C:\Users\geyij\Desktop\new\AssetIO\example\project\Inbox\20191001' +# TODO 改成input"请选择客户文件路径>>>>>>>>>>" +show_dir = r'C:\Users\geyij\Desktop\new\AssetIO\example\project\TDC' +# TODO 改成input "请选择项目路径>>>>>>>>>>>" +show_name = show_dir.rpartition('\\')[-1] + +for a, b, c in os.walk(input_dir): + if c[0].endswith('.ma'): + print(a) + print(b) + print(c) + From 3448f1a75557f12fec4c1f4a67ac7d625b3feb69 Mon Sep 17 00:00:00 2001 From: xiely Date: Wed, 30 Oct 2019 10:54:17 +0800 Subject: [PATCH 2/5] finished copy file part, todo: output --- core/Asset_IO_tool.py | 103 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 15 deletions(-) diff --git a/core/Asset_IO_tool.py b/core/Asset_IO_tool.py index 1a3d864..d930570 100644 --- a/core/Asset_IO_tool.py +++ b/core/Asset_IO_tool.py @@ -1,18 +1,91 @@ # coding=utf-8 import os -asset_types = {'pro': 'Pro', - 'cha': 'Cha', - 'env': 'Env'} -asset_names = {} -input_dir = r'C:\Users\geyij\Desktop\new\AssetIO\example\project\Inbox\20191001' -# TODO 改成input"请选择客户文件路径>>>>>>>>>>" -show_dir = r'C:\Users\geyij\Desktop\new\AssetIO\example\project\TDC' -# TODO 改成input "请选择项目路径>>>>>>>>>>>" -show_name = show_dir.rpartition('\\')[-1] - -for a, b, c in os.walk(input_dir): - if c[0].endswith('.ma'): - print(a) - print(b) - print(c) +import pprint +import shutil +import time +import json + + +def get_input_data(): + input_dir = input("请选择客户文件路径>>>>>>>>>>") + # r'C:\Users\geyij\Desktop\new\AssetIO\example\project\Inbox\20191001' + input_data = {} + for a, b, c in os.walk(input_dir): + if c: + if c[0].endswith('.ma'): + i, j, k = c[0].split('.')[0].split('_') + file_info = { + 'input_file_name': c[0], + 'input_file_path': a, + 'asset_name': j.lower(), + 'asset_type': k.lower(), + 'seq': i.upper() + } + input_data[file_info['asset_name']] = file_info + return input_data, input_dir + + +def create_directory(directory): + if not os.path.exists(directory): + os.makedirs(directory) + + +def get_file_time(directory): + file_time_sec = os.path.getctime(directory) + file_time_struct = time.localtime(file_time_sec) + file_time_str = time.strftime('%Y-%m-%d-%H-%M-%S', file_time_struct) + return file_time_str + + +def bak_file(directory): + file_directory = directory + file_path = os.path.split(file_directory)[0] + file_name = os.path.split(file_directory)[1] + file_time = get_file_time(file_directory) + bak_path = os.path.join(file_path, 'bak', file_time) + create_directory(bak_path) + bak_name = os.path.splitext(file_name)[0] + '_' + file_time + os.path.splitext(file_name)[1] + bak_file_directory = os.path.join(bak_path, bak_name) + os.rename(file_directory, bak_file_directory) + + +def save_data_file(data, name, directory): + save_data = data + save_name = name + '.json' + save_path = directory + save_file = os.path.join(save_path, save_name) + with open(save_file, 'w+') as f: + json.dump(save_data, f) + return save_file + + +def copy_input_files(): + assets_data, input_dir = get_input_data() + show_dir = input("请选择项目路径>>>>>>>>>>>") + # r'C:\Users\geyij\Desktop\new\AssetIO\example\project\TDC' + show_name = show_dir.rpartition('\\')[-1] + + input_dir_time = get_file_time(input_dir) + data_file_name = 'Input_Data_' + input_dir_time + + for asset, info in assets_data.items(): + asset_name = info['asset_name'].capitalize() + asset_type = info['asset_type'].capitalize() + save_name = f'{show_name}_{asset_name}_{asset_type}.ma' + save_path = os.path.join(show_dir, 'Asset', asset_type, asset_name) + save_file = os.path.join(save_path, save_name) + create_directory(save_path) + if os.path.exists(save_file): + bak_file(save_file) + input_file = os.path.join(assets_data[asset]['input_file_path'], assets_data[asset]['input_file_name']) + shutil.copy(input_file, save_file) + assets_data[asset]['saved_file_name'] = save_name + assets_data[asset]['saved_file_path'] = save_path + + saved_data_file = save_data_file(assets_data, data_file_name, input_dir) + + return assets_data, saved_data_file + + +copy_input_files() From 201aed32fc7a41df170795a705704140a8fbce56 Mon Sep 17 00:00:00 2001 From: xiely Date: Wed, 30 Oct 2019 13:20:09 +0800 Subject: [PATCH 3/5] adding output part --- core/Asset_IO_tool.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/Asset_IO_tool.py b/core/Asset_IO_tool.py index d930570..f7163d1 100644 --- a/core/Asset_IO_tool.py +++ b/core/Asset_IO_tool.py @@ -87,5 +87,6 @@ def copy_input_files(): return assets_data, saved_data_file -copy_input_files() +output_assets_str = 'victor' +print(output_assets_str) From b85f23b2cb37d8009cdddb75ba360b4518ea1548 Mon Sep 17 00:00:00 2001 From: xiely Date: Wed, 30 Oct 2019 14:02:55 +0800 Subject: [PATCH 4/5] Revert "adding output part" This reverts commit 201aed32fc7a41df170795a705704140a8fbce56. --- core/Asset_IO_tool.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/Asset_IO_tool.py b/core/Asset_IO_tool.py index f7163d1..d930570 100644 --- a/core/Asset_IO_tool.py +++ b/core/Asset_IO_tool.py @@ -87,6 +87,5 @@ def copy_input_files(): return assets_data, saved_data_file -output_assets_str = 'victor' -print(output_assets_str) +copy_input_files() From 00b86928fb0cc67be9408b6e32c4875367852809 Mon Sep 17 00:00:00 2001 From: xiely Date: Wed, 30 Oct 2019 14:58:17 +0800 Subject: [PATCH 5/5] added func doc --- core/Asset_IO_tool.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/core/Asset_IO_tool.py b/core/Asset_IO_tool.py index d930570..d732c51 100644 --- a/core/Asset_IO_tool.py +++ b/core/Asset_IO_tool.py @@ -7,6 +7,10 @@ def get_input_data(): + """ + get input directory and get all the maya files info + :return: maya files data and input directory + """ input_dir = input("请选择客户文件路径>>>>>>>>>>") # r'C:\Users\geyij\Desktop\new\AssetIO\example\project\Inbox\20191001' input_data = {} @@ -26,11 +30,21 @@ def get_input_data(): def create_directory(directory): + """ + check if the dir exists and create it + :param directory: + :return: + """ if not os.path.exists(directory): os.makedirs(directory) def get_file_time(directory): + """ + get the create time of file or folder + :param directory: + :return: create_time + """ file_time_sec = os.path.getctime(directory) file_time_struct = time.localtime(file_time_sec) file_time_str = time.strftime('%Y-%m-%d-%H-%M-%S', file_time_struct) @@ -38,6 +52,12 @@ def get_file_time(directory): def bak_file(directory): + """ + get a full path file and create a bak folder with file create time + then bak file + :param directory: + :return: + """ file_directory = directory file_path = os.path.split(file_directory)[0] file_name = os.path.split(file_directory)[1] @@ -50,6 +70,13 @@ def bak_file(directory): def save_data_file(data, name, directory): + """ + save given date with given name in given dir + :param data: dic data + :param name: date file name + :param directory: target dir + :return: saved file full path + """ save_data = data save_name = name + '.json' save_path = directory @@ -60,6 +87,14 @@ def save_data_file(data, name, directory): def copy_input_files(): + """ + get a show path + get input data from input dir + save client files to right dir + update assets data + and save data to a json file + :return: asset data dic and data file path + """ assets_data, input_dir = get_input_data() show_dir = input("请选择项目路径>>>>>>>>>>>") # r'C:\Users\geyij\Desktop\new\AssetIO\example\project\TDC'