Blame view

digger.py 2.8 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
import traceback
11
12
13
14
15
16
17
18
19
20
21
22
23
24

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)
25
            instance = module.getInstance()
26
27
28
29
30
31
32
33
34
            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):
35
36
37
38
39
40
    try:
        module = __import__(moduleName).getInstance()
        module.getVars()
        return module
    except Exception as e:
        raise Exception("[" + moduleName + "] " + str(e))
41
42
43

locale.setlocale(locale.LC_ALL, '')
d = Dialog(dialog="dialog",autowidgetsize=True)
44
d.set_background_title("Gravedigger")
45
46

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