-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhamr.py
52 lines (36 loc) · 1.43 KB
/
hamr.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
import requests
HAMR_URL = "https://hamr.rajdhani.pipal.in"
class HamrError(Exception):
pass
class Hamr:
def __init__(self, server_url):
self.server_url = server_url
def create_app(self, app_name, git_url):
url = f"{self.server_url}/apps/create"
r = requests.post(url, data={"app_name": app_name, "git_url": git_url})
if not r.ok:
message = f"Create Request to Hamr API failed with status code {r.status_code}"
try:
data = r.json()
except requests.exceptions.JSONDecodeError:
pass
else:
error_status, error_msg = data["status"], data.get("message", "")
message += f"\nstatus: {error_status}\nmessage: {error_msg}"
raise HamrError(message)
return True
def sync_app(self, app_name):
url = f"{self.server_url}/apps/{app_name}/deploy"
r = requests.post(url)
if not r.ok:
message = f"Deploy Request to Hamr API failed with status code {r.status_code}"
try:
data = r.json()
except requests.exceptions.JSONDecodeError:
pass
else:
error_status, error_msg = data["status"], data.get("message", "")
message += f"\nstatus: {error_status}\nmessage: {error_msg}"
raise HamrError(message)
return True
hamr = Hamr(HAMR_URL)