-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.py
95 lines (66 loc) · 3.22 KB
/
main.py
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
from typing import List, Tuple, Optional
from workspace_instructions import workspace_instructions
from DataController import DataController
from UtilityController import *
import sys
# Create new workspace given name
def create_workspace(workspace_name: str) -> Optional[int]:
if workspace_name in DataController.fetch_all_workspace_names():
print(f"{UtilityTools.RED}{UtilityTools.BOLD}[X] A workspace with the same name already exists.{UtilityTools.RESET}")
return None
DataController.insert_workspace(workspace_name)
print(f"{UtilityTools.GREEN}{UtilityTools.BOLD}[*] Workspace '{workspace_name}' created.{UtilityTools.RESET}")
return 1
# List all workspaces
def list_workspaces(workspace_names: List[Tuple[int, str]]) -> None:
print("[*] Found existing sessions:")
print(" [0] New session")
for idx, name in workspace_names:
print(f" [{idx}] {name}")
print(f" [{len(workspace_names)+1}] exit")
def create_workspace_flow(workspace_index: int) -> None:
while True:
workspace_name = input("> New workspace name: ").strip()
if 0 < len(workspace_name) < 100:
status = create_workspace(workspace_name)
if status:
break
else:
print(f"{UtilityTools.RED}{UtilityTools.BOLD}[X] You need a workspace name of minimum 1 length or maximum 100 length. Please try again...{UtilityTools.RESET}")
workspace_instructions(workspace_index, workspace_name)
def existing_workspaces_initiate(workspace_names: List[Tuple[int, str]]) -> None:
list_workspaces(workspace_names)
while True:
try:
option = int(input("Choose an option: ").strip())
break # Exit the loop if input is successfully converted to an integer
except ValueError:
print("Please enter a valid number.")
# If user chooses to create new workspace start create new workspace flow. ID of workspace is
# length plus 1. For example adding a second workspace means workspace 1 exists with ID 1, so the
# new workspace would be of ID 2
if option == 0:
create_workspace_flow(len(workspace_names)+1)
elif option == len(workspace_names)+1:
exit()
else:
workspace_name = DataController.workspace_exists(option)
if workspace_name:
workspace_instructions(option, workspace_name)
else:
print(f"{UtilityTools.RED}{UtilityTools.BOLD}[X] No workspace was found with this option. Quitting...{UtilityTools.RESET}")
exit()
def main()-> None:
workspace_names = DataController.get_workspaces()
# If the databases have not been created or no workspaces exist, give the default first time message
if len(workspace_names) == 0:
workspace_index = 1
print("[*] No workspaces were detected. Please provide the name for your first workspace below.")
DataController.create_initial_workspace_session_database()
create_workspace_flow(workspace_index)
# Workspaces exist, give option to choose an existing one
else:
existing_workspaces_initiate(workspace_names)
if __name__ == "__main__":
sys.dont_write_bytecode = True
main()