summaryrefslogtreecommitdiffstats
path: root/aria/aria-rest-server/build.py
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-01-02 10:33:50 +0000
committerGerrit Code Review <gerrit@onap.org>2018-01-02 10:33:50 +0000
commitf668415b052f9672801afce7802d7fd878673f67 (patch)
treedfda71d5e19aaf566b84ae283d67ac1a8b118599 /aria/aria-rest-server/build.py
parentfffbc99f5d7ce51601204076f77882cb298f4275 (diff)
parent18266f843b047531ba4ec5c5ef5cb5f148863a1a (diff)
Merge "Updated build to create wheel and push to Pypi"
Diffstat (limited to 'aria/aria-rest-server/build.py')
-rw-r--r--aria/aria-rest-server/build.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/aria/aria-rest-server/build.py b/aria/aria-rest-server/build.py
new file mode 100644
index 0000000000..6076c2ffce
--- /dev/null
+++ b/aria/aria-rest-server/build.py
@@ -0,0 +1,77 @@
+import subprocess
+import os
+import sys
+import glob
+import xml.etree.ElementTree as etree
+
+# create and enter venv
+def create_venv( name):
+ if subprocess.call("virtualenv {}".format(name), shell = True):
+ raise Exception("virtualenv create failed")
+ ret = subprocess.call(". {}/bin/activate && python {} run". \
+ format(name,__file__), shell = True)
+ sys.exit(ret)
+
+def init_venv():
+ subprocess.call("pip install -U pip", shell = True)
+ subprocess.call("pip install -U setuptools", shell = True)
+ subprocess.call("pip install wheel", shell = True)
+ subprocess.call("pip install twine", shell = True)
+
+
+if len(sys.argv) == 1:
+ create_venv ("mavenvenv")
+else:
+ init_venv()
+
+ if os.environ['MVN_PHASE'] == 'package':
+ wheelname = os.environ['WHEEL_NAME']
+ inputdir = os.environ['INPUT_DIR']
+ outputdir = os.environ['OUTPUT_DIR']
+ savedir = os.getcwd()
+ os.chdir(inputdir)
+
+ if subprocess.call( [ "python",
+ "setup.py",
+ "bdist_wheel",
+ "-d",
+ outputdir
+ ]):
+ sys.stderr("wheel create failed")
+ sys.exit(1)
+ f = glob.glob(outputdir+"/*.whl")[0]
+ os.rename(f , outputdir+"/"+ wheelname)
+
+ elif os.environ['MVN_PHASE'] == 'deploy':
+
+ it = etree.iterparse(os.environ['SETTINGS_FILE'])
+ for _, el in it:
+ el.tag = el.tag.split('}', 1)[1] # strip namespace
+ settings = it.root
+
+ username = settings.find('.//server[id="{}"]/username'.format(
+ os.environ['PYPI_SERVERID'])).text
+ password = settings.find('.//server[id="{}"]/password'.format(
+ os.environ['PYPI_SERVERID'])).text
+
+ try:
+ if subprocess.call( [ "twine",
+ "upload",
+ "--username",
+ username,
+ "--password",
+ password,
+ "--repository-url",
+ os.environ["PYPI_SERVER_BASEURL"],
+ os.environ["WHEEL_PATH"]
+ ] ):
+ sys.stderr.write("pypi upload failed")
+ sys.exit(1)
+ finally:
+ subprocess.call("rm -rf mavenvenv", shell = True)
+
+ sys.exit(0)
+ else:
+ sys.stderr.write("Unrecognized phase '{}'\n".format(
+ os.environ('MVN_PHASE')))
+ sys.exit(1)