-
Notifications
You must be signed in to change notification settings - Fork 1
/
dump_count.py
64 lines (48 loc) · 1.63 KB
/
dump_count.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
import os,sys
import string
from optparse import OptionParser
import glob
import json
from bson import json_util
import pymongo
from pymongo import MongoClient
import datetime
__version__="1.0"
__status__ = "Dev"
###############################
def main():
usage = "\n%prog [options]"
parser = OptionParser(usage,version="%prog version___")
parser.add_option("-s","--server",action="store",dest="server",help="dev/tst/beta/prd")
parser.add_option("-c","--coll",action="store",dest="coll",help="")
(options,args) = parser.parse_args()
for key in ([options.server, options.coll]):
if not (key):
parser.print_help()
sys.exit(0)
server = options.server
coll = options.coll
config_obj = json.loads(open("./conf/config.json", "r").read())
mongo_port = config_obj["dbinfo"]["port"][server]
mongo_container = "running_glygen_mongo_%s" % (server)
host = "mongodb://127.0.0.1:%s" % (mongo_port)
db_obj = config_obj["dbinfo"]["glydb"]
db_name, db_user, db_pass = db_obj["db"], db_obj["user"], db_obj["password"]
try:
client = pymongo.MongoClient(host,
username=db_user,
password=db_pass,
authSource=db_name,
authMechanism='SCRAM-SHA-1',
serverSelectionTimeoutMS=10000
)
client.server_info()
dbh = client[db_name]
n = dbh[coll].count_documents({})
print (coll, n)
except pymongo.errors.ServerSelectionTimeoutError as err:
print (err)
except pymongo.errors.OperationFailure as err:
print (err)
if __name__ == '__main__':
main()