1
- import os , sys , time , shutil , math , zipfile , json , pathlib , webbrowser
1
+ import os , sys , time , shutil , math , json , pathlib , webbrowser
2
2
from pathlib import Path
3
3
from jsoncomment import JsonComment
4
4
from playsound import playsound
5
5
6
6
from Python import shared_globals as cfg
7
7
from Python import regex_rules
8
- from Python . zips import create_zips
8
+ from Python import zips as zips_py
9
9
from Python import update_progress
10
10
11
11
@@ -59,61 +59,53 @@ def check_github_button_clicked_and_exit(clicked_github_button):
59
59
def convert ():
60
60
global output_folder , warnings
61
61
62
+ print ("" ) # Only prints a newline.
63
+
62
64
time_start = time .time ()
63
65
64
66
input_folder_path = cfg .sg .user_settings_get_entry ("input_folder" )
65
- true_input_folder_path = os .path .join (input_folder_path , os .pardir ) # TODO: Better variable name.
66
67
67
- unzip (input_folder_path )
68
+ zips_py . unzip (input_folder_path )
68
69
69
70
update_progress .set_max_progress (input_folder_path )
70
71
71
72
for input_subfolder_path , input_subfolders , input_subfiles in os .walk (input_folder_path ):
72
- mod_subfolder = get_mod_subfolder (input_folder_path , input_subfolder_path , true_input_folder_path )
73
+ mod_subfolder = get_mod_subfolder (input_folder_path , input_subfolder_path )
73
74
74
75
mod_subfolder_parts = pathlib .Path (mod_subfolder ).parts
76
+
75
77
if len (mod_subfolder_parts ) > 0 and mod_subfolder_parts [0 ].endswith (".rte" ):
76
- output_subfolder = os .path .join (output_folder , mod_subfolder )
77
78
try_print_mod_name (mod_subfolder_parts , mod_subfolder )
79
+ output_subfolder = os .path .join (output_folder , mod_subfolder )
78
80
create_folder (input_subfolder_path , output_subfolder )
79
81
process_files (input_subfiles , input_subfolder_path , output_subfolder , input_folder_path )
80
82
81
83
if cfg .sg .user_settings_get_entry ("output_zips" ):
82
- create_zips (input_folder_path , output_folder )
84
+ zips_py . create_zips (input_folder_path , output_folder )
83
85
84
86
if len (warnings ) > 0 :
85
87
warnings_popup ()
86
88
87
- update_progress .progress = 0
88
- update_progress .total_progress = 0
89
89
warnings = []
90
90
91
+ update_progress .increment_progress () # TODO: This is a temporary solution for zipping not being accounted in the progress.
92
+
91
93
elapsed = math .floor (time .time () - time_start )
92
94
if cfg .sg .user_settings_get_entry ("play_finish_sound" ):
93
95
playsound (resource_path ("Media/finish.wav" ), block = False )
94
96
print ("Finished in {} {}" .format (elapsed , pluralize ("second" , elapsed )))
95
97
96
98
97
- def unzip (input_folder_path ):
98
- for f in os .listdir (input_folder_path ):
99
- zip_path = os .path .join (input_folder_path , f )
100
- if zipfile .is_zipfile (zip_path ):
101
- with zipfile .ZipFile (zip_path ) as item :
102
- item .extractall (input_folder_path )
103
- os .remove (zip_path )
104
-
105
-
106
- def get_mod_subfolder (input_folder_path , input_subfolder_path , true_input_folder_path ):
99
+ def get_mod_subfolder (input_folder_path , input_subfolder_path ):
107
100
if input_folder_path .endswith (".rte" ):
108
- return os .path .relpath (input_subfolder_path , true_input_folder_path )
101
+ return os .path .relpath (input_subfolder_path , os . path . join ( input_folder_path , os . pardir ) )
109
102
else :
110
103
return os .path .relpath (input_subfolder_path , input_folder_path )
111
104
112
105
113
106
def try_print_mod_name (mod_subfolder_parts , mod_subfolder ):
114
107
if len (mod_subfolder_parts ) == 1 :
115
108
print ("Converting '{}'" .format (mod_subfolder ))
116
- update_progress .increment_progress ()
117
109
118
110
119
111
def create_folder (input_subfolder_path , output_subfolder ):
@@ -138,6 +130,7 @@ def process_files(input_subfiles, input_subfolder_path, output_subfolder, input_
138
130
else :
139
131
shutil .copyfile (input_file_path , output_file_path )
140
132
133
+ update_progress .increment_progress ()
141
134
142
135
def create_converted_file (input_file_path , output_file_path , input_folder_path ):
143
136
# try: # TODO: Figure out why this try/except is necessary and why it doesn't check for an error type.
@@ -155,7 +148,6 @@ def create_converted_file(input_file_path, output_file_path, input_folder_path):
155
148
156
149
for old_str , new_str in warning_rules .items ():
157
150
if old_str in line :
158
- print (old_str , new_str )
159
151
warnings .append ("'{}' line {}: {} -> {}" .format (file_path , line_number , old_str , new_str ))
160
152
161
153
all_lines_list .append (line )
0 commit comments