-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmis-cli.py
More file actions
527 lines (483 loc) · 19.4 KB
/
Copy pathmis-cli.py
File metadata and controls
527 lines (483 loc) · 19.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
import subprocess
import sys
from colorama import init, Fore, Style as ColoramaStyle
import questionary
import os
from datetime import datetime
from questionary import Style as QuestionaryStyle
from src.instance_selector import select_instance
# Check if config/config.ini exists, if not, run config_setup.py
if not os.path.exists(os.path.join("config", "config.ini")):
subprocess.run(["python", "src/config_setup.py"])
# Instance selection
current_term, _ = select_instance()
if current_term is None:
print("No instance selected. Exiting CLI.")
sys.exit(0)
BASE_DIR = os.path.join(os.getcwd(), "data", current_term)
DATA_DIR = BASE_DIR # or use subfolders as needed
MASTER_LOG = os.path.join(BASE_DIR, "mis-cli.log")
HISTORY_LOG = os.path.join(BASE_DIR, "history.log")
custom_style = QuestionaryStyle([
("pointer", "fg:#00ff00 bold"), # color/style for the pointer
])
# Reset both log files at startup
with open(MASTER_LOG, "w", encoding="utf-8") as f:
f.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Log started\n")
with open(HISTORY_LOG, "w", encoding="utf-8") as f:
f.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Log started\n")
init(autoreset=True)
def run_config_setup():
subprocess.run(["python", "src/config_setup.py"])
input("Press Enter to return to the menu...")
def show_current_instance():
print(Fore.GREEN + f"Current Instance: {current_term}" + ColoramaStyle.RESET_ALL)
def log_action(action):
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
message = f"{timestamp} - {action}\n"
with open(MASTER_LOG, "a", encoding="utf-8") as f:
f.write(message)
with open(HISTORY_LOG, "a", encoding="utf-8") as f:
f.write(message)
def get_last_action():
if not os.path.exists(MASTER_LOG):
return "No actions yet."
with open(MASTER_LOG, "r", encoding="utf-8") as f:
lines = f.readlines()
if not lines:
return "No actions yet."
return lines[-1].strip()
def show_last_action():
last = get_last_action()
print(Fore.YELLOW + f"Last Action: {last}" + ColoramaStyle.RESET_ALL)
def print_logo():
print(Fore.CYAN + ColoramaStyle.BRIGHT + r"""
__ __ ___ ____ ____ _ ___
| \/ |_ _/ ___| / ___| | |_ _|
| |\/| || |\___ \ | | | | | |
| | | || | ___) / \ |___| |___ | |
|_| |_|___|____/ \____|_____|___|
Created by: Jihoon Ahn <github: hoonywise>
Email: hoonywise@proton.me
Check for updates at https://github.com/hoonywise/mis-cli/releases
""" + ColoramaStyle.RESET_ALL)
def run_gvprmis_export_batch():
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/gvprmis_export_batch.py"], env=env)
log_action("GVPRMIS SQL Export Batch")
input("Press Enter to return to the menu...")
#def run_gvprmis_export_batch_custom():
# env = os.environ.copy()
# env["MIS_INSTANCE_PATH"] = BASE_DIR
# subprocess.run(["python", "src/gvprmis_export_batch_custom.py"], env=env)
# log_action("Raw SQL Export Batch")
# input("Press Enter to return to the menu...")
def run_gvprmis_processing():
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/gvprmis_processing.py"], env=env)
log_action("GVPRMIS.dat / SVRCAXX.dat Processing")
input("Press Enter to return to the menu...")
def run_row_replace():
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/row_replace.py"], env=env)
log_action("Replace Partial Records in DAT")
input("Press Enter to return to the menu...")
def run_error_stripper():
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/error_stripper.py"], env=env)
log_action("Strip Records in DAT")
input("Press Enter to return to the menu...")
def run_dat_file_stager():
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/dat_file_stager.py"], env=env)
log_action("Stage Final DAT to Input DAT")
input("Press Enter to return to the menu...")
def run_dat_loader():
try:
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/dat_loader.py"], env=env)
log_action("DAT Loader (Database)")
except KeyboardInterrupt:
print("\nDAT Loader interrupted by user.")
input("Press Enter to return to the menu...")
def run_error_report_loader():
try:
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/error_report_loader.py"], env=env)
log_action("Error Report Loader (Database)")
except KeyboardInterrupt:
print("\nError Report Loader interrupted by user.")
input("Press Enter to return to the menu...")
def run_sg26_sg29_loader():
try:
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/sg26_sg29_loader.py"], env=env)
log_action("SG26/SG29 Loader (Database)")
except KeyboardInterrupt:
print("\nSG26/SG29 Loader interrupted by user.")
input("Press Enter to return to the menu...")
def run_csv_loader():
try:
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/csv_loader.py"], env=env)
log_action("CSV Loader (Database)")
except KeyboardInterrupt:
print("\nCSV Loader interrupted by user.")
input("Press Enter to return to the menu...")
def run_invalid_rows():
try:
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/invalid_rows.py"], env=env)
log_action("Invalid Rows Identifier")
except KeyboardInterrupt:
print("\nInvalid Rows Identifier interrupted by user.")
input("Press Enter to return to the menu...")
def run_finalize_submission():
try:
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/finalize_sub.py"], env=env)
log_action("Copy Submission to OneDrive")
except KeyboardInterrupt:
print("\nFinalize Submission interrupted by user.")
input("Press Enter to return to the menu...")
def run_import_submission():
try:
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/import_sub.py"], env=env)
log_action("Import Submission from OneDrive")
except KeyboardInterrupt:
print("\nImport Submission interrupted by user.")
input("Press Enter to return to the menu...")
def run_open_explorer():
try:
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/open_explorer.py"], env=env)
log_action("Open Term Folder in Explorer")
except KeyboardInterrupt:
print("\nOpen Term Folder in Explorer interrupted by user.")
input("Press Enter to return to the menu...")
def run_dat_file_stager_load():
try:
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/dat_file_stager_load.py"], env=env)
log_action("DAT File Stager (Load)")
except KeyboardInterrupt:
print("\nDAT File Stager (Load) interrupted by user.")
input("Press Enter to return to the menu...")
def run_dat_file_stager_hist():
try:
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/dat_file_stager_hist.py"], env=env)
log_action("Stage History DAT to Input DAT")
except KeyboardInterrupt:
print("\nDAT File Stager (History) interrupted by user.")
input("Press Enter to return to the menu...")
def run_instance_delete():
global current_term, BASE_DIR, DATA_DIR, MASTER_LOG, HISTORY_LOG
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
subprocess.run(["python", "src/instance_delete.py"], env=env)
input("Press Enter to return to the menu...")
# Return True if the current instance folder was deleted
return not os.path.exists(BASE_DIR)
def run_si_export_sp():
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
# Prompt for term value
gi03_val = questionary.text(
"Enter gi03_val (term, e.g. 253):",
validate=lambda t: t.isdigit() and len(t) > 0
).ask()
if not gi03_val:
print("No term entered. Returning to menu.")
return
# Run the export script
subprocess.run(
["python", "src/si_export_sp.py", "SI_EXTRACT_SP.sql", f"gi03_val={gi03_val}"],
env=env
)
log_action(f"SI Extract Export for term {gi03_val}")
input("Press Enter to return to the menu...")
def run_pdis_export():
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
# Prompt for term value
gi03_val = questionary.text(
"Enter gi03_val (term, e.g. 253):",
validate=lambda t: t.isdigit() and len(t) > 0
).ask()
if not gi03_val:
print("No term entered. Returning to menu.")
return
# Run the export script
subprocess.run(
["python", "src/pdis_export.py", "PDIS_EXTRACT.sql", f"gi03_val={gi03_val}"],
env=env
)
log_action(f"PDIS Extract Export for term {gi03_val}")
input("Press Enter to return to the menu...")
def run_dat_processing():
"""Handle DAT processing with method selection"""
while True:
method_choice = questionary.select(
"Select DAT processing method:",
choices=[
"Compile (rewrite method)",
"Paste (copy/paste method)",
questionary.Separator(),
"Back to main menu"
],
pointer="→",
style=custom_style
).ask()
env = os.environ.copy()
env["MIS_INSTANCE_PATH"] = BASE_DIR
if method_choice is None or method_choice.startswith("Back to main menu"):
return
elif method_choice.startswith("Compile"):
print("Running DAT Compile...")
result = subprocess.run(["python", "src/dat_compile.py"], env=env)
log_action("Compile New DAT Set (Compile)")
input("Press Enter to return to the menu...")
if result.returncode == 2:
continue # Go back to run_dat_processing menu
elif result.returncode == 3:
break # Go back to data_editing_stripping_menu
else:
return
elif method_choice.startswith("Paste"):
print("Running DAT Paste...")
result = subprocess.run(["python", "src/dat_paste.py"], env=env)
log_action("Compile New DAT Set (Paste)")
input("Press Enter to return to the menu...")
if result.returncode == 2:
continue
elif result.returncode == 3:
break
else:
return
def data_extract_preparation_menu():
while True:
os.system('cls')
print_logo()
show_current_instance()
show_last_action()
choice = questionary.select(
"Data Extract and Preparation:",
choices=[
questionary.Separator(),
"GVPRMIS.dat / SVRCAXX.dat Processing",
"GVPRMIS SQL Export Batch",
# "Raw SQL Export Batch",
"SI Extract Export (Student ID/SSN)",
"PDIS Extract Export (Student ID/SSN)",
questionary.Separator(),
"Back to Main Menu"
],
pointer="→",
style=custom_style
).ask()
if choice is None:
continue
elif choice.startswith("Back to Main Menu"):
break
elif choice.startswith("GVPRMIS.dat / SVRCAXX.dat Processing"):
run_gvprmis_processing()
elif choice.startswith("GVPRMIS SQL Export Batch"):
run_gvprmis_export_batch()
# elif choice.startswith("Raw SQL Export Batch"):
# run_gvprmis_export_batch_custom()
elif choice.startswith("SI Extract Export"):
run_si_export_sp()
elif choice.startswith("PDIS Extract Export"):
run_pdis_export()
def data_editing_stripping_menu():
while True:
os.system('cls')
print_logo()
show_current_instance()
show_last_action()
choice = questionary.select(
"Data Editing and Stripping:",
choices=[
questionary.Separator(),
"Replace Partial Records in DAT",
"Compile New DAT Set",
"Strip Records in DAT",
"Invalid Rows Identifier",
questionary.Separator(),
"Stage Final DAT to Input DAT",
"Stage History DAT to Input DAT",
questionary.Separator(),
"Back to Main Menu"
],
pointer="→", # <-- Change the arrow here!
style=custom_style
).ask()
if choice is None:
continue
elif choice.startswith("Back to Main Menu"):
break
elif choice.startswith("Stage Final DAT to Input DAT"):
run_dat_file_stager()
elif choice.startswith("Stage History DAT to Input DAT"):
run_dat_file_stager_hist()
elif choice.startswith("Replace Partial Records in DAT"):
run_row_replace()
elif choice.startswith("Compile New DAT Set"):
run_dat_processing()
elif choice.startswith("Strip Records in DAT"):
run_error_stripper()
elif choice.startswith("Invalid Rows Identifier"):
run_invalid_rows()
def database_operations_menu():
while True:
os.system('cls')
print_logo()
show_current_instance()
show_last_action()
choice = questionary.select(
"Database Operations Options:",
choices=[
questionary.Separator(),
"Error Report Loader",
"SG26/SG29 Loader",
"DAT Loader",
"CSV Loader",
questionary.Separator(),
"Stage Highest Version to DAT Loader",
questionary.Separator(),
"Back to Main Menu"
],
pointer="→", # <-- Change the arrow here!
style=custom_style
).ask()
if choice is None:
continue
elif choice.startswith("Back to Main Menu"):
break
elif choice.startswith("Stage Highest Version to DAT Loader"):
run_dat_file_stager_load()
elif choice.startswith("Error Report Loader"):
run_error_report_loader()
elif choice.startswith("SG26/SG29 Loader"):
run_sg26_sg29_loader()
elif choice.startswith("DAT Loader"):
run_dat_loader()
elif choice.startswith("CSV Loader"):
run_csv_loader()
def onedrive_menu():
while True:
os.system('cls')
print_logo()
show_current_instance()
show_last_action()
choice = questionary.select(
"Finalize:",
choices=[
questionary.Separator(),
"Copy Submission to OneDrive",
"Import Submission from OneDrive",
questionary.Separator(),
"Back to Main Menu"
],
pointer="→", # <-- Change the arrow here!
style=custom_style
).ask()
if choice is None:
continue
elif choice.startswith("Back to Main Menu"):
break
elif choice.startswith("Copy Submission to OneDrive"):
run_finalize_submission()
elif choice.startswith("Import Submission from OneDrive"):
run_import_submission()
def main_menu():
try:
while True:
os.system('cls')
print_logo()
show_current_instance()
show_last_action()
choice = questionary.select(
"Main Menu:",
choices=[
questionary.Separator(),
"Data Extract and Preparation",
"Data Editing and Stripping",
"Database Operations",
"OneDrive Operations",
questionary.Separator(),
"Open Term Folder in Explorer",
"Change Instance Term",
"Delete Instance Term",
"Setup/Update Configuration",
"Exit"
],
pointer="→", # <-- Change the arrow here!
style=custom_style
).ask()
if choice is None or choice.startswith("Exit"):
log_action("Exit")
print(Fore.MAGENTA + "Goodbye!")
sys.exit(0)
elif choice.startswith("Setup/Update Configuration"):
run_config_setup()
elif choice.startswith("Open Term Folder in Explorer"):
run_open_explorer()
elif choice.startswith("Change Instance Term"):
global current_term, BASE_DIR, DATA_DIR, MASTER_LOG, HISTORY_LOG
new_term, _ = select_instance()
if new_term is None:
print("No instance selected. Returning to main menu.")
continue
current_term = new_term
BASE_DIR = os.path.join(os.getcwd(), "data", current_term)
DATA_DIR = BASE_DIR
MASTER_LOG = os.path.join(BASE_DIR, "mis-cli.log")
HISTORY_LOG = os.path.join(BASE_DIR, "history.log")
print(Fore.GREEN + f"Switched to instance: {current_term}" + ColoramaStyle.RESET_ALL)
log_action(f"Switched to instance: {current_term}")
elif choice.startswith("Delete Instance Term"):
was_deleted = run_instance_delete()
if was_deleted:
print(Fore.RED + f"Current instance '{current_term}' was deleted. Please select a new instance." + ColoramaStyle.RESET_ALL)
new_term, _ = select_instance()
if new_term is None:
print("No instance selected. Exiting CLI.")
sys.exit(0)
current_term = new_term
BASE_DIR = os.path.join(os.getcwd(), "data", current_term)
DATA_DIR = BASE_DIR
MASTER_LOG = os.path.join(BASE_DIR, "mis-cli.log")
HISTORY_LOG = os.path.join(BASE_DIR, "history.log")
print(Fore.GREEN + f"Switched to instance: {current_term}" + ColoramaStyle.RESET_ALL)
log_action(f"Switched to instance: {current_term}")
elif choice.startswith("Data Extract and Preparation"):
data_extract_preparation_menu()
elif choice.startswith("Data Editing and Stripping"):
data_editing_stripping_menu()
elif choice.startswith("Database Operations"):
database_operations_menu()
elif choice.startswith("OneDrive Operations"):
onedrive_menu()
except KeyboardInterrupt:
print(Fore.MAGENTA + "\nCLI interrupted by user. Goodbye!")
sys.exit(0)
if __name__ == "__main__":
main_menu()