1 ##############################################################################
2 # Copyright (c) 2016 ZTE Corporation
3 # feng.xiaowei@zte.com.cn
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
14 def get_abspath(path):
15 assert os.path.isdir(path), 'Path %s can\'t be found.' % path
16 return os.path.abspath(path)
19 def parse_mongodb_url(url):
20 url = urlparse.urlparse(url)
21 assert url.scheme == 'mongodb', 'URL must be a MongoDB URL'
26 url = parse_mongodb_url(url)
27 return url.username, url.password, url.hostname, url.port
30 def execute(cmd, args):
31 (username, password, hostname, port) = url_parse(args.url)
32 cmd.extend(['--host', '%s' % hostname, '--port', '%s' % port])
35 cmd.extend(['--db', '%s' % db])
36 if username is not None:
37 cmd.extend(['-u', '%s' % username, '-p', '%s' % password])
38 print('execute: %s' % cmd)
39 execute_output = subprocess.check_output(cmd)
43 def main(method, parser):
44 args = parser.parse_args()
47 except AssertionError, msg: