Skip to content

Commit

Permalink
STY: Fix pep8 issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
hhslepicka committed Jan 13, 2024
1 parent 1e6a3b2 commit eb0eced
Showing 1 changed file with 49 additions and 16 deletions.
65 changes: 49 additions & 16 deletions botcity/maestro/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ def login(self, server: Optional[str] = None, login: Optional[str] = None, key:
data = {"login": self.organization, "key": self._key}
headers = {'Content-Type': 'application/json'}

with requests.post(url, data=json.dumps(data), headers=headers, timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, data=json.dumps(data), headers=headers, timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if req.ok:
self.access_token = req.json()['accessToken']
else:
Expand Down Expand Up @@ -319,7 +321,9 @@ def alert(self, task_id: str, title: str, message: str, alert_type: model.AlertT
data = {"taskId": task_id, "title": title,
"message": message, "type": alert_type}

with requests.post(url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if req.ok:
return model.ServerMessage.from_json(req.text)
else:
Expand Down Expand Up @@ -350,7 +354,9 @@ def message(self, email: List[str], users: List[str], subject: str, body: str,

data = {"emails": email, "logins": users, "subject": subject, "body": body,
"type": msg_type, "group": group}
with requests.post(url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if req.status_code != 200:
raise ValueError(
'Error during message. Server returned %d. %s' %
Expand Down Expand Up @@ -387,7 +393,9 @@ def create_task(self, activity_label: str, parameters: Dict[str, object],
data["minExecutionDate"] = min_execution_date.isoformat()

headers = self._headers()
with requests.post(url, json=data, headers=headers, timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, json=data, headers=headers, timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if req.ok:
return model.AutomationTask.from_json(req.text)
else:
Expand Down Expand Up @@ -521,7 +529,9 @@ def new_log(self, activity_label: str, columns: List[model.Column]) -> model.Ser
cols = [asdict(c) for c in columns]

data = {"activityLabel": activity_label, "columns": cols, 'organizationLabel': self.organization}
with requests.post(url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if req.ok:
return model.ServerMessage.from_json(req.text)
else:
Expand All @@ -546,7 +556,9 @@ def new_log_entry(self, activity_label: str, values: Dict[str, object]) -> model
"""
url = f'{self._server}/api/v2/log/{activity_label}/entry'

with requests.post(url, json=values, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, json=values, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if req.status_code != 200:
try:
message = 'Error during new log entry. Server returned %d. %s' % (
Expand Down Expand Up @@ -586,7 +598,9 @@ def get_log(self, activity_label: str, date: Optional[str] = "") -> List[Dict[st
url = f'{self._server}/api/v2/log/{activity_label}/entry-list'

data = {"days": days}
with requests.get(url, params=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as entry_req:
with requests.get(
url, params=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as entry_req:
if entry_req.ok:
log_data = []
for en in entry_req.json():
Expand Down Expand Up @@ -660,7 +674,9 @@ def post_artifact(self, task_id: int, artifact_name: str, filepath: str) -> mode
fields={'file': (artifact_name, f)}
)
headers = {**self._headers(), 'Content-Type': data.content_type}
with requests.post(url, data=data, headers=headers, timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, data=data, headers=headers, timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if req.ok:
return artifact_id
else:
Expand All @@ -687,7 +703,9 @@ def _create_artifact(self, task_id: int, name: str, filename: str) -> model.Serv
"""
url = f'{self._server}/api/v2/artifact'
data = {'taskId': task_id, 'name': name, 'filename': filename}
with requests.post(url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if req.ok:
return model.ServerMessage.from_json(req.text)
else:
Expand All @@ -714,7 +732,9 @@ def list_artifacts(self, days: int = 7) -> List[model.Artifact]:
response = [model.Artifact.from_dict(a) for a in content]
for page in range(1, req.json()['totalPages']):
url = f'{self._server}/api/v2/artifact?size=5&page={page}&sort=dateCreation,desc&days={days}'
with requests.get(url, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.get(
url, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
content = req.json()['content']
response.extend([model.Artifact.from_dict(a) for a in content])
return response
Expand Down Expand Up @@ -745,7 +765,9 @@ def get_artifact(self, artifact_id: int) -> Tuple[str, bytes]:
filename = payload['fileName']

url = f'{self.server}/api/v2/artifact/{artifact_id}/file'
with requests.get(url, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req_file:
with requests.get(
url, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req_file:
file_content = req_file.content

return filename, file_content
Expand Down Expand Up @@ -790,7 +812,9 @@ def error(self, task_id: int, exception: Exception, screenshot: Optional[str] =
'stackTrace': trace, 'language': 'PYTHON', 'tags': tags}

response = None
with requests.post(url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if req.status_code == 201:
response = req.json()
else:
Expand Down Expand Up @@ -871,7 +895,10 @@ def _create_screenshot(self, error_id: int, filepath: str) -> None:
headers = self._headers()
headers['Content-Type'] = data_screenshot.content_type

with requests.post(url_screenshot, data=data_screenshot, headers=headers, timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url_screenshot, data=data_screenshot, headers=headers,
timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if not req.ok:
try:
message = 'Error during new log entry. Server returned %d. %s' % (
Expand All @@ -897,7 +924,9 @@ def _create_attachment(self, error_id: int, filename: str, buffer: IOBase):
)
headers = self._headers()
headers['Content-Type'] = file.content_type
with requests.post(url_attachments, data=file, headers=headers, timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url_attachments, data=file, headers=headers, timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if not req.ok:
try:
message = 'Error during new log entry. Server returned %d. %s' % (
Expand Down Expand Up @@ -954,7 +983,9 @@ def create_credential(self, label: str, key: str, value):
'value': value
}
url = f'{self._server}/api/v2/credential/{label}/key'
with requests.post(url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if not req.ok:
req.raise_for_status()

Expand Down Expand Up @@ -983,7 +1014,9 @@ def _create_credential_by_label(self, label: str, key: str, value):
}
url = f'{self._server}/api/v2/credential'

with requests.post(url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT) as req:
with requests.post(
url, json=data, headers=self._headers(), timeout=self._timeout, verify=self.VERIFY_SSL_CERT
) as req:
if req.ok:
return model.ServerMessage.from_json(req.text)
else:
Expand Down

0 comments on commit eb0eced

Please sign in to comment.