-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage.py
91 lines (69 loc) · 2.56 KB
/
manage.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
from __future__ import absolute_import, division, unicode_literals
import argparse
import sys
import time
import config
import packages
import index
def _stopwatch(start_time):
return "Done. Time elapsed in seconds: " + unicode(time.time() - start_time)
def _download():
start_time = time.time()
print "Starting downloads. This can take up to a few minutes."
packages.download()
print _stopwatch(start_time)
def _index_refresh():
start_time = time.time()
print "Starting indexing. This can take a minute."
index.write_indices()
print _stopwatch(start_time)
def _search(query, os_version):
if not os_version in config.OS_VERSIONS:
print "Unknown os_version."
sys.exit(1)
searchkit = index.searchkit_factory()
searcher = searchkit[os_version]['ix'].searcher()
myparser = searchkit[os_version]['parser']
start_time = time.time()
results = searcher.search(myparser.parse(query))
for result in results:
print result
print _stopwatch(start_time)
def _set_package_timestamp_to_now():
packages.set_timestamp_to_now()
print "Done setting package data timestamp to current time and date."
parser = argparse.ArgumentParser(description='Manage Centos Packages stuff.')
parser.add_argument('--download',
help='Download repo data from web.',
action='store_true')
parser.add_argument('--index',
help='Recreate the search index from the repo data.',
action='store_true')
parser.add_argument('--search',
help='Search for packages from the commmand line.',
action='store')
parser.add_argument('--version',
help='Only with "search" and "timestamp" option. '
'Specifies version to search in.',
action='store')
parser.add_argument('--packages_timestamp',
help="Sets timestamp of package data to now which indicats that "
"they are fresh to webapp.",
action='store_true')
args = parser.parse_args()
if not any([args.download, args.index, args.search, args.packages_timestamp]):
print "At least one option is required. See --help."
sys.exit(1)
def _requires_version():
if not args.version:
print "Please specify version."
sys.exit(1)
if args.download:
_download()
if args.index:
_index_refresh()
if args.search:
_requires_version()
_search(args.search, args.version)
if args.packages_timestamp:
_set_package_timestamp_to_now()