2 # ============LICENSE_START===================================================
3 # Copyright (c) 2018 Amdocs. All rights reserved.
4 # ===================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 # use this file except in compliance with the License. You may obtain a copy
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations under
16 # ============LICENSE_END====================================================
23 import xml.etree.ElementTree as etree
25 # create and enter venv
26 def create_venv( name):
27 if subprocess.call("virtualenv {}".format(name), shell = True):
28 raise Exception("virtualenv create failed")
29 ret = subprocess.call(". {}/bin/activate && python {} run". \
30 format(name,__file__), shell = True)
34 subprocess.call("pip install -U pip", shell = True)
35 subprocess.call("pip install -U setuptools", shell = True)
36 subprocess.call("pip install wheel", shell = True)
37 subprocess.call("pip install twine", shell = True)
40 if len(sys.argv) == 1:
41 create_venv ("mavenvenv")
45 if os.environ['MVN_PHASE'] == 'package':
46 wheelname = os.environ['WHEEL_NAME']
47 inputdir = os.environ['INPUT_DIR']
48 outputdir = os.environ['OUTPUT_DIR']
52 if subprocess.call( [ "python",
58 sys.stderr("wheel create failed")
60 f = glob.glob(outputdir+"/*.whl")[0]
61 os.rename(f , outputdir+"/"+ wheelname)
63 elif os.environ['MVN_PHASE'] == 'deploy':
65 it = etree.iterparse(os.environ['SETTINGS_FILE'])
67 el.tag = el.tag.split('}', 1)[1] # strip namespace
70 username = settings.find('.//server[id="{}"]/username'.format(
71 os.environ['PYPI_SERVERID'])).text
72 password = settings.find('.//server[id="{}"]/password'.format(
73 os.environ['PYPI_SERVERID'])).text
76 if subprocess.call( [ "twine",
83 os.environ["PYPI_SERVER_BASEURL"],
84 os.environ["WHEEL_PATH"]
86 sys.stderr.write("pypi upload failed")
89 subprocess.call("rm -rf mavenvenv", shell = True)
93 sys.stderr.write("Unrecognized phase '{}'\n".format(
94 os.environ('MVN_PHASE')))