-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
53 lines (44 loc) · 1.42 KB
/
run.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
if __name__ == '__main__':
import regex
from multiprocessing import Pool
from treesearcher import tasks, do_cleanup, do_set_root, \
do_set_fileexts, do_search, make_fs_name, write_toc
#[of]set up some global stuff:set up some global stuff
import variables
globs = {
'root': None,
'fileexts': set(),
'vars': {
var[2:]: getattr(variables, var)
for var in dir(variables) if var .startswith('p_')
},
'variableregex': regex.compile(r'{{([^{}]+)}}'),
'newlineregex': regex.compile(r'\n'),
}
#[cf]
import searches
for typ, task in tasks:
if typ == 'cleanup': do_cleanup(globs, ask=task)
elif typ == 'setroot': do_set_root(globs, task)
elif typ == 'setfileexts': do_set_fileexts(globs, task)
elif typ == 'search':
#[of]:ensure that basics options are configured
if not globs['root']:
abort('please define a root directory using set_root()')
if not globs['fileexts']:
abort('please define some file extensions using set_fileexts()')
#[cf]
#[of]:run the searches using multiple python processes
todo = []
for searchtitle, searchpattern in task.items():
searchtitle = make_fs_name(searchtitle)
todo.append((globs, searchtitle, searchpattern))
print('starting search (may take a while)')
pool = Pool()
pool.map(do_search, todo)
pool.close()
pool.join()
print('done')
#[cf]
write_toc(todo)
print('ALL DONE')