-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
03001_谢丽妍_期中作业第一版 #13
Open
xly0805
wants to merge
5
commits into
TDChina:dev
Choose a base branch
from
xly0805:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# coding=utf-8 | ||
import os | ||
import pprint | ||
import shutil | ||
import time | ||
import json | ||
|
||
|
||
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 = {} | ||
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): | ||
""" | ||
check if the dir exists and create it | ||
:param directory: | ||
:return: | ||
""" | ||
if not os.path.exists(directory): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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) | ||
return file_time_str | ||
|
||
|
||
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] | ||
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 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 | ||
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(): | ||
""" | ||
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' | ||
show_name = show_dir.rpartition('\\')[-1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. show_name = os.path.basename(show_dir) |
||
|
||
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() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要使用 a,b,c 作为变量名称
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for path, dirs, files in os.walk