forked from rrenaud/dominionstats
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindexes.py
78 lines (59 loc) · 1.68 KB
/
indexes.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
#!/usr/bin/python
import logging
import logging.handlers
import os
import os.path
import re
import sys
import utils
from keys import *
# Module-level logging instance
log = logging.getLogger(__name__)
INDEXES = {
'games': [
PLAYERS,
SUPPLY,
],
'raw_games': [
'game_date',
],
'goals': [
'goals.player',
'goals.goal_name',
],
}
def ensure_all_indexes(db):
"""Ensure all expected indexes are in place, for all tables"""
for table_name, index_list in INDEXES.items():
for index in index_list:
log.info("Ensuring %s index for %s", index, table_name)
db[table_name].ensure_index(index)
def main():
con = utils.get_mongo_connection()
ensure_all_indexes(con.test)
if __name__ == '__main__':
args = utils.incremental_parser().parse_args()
script_root = os.path.splitext(sys.argv[0])[0]
# Create the basic logger
#logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
# Log to a file
fh = logging.handlers.TimedRotatingFileHandler(script_root + '.log', when='midnight')
if args.debug:
fh.setLevel(logging.DEBUG)
else:
fh.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
fh.setFormatter(formatter)
log.addHandler(fh)
# Put logging output on stdout, too
ch = logging.StreamHandler(sys.stdout)
if args.debug:
ch.setLevel(logging.DEBUG)
else:
ch.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
ch.setFormatter(formatter)
log.addHandler(ch)
main()