From b3e40f026d655501bfa581452c447784604ecb05 Mon Sep 17 00:00:00 2001 From: xudan Date: Fri, 6 Jul 2018 05:16:40 -0400 Subject: Move all web portal code to the new repo dovetail-webportal This is only the first step to simply copy the file here. There still need some more work to make sure all work well. All the changes will be submitted with other patches to make it easily to review. JIRA: DOVETAIL-671 Change-Id: I64d32a9df562184166b6199e2719f298687d1a0a Signed-off-by: xudan --- update/templates/utils.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 update/templates/utils.py (limited to 'update/templates/utils.py') diff --git a/update/templates/utils.py b/update/templates/utils.py new file mode 100644 index 0000000..4254fee --- /dev/null +++ b/update/templates/utils.py @@ -0,0 +1,48 @@ +############################################################################## +# Copyright (c) 2016 ZTE Corporation +# feng.xiaowei@zte.com.cn +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import os +import urlparse +import subprocess + + +def get_abspath(path): + assert os.path.isdir(path), 'Path %s can\'t be found.' % path + return os.path.abspath(path) + + +def parse_mongodb_url(url): + url = urlparse.urlparse(url) + assert url.scheme == 'mongodb', 'URL must be a MongoDB URL' + return url + + +def url_parse(url): + url = parse_mongodb_url(url) + return url.username, url.password, url.hostname, url.port + + +def execute(cmd, args): + (username, password, hostname, port) = url_parse(args.url) + cmd.extend(['--host', '%s' % hostname, '--port', '%s' % port]) + db = args.db + if db is not None: + cmd.extend(['--db', '%s' % db]) + if username is not None: + cmd.extend(['-u', '%s' % username, '-p', '%s' % password]) + print('execute: %s' % cmd) + execute_output = subprocess.check_output(cmd) + print(execute_output) + + +def main(method, parser): + args = parser.parse_args() + try: + method(args) + except AssertionError as msg: + print(msg) -- cgit 1.2.3-korg