-
Notifications
You must be signed in to change notification settings - Fork 0
/
saphub.py
119 lines (88 loc) · 2.41 KB
/
saphub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python
import datetime, io, os, sys, zipfile
try:
import argparse
except:
print("")
print("The module argparse is not availble on your machine:")
print("- upgrade to python 2.7 or higher, or")
print("- download and install argparse from https://pypi.python.org/pypi/argparse")
print("")
sys.exit()
try:
# python 3.x
from urllib.request import Request
except:
# python 2.x
from urllib2 import Request
try:
# python 3.x
from urllib.request import HTTPHandler
except:
# python 2.x
from urllib2 import HTTPHandler
try:
# python 3.x
from urllib.request import build_opener
except:
# python 2.x
from urllib2 import build_opener
try:
# python 3.x
from urllib.request import urlopen
except:
# python 2.x
from urllib2 import urlopen
try:
# python 3.x
from urlib.request import HTTPError
except:
# python 2.x
from urllib2 import HTTPError
parser = argparse.ArgumentParser(description='Deploy a sap hana application')
parser.add_argument('--host',
help='hana (ip:port)')
parser.add_argument('--usr',
help='hana user')
parser.add_argument('--pwd',
help='hana password')
parser.add_argument('--package',
help='hana package name')
parser.add_argument('--saphub',
help='saphub (ip:port)')
args = parser.parse_args()
DIR = os.getcwd()
HOST = args.host
USER = args.usr
PASS = args.pwd
PACK = args.package
SAPHUB = args.saphub
print("Deploy %s to %s as %s via %s" % (DIR, HOST, PACK, SAPHUB))
kickoff = datetime.datetime.now()
archive = io.BytesIO()
zipfile = zipfile.ZipFile(archive, 'w')
for path, dirs, files in os.walk(DIR):
for file in files:
if os.path.isfile(os.path.join(path, file)):
print("add %s" % os.path.relpath(os.path.join(path, file), DIR))
zipfile.write(os.path.join(path, file), os.path.relpath(os.path.join(path, file), DIR))
zipfile.close()
archive.seek(0)
try:
opener = build_opener(HTTPHandler)
request = Request('http://%s/?host=%s&usr=%s&pwd=%s&package=%s' % (SAPHUB, HOST, USER, PASS, PACK), archive.read())
request.add_header('Content-Type', 'application/zip')
request.get_method = lambda: 'PUT'
response = urlopen(request)
print("")
print(response.read())
print("")
print(datetime.datetime.now() - kickoff)
except HTTPError as u:
print("")
print("SAPHUBD Exception", u.read())
print("")
except Exception as e:
print("")
print("SAPHUBD Exception", e)
print("")