-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.py
56 lines (40 loc) · 1.19 KB
/
main.py
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
import glob
import logging
import optparse
import sys
import generator
USAGE = "%prog [-v] [<package> [<version]]"
def main():
# Initialise logging
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s %(levelname)-7s %(name)-32s %(message)s",
)
logger = logging.getLogger("main")
# Parse options
parser = optparse.OptionParser(usage=USAGE)
parser.add_option("-v", "--verbose", dest="verbose", action="store_true")
options, args = parser.parse_args(sys.argv[1:])
package_name = None
package_version = None
if len(args) >= 1:
package_name = args[0]
if len(args) >= 2:
package_version = args[1]
generator.Generator.OPTIONS = options
# Find generator modules
module_filenames = glob.glob("generator_*.py")
generators = []
# Load generator modules
for filename in module_filenames:
module_name = filename[:-3]
module = __import__(module_name)
generators += module.MakeGenerators()
# Run them
for gen in generators:
if (package_name is not None and gen.name != package_name) or \
(package_version is not None and gen.version != package_version):
continue
gen.Generate()
if __name__ == "__main__":
main()