Skip to content

Commit

Permalink
Improve request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jlorrain authored and ClementHector committed Feb 7, 2022
1 parent e477a7d commit ceb3cd2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
30 changes: 23 additions & 7 deletions openpype/modules/default_modules/shotgrid/lib/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@
from openpype_modules.shotgrid.lib import settings as settings_lib


def _format_url(url: str) -> str:
if not url.startswith('http://') or not url.startswith('https://'):
return "http://" + url
return url


def poll_server() -> int:
module_url = settings_lib.get_module_server_url()
module_url = _format_url(settings_lib.get_module_server_url())
url = "/".join([module_url, "docs"])
res = requests.get(url)
try:
res = requests.get(url)
except requests.exceptions.RequestException:
return 404
return res.status_code


def check_batch_settings(project: str, settings: Dict[str, any]) -> bool:
module_url = settings_lib.get_module_server_url()
module_url = _format_url(settings_lib.get_module_server_url())
url = "/".join([module_url, "batch", project, "check"])
params = {
"shotgrid_url": settings.get("auth", {}).get("project_shotgrid_url"),
Expand All @@ -24,7 +33,10 @@ def check_batch_settings(project: str, settings: Dict[str, any]) -> bool:
),
}

res = requests.get(url, params=params)
try:
res = requests.get(url, params=params)
except requests.exceptions.RequestException:
return False

if res.status_code == 200:
return res.json().get("status", "KO") == "OK"
Expand All @@ -36,7 +48,7 @@ def send_batch_request(
project: str, settings: Dict[str, any], override: bool
) -> int:

module_url = settings_lib.get_module_server_url()
module_url = _format_url(settings_lib.get_module_server_url())
url = "/".join([module_url, "batch", project])
payload = {
"shotgrid_url": settings.get("auth", {}).get("project_shotgrid_url"),
Expand All @@ -47,9 +59,13 @@ def send_batch_request(
"script_key": settings.get("auth", {}).get(
"project_shotgrid_script_key"
),
"override": override,
"overwrite": override,
"fields_mapping": settings.get("fields", {}),
}

res = requests.post(url, json=payload)
try:
res = requests.post(url, json=payload)
except requests.exceptions.RequestException:
return 404

return res.status_code
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, module, parent=None):

self.setWindowTitle("OpenPype - Shotgrid Batch")

icon = QtGui.QIcon(resources.pype_icon_filepath())
icon = QtGui.QIcon(resources.get_resource("app_icons/shotgrid.png"))
self.setWindowIcon(icon)

self.setWindowFlags(
Expand Down
Binary file added openpype/resources/app_icons/shotgrid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ceb3cd2

Please sign in to comment.