Repository navigation
Expand file tree
/
Copy pathshell_options.py
More file actions
74 lines (65 loc) · 2.61 KB
/
Copy pathshell_options.py
File metadata and controls
74 lines (65 loc) · 2.61 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
from os import walk
from os.path import join
from utils.color_palette import colors_terminal
class ShellOptions:
__instance = None
@staticmethod
def get_instance():
if ShellOptions.__instance == None:
ShellOptions()
return ShellOptions.__instance
def __init__(self):
if ShellOptions.__instance == None:
ShellOptions.__instance = self
modules_list = self._get_list_modules()
self.options_to_del = ["set", "unset", "show", "back", "run", "global"]
self.shell_options = {
"load": modules_list,
"help": [],
"banner": [],
"find": [],
"import": [],
"export": [],
"modules": list(set([module.split("/")[0] for module in modules_list])),
"tasks": ["kill", "list"],
"theme": colors_terminal.keys(),
"exit": None,
"quit": None
}
def get_shell_options(self):
return self.shell_options
# To allow extend autocomplete from modules
def add_set_option_values(self, op, value):
if type(value) != type([]):
value = [value]
try:
self.shell_options["set"][op].append(value)
except Exception as e:
print(e)
# To extend options to Autocomplete commands
def add_module_options(self, options_name=[], new_functions=[]):
self.shell_options["set"] = self.shell_options["global"] = {}
self.shell_options["unset"] = options_name
for name in options_name:
self.shell_options["set"][name] = self.shell_options["global"][name] = []
self.shell_options["run"] = []
self.shell_options["back"] = []
self.shell_options["show"] = ["options", "info"]
# Update new functions
for f in new_functions:
if f not in list(self.shell_options.keys()):
self.shell_options[f] = []
self.options_to_del.append(f)
def del_module_options(self):
self.shell_options["show"] = ["banner"]
for c in self.options_to_del:
try:
del self.shell_options[c]
except:
self.options_to_del.remove(c)
# Search tool modules in folder 'modules'
def _get_list_modules(self, pwd="./modules"):
file_list = []
for (p, d, files) in walk(pwd):
file_list.extend([join(p.replace("./modules/", ""), f.replace(".py", "")) for f in files if ("_" not in f) and ("_" not in p)])
return file_list