Repository navigation
Expand file tree
/
Copy pathinspector.py
More file actions
159 lines (134 loc) · 5.44 KB
/
Copy pathinspector.py
File metadata and controls
159 lines (134 loc) · 5.44 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
import inspect
import subprocess
import time
import os
import io
import sys
def install_module(module_name):
try:
print(f"Status: Module {module_name} is not installed. Installing...")
subprocess.check_call(['pip', 'install', module_name])
print(f"Status: Module {module_name} has been installed.")
except Exception as e:
print(f"Error installing module {module_name}: {e}")
def install_another_module():
clear()
module_name = input('Enter the name of the module: ')
subprocess.check_call(['pip', 'install', module_name])
print(f"Status: Module {module_name} has been installed.")
def check_and_install_module(module_name):
try:
# Run 'pip list' and get the output
pip_list_output = subprocess.check_output(['pip', 'list']).decode('utf-8')
# Check if the module is in the list
if module_name not in pip_list_output:
install_module(module_name)
else:
print(f"Status: Module {module_name} is already installed.")
except Exception as e:
print(f"Error checking or installing module {module_name}: {e}")
def list_classes(module):
classes = inspect.getmembers(module, inspect.isclass)
print("\n\t*****CLASSES*****\n")
for name, cls in classes:
print(f"Class: {name}")
def list_functions(module):
functions = inspect.getmembers(module, inspect.isfunction)
print("\n\t*****FUNCTIONS*****\n")
for name, func in functions:
print(f"Function: {name}")
def list_functions_and_arguments(module):
functions = inspect.getmembers(module, inspect.isfunction)
print("\n\t*****FUNCTIONS and ARGUMENTS*****\n")
for name, func in functions:
sig = inspect.signature(func)
args = ', '.join(str(param) for param in sig.parameters.values())
print(f"Function: {name}, Arguments: {args}")
def list_classes_and_methods(module):
classes = inspect.getmembers(module, inspect.isclass)
print("\n\t*****CLASSES and METHODS*****\n")
for name, cls in classes:
methods = inspect.getmembers(cls, predicate=inspect.isfunction)
for method_name, method in methods:
print(f"Class: {name}, Method: {method_name}")
def list_functions_methods_and_arguments(module):
classes = inspect.getmembers(module, inspect.isclass)
print("\n\t*****FUNCTIONS, METHODS and ARGUMENTS*****\n")
for name, cls in classes:
methods = inspect.getmembers(cls, predicate=inspect.isfunction)
for method_name, method in methods:
sig = inspect.signature(method)
args = ', '.join(str(param) for param in sig.parameters.values())
print(f"Class: {name}, Method: {method_name}, Arguments: {args}")
def run_all_functions(module):
print("\n\t*****RUNNING ALL FUNCTIONS*****\n")
list_classes(module)
list_functions(module)
list_functions_and_arguments(module)
list_classes_and_methods(module)
list_functions_methods_and_arguments(module)
def run_all_with_export(module):
try:
# Capture the output of run_all_functions
output = io.StringIO()
sys.stdout = output
run_all_functions(module)
sys.stdout = sys.__stdout__
output_str = output.getvalue()
# Write the output to all.txt, overwriting if it exists
with open('./all.txt', 'w') as f:
f.write(output_str)
print("Data exported to all.txt successfully.")
except Exception as e:
print(f"Error exporting data to all.txt: {e}")
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
def main():
module_name = input("Enter the name of the module you want to get information of: ")
try:
module = __import__(module_name)
check_and_install_module(module_name)
# 3-second delay
time.sleep(2)
# Clear the console
clear()
# Show menu one time
print("\nMenu:")
print("1. List Classes")
print("2. List Functions")
print("3. List Functions and Arguments")
print("4. List Classes and Methods")
print("5. List Functions, Methods, and Arguments")
print("6. Run All Functions")
print("7. Run All Functions With Export")
print("8. Install another module")
print("9. Exit")
choice = input("Please select an option: ")
if choice == '1':
list_classes(module)
elif choice == '2':
list_functions(module)
elif choice == '3':
list_functions_and_arguments(module)
elif choice == '4':
list_classes_and_methods(module)
elif choice == '5':
list_functions_methods_and_arguments(module)
elif choice == '6':
run_all_functions(module)
elif choice == '7':
run_all_with_export(module)
elif choice == '8':
install_another_module(module_name)
elif choice == '9' or choice == 'exit' or choice == 'Exit':
print("Exiting...")
time.sleep(2)
else:
print("Invalid option. Please try again.")
except ImportError:
print(f"Module {module_name} is incorrect or not found.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
clear()
main()