-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwisdom-cli.py
executable file
·95 lines (79 loc) · 2.69 KB
/
wisdom-cli.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
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
89
90
91
92
93
94
95
#!/usr/bin/python3
from jinja2.exceptions import TemplateSyntaxError
from logging import error
from logging import info
from logging.config import dictConfig
from os.path import join
from sys import argv
from time import perf_counter_ns
from time import sleep
from traceback import format_exc
from wisdom.arguments import Arguments
from wisdom.configuration import Configuration
from wisdom.source import Source
from wisdom.output import Output
def process(arguments):
configuration = Configuration(arguments)
source = Source(arguments, configuration)
source.discover()
output = Output(arguments, configuration, source)
output.generate_static()
output.generate_jinja2()
def main():
arguments = Arguments()
dictConfig({
'version': 1,
'formatters': {
'default': {
'format': '%(asctime)s [%(levelname)-8s] %(pathname)s:%(lineno)s (%(funcName)s) %(message)s',
'datefmt': "%Y-%m-%d %H:%M:%S",
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': max(0, 10 * (4 - arguments.verbosity_level)),
},
'file': {
'backupCount': 14,
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': join(arguments.output_path, 'wisdom-cli.log'),
'formatter': 'default',
'level': 'DEBUG',
'when': 'midnight',
},
},
'root': {
'handlers': ['console', 'file'],
'level': 'DEBUG',
},
})
info('wisdom-cli "%s"', '" "'.join(argv))
if arguments.watch_path:
from inotify.adapters import InotifyTree
from inotify.constants import IN_CLOSE_WRITE
inotify = InotifyTree(arguments.watch_path, IN_CLOSE_WRITE, 24*60*60)
while True:
time_nano_from = perf_counter_ns()
try:
process(arguments)
except Exception:
error(format_exc())
time_nano_till = perf_counter_ns()
span_nano = time_nano_till - time_nano_from
span_micro = span_nano // 1000
span_milli = span_micro // 1000
total_full = span_milli // 1000
total_milli = span_milli % 1000
info(f'{total_full} seconds {total_milli} milliseconds elapsed.')
for e in inotify.event_gen():
if e:
_, _, path, name = e
info('inotify "%s/%s"', path, name)
else:
break
sleep(0.1)
else:
process(arguments)
if __name__ == '__main__':
main()