-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_db.py
More file actions
55 lines (38 loc) · 1.56 KB
/
build_db.py
File metadata and controls
55 lines (38 loc) · 1.56 KB
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
from datetime import datetime
import db.database as D
import db.collection as CM
db_confirmed = False
while not db_confirmed:
db_prompt = 'note that you are using the DB named {}, continue? y/n: '.format(D.Mdb.name)
go_ahead = input(db_prompt)
if go_ahead == 'y':
db_confirmed = True
else:
rename_db_prompt = 'enter the name of the DB you would like to use: '
new_db_name = input(rename_db_prompt)
D.set_db(new_db_name)
for class_name in CM.build_order:
class_instance = getattr(CM, class_name)()
n_docs = class_instance.count()
if n_docs > 0:
if class_name in CM.incremental_collections:
prompt = '{} contains {} docs but is incremental, re-run the build? y/n: '. \
format(class_instance.collection_name, n_docs)
do_rebuild = input(prompt)
if do_rebuild != 'y':
print('skipping', class_instance.collection_name)
continue
else:
prompt = '{} already contains {} docs, do you want to rebuild? y/n: '. \
format(class_instance.collection_name, n_docs)
do_rebuild = input(prompt)
if do_rebuild == 'y':
class_instance.drop()
else:
print('skipping', class_instance.collection_name)
continue
print('building', class_instance.collection_name)
t0 = datetime.now()
class_instance.build()
t1 = datetime.now()
print('build of {} completed, taking {}'.format(class_instance.collection_name, t1 - t0))