-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_tool.py
More file actions
executable file
·135 lines (125 loc) · 5.32 KB
/
Copy pathconfig_tool.py
File metadata and controls
executable file
·135 lines (125 loc) · 5.32 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
#!/usr/bin/env python3
import sys
sys.dont_write_bytecode = True
import os
from general_process_profiler import general_process_profiler
from memory_process_profiler import memory_process_profiler
from file_descriptor_process_profiler import file_descriptor_process_profiler
from thread_process_profiler import thread_process_profiler
# Menu ANSI Colors
BLACK = '\033[30m'
GREEN = '\033[32m'
BOLD_GREEN = '\033[1;32m'
BRIGHT_YELLOW = '\033[93m'
BRIGHT_RED = '\033[91m'
BOLD_CYAN = '\033[1;36m'
BRIGHT_CYAN = '\033[96m'
BRIGHT_GREEN = '\033[92m'
BRIGHT_BOLD_BLUE = '\033[1;94m'
BACKGROUND_BRIGHT_MAGENTA = '\033[105m'
RESET = '\033[0m'
# Reset Sceen
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
# Create the watch_list directory to store configurations
def create_watch_list_directory_if_not_exists(watch_list_path):
if not os.path.exists(watch_list_path):
os.makedirs(watch_list_path)
print(f"{GREEN}Directory '{watch_list_path}' created.{RESET}")
# List configurations in the watch_list directory
def list_files(directory):
try:
files = os.listdir(directory)
return files
except FileNotFoundError:
clear_screen()
print(f"\n{BLACK}{BACKGROUND_BRIGHT_MAGENTA}Error: Directory '{directory}' not found.{RESET}")
return []
except NotADirectoryError:
clear_screen()
print(f"\n{BLACK}{BACKGROUND_BRIGHT_MAGENTA}Error: '{directory}' is not a valid directory.{RESET}")
return []
# Delete a chosen configuration in the watch_list directory
def delete_file(directory, filename):
watch_list_path = os.path.join(directory, filename)
try:
os.remove(watch_list_path)
clear_screen()
print(f"\n{BRIGHT_GREEN}'{filename}' configuration deleted successfully.{RESET}")
except FileNotFoundError:
clear_screen()
print(f"\n{BLACK}{BACKGROUND_BRIGHT_MAGENTA}Error: File '{filename}' not found.{RESET}")
except PermissionError:
clear_screen()
print(f"\n{BLACK}{BACKGROUND_BRIGHT_MAGENTA}Error: Permission denied to delete '{filename}'.{RESET}")
except Exception as e:
clear_screen()
print(f"\n{BLACK}{BACKGROUND_BRIGHT_MAGENTA}An error occurred: {e}{RESET}")
# Configuration Tool Menu
def display_menu():
clear_screen()
create_watch_list_directory_if_not_exists("../watch_list")
while True:
print(f"\n{BRIGHT_GREEN}PROCESS WATCH OPTIONS{RESET}\n")
print("1. List Configuration Files.")
print("2. Delete a Configuration.")
print("3. Create a Process Profiler Configuration.")
print("4. Quit")
top_choice = input(f"\n{BRIGHT_CYAN}Enter your choice (1-4):{RESET}\n")
if top_choice == '1':
clear_screen()
files = list_files("../watch_list")
if files:
print(f"\n{BRIGHT_GREEN}CURRENT CONFIGURATION FILES:{RESET}\n")
for i, file in enumerate(files):
print(f"{BRIGHT_YELLOW}{i+1}. {file}{RESET}")
elif top_choice == '2':
clear_screen()
while True:
files = list_files("../watch_list")
if files:
print(f"\n{BRIGHT_GREEN}CURRENT CONFIGURATION FILES:{RESET}\n")
for i, file in enumerate(files):
print(f"{BRIGHT_YELLOW}{file}{RESET}")
filename = input(f"\n{BRIGHT_RED}Enter the{RESET} {BRIGHT_CYAN}name{RESET} {BRIGHT_RED}of the configuration to{RESET} {BRIGHT_RED}delete{RESET}{BRIGHT_YELLOW} ({BRIGHT_CYAN}e to exit{RESET}):{RESET}\n")
if filename == 'e':
clear_screen()
break
delete_file("../watch_list", filename)
elif top_choice == '3':
clear_screen()
while True:
print(f"\n{BRIGHT_GREEN}PROCESS WATCH CONFIGURATION CREATION OPTIONS{RESET}\n")
print("1. Create General Process Profiler")
print("2. Create Memory Process Profiler")
print("3. Create File Descriptor Profiler")
print("4. Create Thread Descriptor Profiler")
print("5. Exit")
watch_list_choice = input(f"\n{BRIGHT_CYAN}Enter your choice (1-5):{RESET}\n")
if watch_list_choice == '1':
clear_screen()
general_process_profiler()
break
if watch_list_choice == '2':
clear_screen()
memory_process_profiler()
break
if watch_list_choice == '3':
clear_screen()
file_descriptor_process_profiler()
break
if watch_list_choice == '4':
clear_screen()
thread_process_profiler()
break
if watch_list_choice == '5':
break
print(f"\n{BLACK}{BACKGROUND_BRIGHT_MAGENTA}Invalid choice. Please try again.{RESET}")
elif top_choice == '4':
print(f"\n{BRIGHT_GREEN}Quitting...{RESET}")
break
else:
clear_screen()
print(f"\n{BLACK}{BACKGROUND_BRIGHT_MAGENTA}Invalid choice. Please try again.{RESET}")
if __name__ == "__main__":
display_menu()