Blame view

digger.py 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#! /usr/bin/env python3

import locale
from dialog import Dialog
import glob
import os
import sys
import subprocess as sp

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)
23
            instance = module.getInstance()
24
25
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)

    choiceList.append(("all","Execute all modules",False))
    return choiceList

def prepareModule(moduleName):
35
    module = __import__(moduleName).getInstance()
36
37
38
39
40
    module.getVars()
    return module

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

moduleList = getModules()
code, tags = d.checklist("Select modules to execute",
                         choices=moduleList,
                         title="Module selection")
if code == d.OK:
    runlist = []
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    try:
        if "All" in tags:
            for module in moduleList:
                runlist.append(prepareModule(module))
        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))

    except Exception as e:
        print("Exception raised while preparing module: " + str(e))
68
69