mirror of
https://github.com/blw1138/Zordon.git
synced 2026-06-09 21:49:23 -05:00
Windows path fixes (#129)
* Change uses of os.path to use Pathlib * Add return types and type hints * Add more docstrings * Add missing import to api_server
This commit is contained in:
@@ -3,6 +3,7 @@ import logging
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
from requests_toolbelt.multipart import MultipartEncoder, MultipartEncoderMonitor
|
||||
@@ -184,12 +185,12 @@ class RenderServerProxy:
|
||||
# Job Lifecycle:
|
||||
# --------------------------------------------
|
||||
|
||||
def post_job_to_server(self, file_path, job_data, callback=None):
|
||||
def post_job_to_server(self, file_path: Path, job_data, callback=None):
|
||||
"""
|
||||
Posts a job to the server.
|
||||
|
||||
Args:
|
||||
file_path (str): The path to the file to upload.
|
||||
file_path (Path): The path to the file to upload.
|
||||
job_data (dict): A dict of jobs data.
|
||||
callback (function, optional): A callback function to call during the upload. Defaults to None.
|
||||
|
||||
@@ -197,12 +198,12 @@ class RenderServerProxy:
|
||||
Response: The response from the server.
|
||||
"""
|
||||
# Check if file exists
|
||||
if not os.path.exists(file_path):
|
||||
if not file_path.exists():
|
||||
raise FileNotFoundError(f"File not found: {file_path}")
|
||||
|
||||
# Bypass uploading file if posting to localhost
|
||||
if self.is_localhost:
|
||||
job_data['local_path'] = file_path
|
||||
job_data['local_path'] = str(file_path)
|
||||
url = urljoin(f'http://{self.hostname}:{self.port}', '/api/add_job')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
return requests.post(url, data=json.dumps(job_data), headers=headers)
|
||||
@@ -210,7 +211,7 @@ class RenderServerProxy:
|
||||
# Prepare the form data for remote host
|
||||
with open(file_path, 'rb') as file:
|
||||
encoder = MultipartEncoder({
|
||||
'file': (os.path.basename(file_path), file, 'application/octet-stream'),
|
||||
'file': (file_path.name, file, 'application/octet-stream'),
|
||||
'json': (None, json.dumps(job_data), 'application/json'),
|
||||
})
|
||||
|
||||
@@ -247,7 +248,7 @@ class RenderServerProxy:
|
||||
# Engines:
|
||||
# --------------------------------------------
|
||||
|
||||
def get_engine_for_filename(self, filename, timeout=5):
|
||||
def get_engine_for_filename(self, filename:str, timeout=5):
|
||||
response = self.request(f'engine_for_filename?filename={os.path.basename(filename)}', timeout)
|
||||
return response.text
|
||||
|
||||
|
||||
Reference in New Issue
Block a user