-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (69 loc) · 3.07 KB
/
main.py
File metadata and controls
88 lines (69 loc) · 3.07 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
def main():
import sys
import time
import msvcrt
import os
import importlib
from csiapi import csiutils
def spinner():
spinner = ['/', '-', '\\', '|']
i = 0
# print("Press Enter to stop the spinner.")
while True:
# Display the spinner
sys.stdout.write(spinner[i % len(spinner)])
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write('\b') # Erase the last character
# Check if a key is pressed
if msvcrt.kbhit():
key = msvcrt.getch() # Get the key press
if key == b'\r': # Enter key is detected
break
i += 1
# print("Loop exited.")
SapModel = csiutils.attach()
processors_dir = 'processors' #to be called from folder which has this folder
# Dynamically import all .py files from the processors directory
modules = {}
for file in os.listdir(processors_dir):
if file.endswith(".py"):
module_name = file[:-3] # Remove .py extension
module = importlib.import_module(f"{processors_dir}.{module_name}")
modules[module_name] = module
# Create dictionary mapping selection numbers to modules and their main functions
scripts = {i + 1: module for i, (name, module) in enumerate(modules.items())}
while True:
try:
# Dynamically generate the user input prompt string
input_string = "Enter the following number for the desired action:\n 0 - Exit\n"
for i, (name, module) in enumerate(modules.items(), start=1):
display_name = getattr(module, "NAME", name)
description = getattr(module, "DESCRIPTION", "")
input_string += f" {i} - {display_name}\n"
if description:
input_string += f" {description}\n"
selection = int(input(input_string))
if selection == 0:
# sys.exit() # not working with python notebook
return SapModel # to use in python notebook
elif selection in scripts:
script = scripts[selection]
if hasattr(script, 'main'):
script.main(SapModel)
# spinner() # not used due to issue with notebook
input("Press enter to continue")
print("==========================================================")
elif hasattr(script, 'local'):
script.local()
# spinner() # not used due to issue with notebook
input("Press enter to continue")
print("==========================================================")
else:
print(f"The selected script does not have a 'main' function.")
except ValueError:
print("Invalid input. Please enter a number")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
main()