Blame view

digger.py 2.61 KB
1
2
3
4
5
6
7
8
#! /usr/bin/env python3

import locale
from dialog import Dialog
import glob
import os
import sys
import subprocess as sp
Imanol-Mikel Barba Sabariego authored
9
import tomb
10
11
12
13
14
15
16
17
18
19
20
21
22
23

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)
24
            instance = module.getInstance()
25
26
27
28
29
30
31
32
33
            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):
34
    module = __import__(moduleName).getInstance()
35
36
37
38
39
    module.getVars()
    return module

locale.setlocale(locale.LC_ALL, '')
d = Dialog(dialog="dialog",autowidgetsize=True)
40
d.set_background_title("Gravedigger")
41
42

moduleList = getModules()
Imanol-Mikel Barba Sabariego authored
43
code,value = d.inputbox("Input computer's name")
44
if code == d.OK:
Imanol-Mikel Barba Sabariego authored
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    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))
59
Imanol-Mikel Barba Sabariego authored
60
            sp.call('clear', shell=True)
61
Imanol-Mikel Barba Sabariego authored
62
63
64
65
66
67
            for module in runlist:
                print("Running " + module.name + "...")
                try:
                    module.run()
                except Exception as e:
                    print("Exception raised while running " + module.name + ": " + str(e))
68
Imanol-Mikel Barba Sabariego authored
69
70
71
72
73
74
75
76
77
78
79
80
            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))
81
82