digger.py
2.8 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
#! /usr/bin/env python3
import locale
from dialog import Dialog
import glob
import os
import sys
import subprocess as sp
import tomb
import traceback
sys.path.append('modules')
sys.path.append('vars')
def getModules():
choiceList = []
modules = []
for filename in glob.glob('./modules/*.py'):
modules.append(os.path.splitext(os.path.basename(filename))[0])
modules.remove('__init__')
for modname in modules:
try:
module = __import__(modname)
instance = module.getInstance()
choiceList.append((instance.name,instance.description,False))
del instance
del module
sys.modules.pop(modname)
except Exception as e:
print("Exception raised while importing " + modname)
return choiceList
def prepareModule(moduleName):
try:
module = __import__(moduleName).getInstance()
module.getVars()
return module
except Exception as e:
raise Exception("[" + moduleName + "] " + str(e))
locale.setlocale(locale.LC_ALL, '')
d = Dialog(dialog="dialog",autowidgetsize=True)
d.set_background_title("Gravedigger")
moduleList = getModules()
code,value = d.inputbox("Input computer's name")
if code == d.OK:
tomb._MACHINE_NAME= value
d.set_background_title("Gravedigger - " + value)
code, tags = d.checklist("Select modules to execute",
choices=moduleList + [("all","Execute all modules",False)],
title="Module selection")
if code == d.OK:
runlist = []
try:
if "all" in tags:
for module in moduleList:
runlist.append(prepareModule(module[0]))
else:
for tag in tags:
runlist.append(prepareModule(tag))
sp.call('clear', shell=True)
for module in runlist:
print("Running " + module.name + "...")
try:
module.run()
except Exception as e:
print("Exception raised while running " + module.name + ": " + str(e))
traceback.print_exc()
code, tag = d.menu("All modules finished execution",choices=[("Poweroff","Shutdown the computer"),
("Reboot","Reboot the computer"),
("Restart","Run Gravedigger again")])
if(code == d.OK):
if tag == "Poweroff":
sp.call("poweroff",shell=True)
elif tag == "Reboot":
sp.call("reboot", shell=True)
except Exception as e:
print("Exception raised while preparing module: " + str(e))
traceback.print_exc()