Add more docstrings

This commit is contained in:
Brett Williams
2023-12-16 22:23:02 -06:00
parent f663430984
commit 8863a38904
3 changed files with 129 additions and 22 deletions

View File

@@ -24,7 +24,17 @@ LOOPBACK = '127.0.0.1'
class RenderServerProxy:
"""
The ServerProxy class is responsible for interacting with a remote server.
It provides methods to request data from the server and store the status of the server.
Attributes:
system_cpu (str): The CPU type of the system.
system_cpu_count (int): The number of CPUs in the system.
system_os (str): The operating system of the system.
system_os_version (str): The version of the operating system.
"""
def __init__(self, hostname, server_port="8080"):
self.hostname = hostname
self.port = server_port
@@ -43,6 +53,9 @@ class RenderServerProxy:
self.system_os = None
self.system_os_version = None
def __repr__(self):
return f"<RenderServerProxy - {self.hostname}>"
def connect(self):
return self.status()
@@ -118,8 +131,7 @@ class RenderServerProxy:
self.__jobs_cache_token = status_result['token']
def get_data(self, timeout=5):
all_data = self.request_data('full_status', timeout=timeout)
return all_data
return self.request_data('full_status', timeout=timeout)
def cancel_job(self, job_id, confirm=False):
return self.request_data(f'job/{job_id}/cancel?confirm={confirm}')
@@ -143,12 +155,32 @@ class RenderServerProxy:
return self.request_data('all_engines')
def notify_parent_of_status_change(self, parent_id, subjob):
"""
Notifies the parent job of a status change in a subjob.
Args:
parent_id (str): The ID of the parent job.
subjob (Job): The subjob that has changed status.
Returns:
Response: The response from the server.
"""
hostname = LOOPBACK if self.is_localhost else self.hostname
return requests.post(f'http://{hostname}:{self.port}/api/job/{parent_id}/notify_parent_of_status_change',
json=subjob.json())
def post_job_to_server(self, file_path, job_list, callback=None):
"""
Posts a job to the server.
Args:
file_path (str): The path to the file to upload.
job_list (list): A list of jobs to post.
callback (function, optional): A callback function to call during the upload. Defaults to None.
Returns:
Response: The response from the server.
"""
# bypass uploading file if posting to localhost
if self.is_localhost:
jobs_with_path = [{**item, "local_path": file_path} for item in job_list]
@@ -188,10 +220,30 @@ class RenderServerProxy:
# --- Renderer --- #
def get_renderer_info(self, timeout=5):
"""
Fetches renderer information from the server.
Args:
timeout (int, optional): The number of seconds to wait for a response from the server. Defaults to 5.
Returns:
dict: A dictionary containing the renderer information.
"""
all_data = self.request_data(f'renderer_info', timeout=timeout)
return all_data
def delete_engine(self, engine, version, system_cpu=None):
"""
Sends a request to the server to delete a specific engine.
Args:
engine (str): The name of the engine to delete.
version (str): The version of the engine to delete.
system_cpu (str, optional): The system CPU type. Defaults to None.
Returns:
Response: The response from the server.
"""
form_data = {'engine': engine, 'version': version, 'system_cpu': system_cpu}
hostname = LOOPBACK if self.is_localhost else self.hostname
return requests.post(f'http://{hostname}:{self.port}/api/delete_engine', json=form_data)