26
26
"""
27
27
28
28
import os
29
+ import shutil
29
30
from classes import info
30
31
from classes .logger import log
31
32
@@ -37,17 +38,31 @@ def get_assets_path(file_path=None, create_paths=True):
37
38
return info .USER_PATH
38
39
39
40
try :
40
- # Generate asset folder name, max 30 chars of filename + "_assets"
41
+ # Generate asset folder name filename + "_assets"
41
42
file_path = file_path
42
43
asset_filename = os .path .splitext (os .path .basename (file_path ))[0 ]
43
- asset_folder_name = asset_filename [:30 ] + "_assets"
44
+ asset_folder_name = asset_filename [:248 ] + "_assets" #Windows max name size is 255. 248 = 255 - len("_assets")
44
45
asset_path = os .path .join (os .path .dirname (file_path ), asset_folder_name )
45
46
47
+ # Previous Assets File Name Convention.
48
+ # We can remove the 30_char variables after 05/27/2022
49
+ asset_folder_name_30_char = asset_filename [:30 ] + "_assets"
50
+ asset_path_30_char = os .path .join (os .path .dirname (file_path ), asset_folder_name_30_char )
51
+
46
52
# Create asset folder, if necessary
47
53
if create_paths :
48
54
if not os .path .exists (asset_path ):
49
- os .mkdir (asset_path )
50
- log .info ("Asset dir created as {}" .format (asset_path ))
55
+ if os .path .exists (asset_path_30_char ):
56
+ #copy assets folder, if it follows the previous naming convention
57
+ #must leave a copy for possible projects that shared the folder.
58
+ try :
59
+ shutil .copytree (asset_path_30_char , asset_path )
60
+ log .info ("Copying shortened asset folder. {}" .format (asset_path ))
61
+ except :
62
+ log .error ("Could not make a copy of assets folder" )
63
+ else :
64
+ os .mkdir (asset_path )
65
+ log .info ("Asset dir created as {}" .format (asset_path ))
51
66
else :
52
67
log .info ("Using existing asset folder {}" .format (asset_path ))
53
68
0 commit comments