-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_index.py
executable file
·52 lines (43 loc) · 1.48 KB
/
update_index.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
#!/usr/bin/env python3
from argparse import ArgumentParser, Namespace
from fnmatch import fnmatch
from definitions import definitions
from indexing.indexer import Indexer
def index(arguments: Namespace):
"""Index all defined software packages versions."""
indexer = Indexer()
if arguments.garbage_collect:
indexer.gc_all()
return
limit_definitions = None
if arguments.limit_definitions:
limit_definitions = [
definition
for definition in definitions
if fnmatch(
definition.software_package.name.lower(),
arguments.limit_definitions.lower())
]
if not limit_definitions:
print('no definitions match the expression.')
return
print(
'Definitions matching the expression: \n',
'\n '.join(
definition.software_package.name
for definition in limit_definitions))
indexer.index_all(
max_workers=arguments.max_workers, limit_definitions=limit_definitions)
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument(
'-w', '--max-workers', type=int, default=16,
)
parser.add_argument(
'-g', '--garbage-collect', action='store_true', default=False,
)
parser.add_argument(
'-l', '--limit-definitions', type=str,
help='Only index software packages which name matches the given expression',
)
index(parser.parse_args())