blob: cc36d2f855e76fef09c9e3bb719f2ace69ea9711 [file] [log] [blame]
dfilppi92487722017-12-27 17:22:23 +00001#
2# ============LICENSE_START===================================================
3# Copyright (c) 2017 Cloudify.co. 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
7# of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
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
15# the License.
16# ============LICENSE_END====================================================
17#
18
dfilppi18266f82017-12-26 21:54:15 +000019import subprocess
20import os
21import sys
22import glob
23import xml.etree.ElementTree as etree
24
25# create and enter venv
26def 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)
31 sys.exit(ret)
32
33def init_venv():
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)
38
39
40if len(sys.argv) == 1:
41 create_venv ("mavenvenv")
42else:
43 init_venv()
44
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']
49 savedir = os.getcwd()
50 os.chdir(inputdir)
51
52 if subprocess.call( [ "python",
53 "setup.py",
54 "bdist_wheel",
55 "-d",
56 outputdir
57 ]):
58 sys.stderr("wheel create failed")
59 sys.exit(1)
60 f = glob.glob(outputdir+"/*.whl")[0]
61 os.rename(f , outputdir+"/"+ wheelname)
62
63 elif os.environ['MVN_PHASE'] == 'deploy':
64
65 it = etree.iterparse(os.environ['SETTINGS_FILE'])
66 for _, el in it:
67 el.tag = el.tag.split('}', 1)[1] # strip namespace
68 settings = it.root
69
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
74
75 try:
76 if subprocess.call( [ "twine",
77 "upload",
78 "--username",
79 username,
80 "--password",
81 password,
82 "--repository-url",
83 os.environ["PYPI_SERVER_BASEURL"],
84 os.environ["WHEEL_PATH"]
85 ] ):
86 sys.stderr.write("pypi upload failed")
87 sys.exit(1)
88 finally:
89 subprocess.call("rm -rf mavenvenv", shell = True)
90
91 sys.exit(0)
92 else:
93 sys.stderr.write("Unrecognized phase '{}'\n".format(
94 os.environ('MVN_PHASE')))
95 sys.exit(1)