mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
Added file_exists_in_mounts method to look for projects on connected network mounts
This commit is contained in:
@@ -11,7 +11,7 @@ from PIL import Image, ImageTk
|
|||||||
from lib.client.new_job_window import NewJobWindow
|
from lib.client.new_job_window import NewJobWindow
|
||||||
from lib.server.server_proxy import RenderServerProxy
|
from lib.server.server_proxy import RenderServerProxy
|
||||||
from lib.server.zeroconf_server import ZeroconfServer
|
from lib.server.zeroconf_server import ZeroconfServer
|
||||||
from lib.utilities.misc_helper import launch_url
|
from lib.utilities.misc_helper import launch_url, file_exists_in_mounts
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
@@ -99,19 +99,23 @@ class DashboardWindow:
|
|||||||
button_frame.pack(pady=5, fill=tk.BOTH, expand=True)
|
button_frame.pack(pady=5, fill=tk.BOTH, expand=True)
|
||||||
|
|
||||||
# Create buttons
|
# Create buttons
|
||||||
logs_button = tk.Button(button_frame, text="Logs", command=self.open_logs)
|
self.logs_button = tk.Button(button_frame, text="Logs", command=self.open_logs)
|
||||||
finder_button = tk.Button(button_frame, text="Reveal in Finder", command=self.reveal_in_finder)
|
self.show_files_button = tk.Button(button_frame, text="Show Files", command=self.show_files)
|
||||||
self.stop_button = tk.Button(button_frame, text="Stop", command=self.stop_job)
|
self.stop_button = tk.Button(button_frame, text="Stop", command=self.stop_job)
|
||||||
delete_button = tk.Button(button_frame, text="Delete", command=self.delete_job)
|
self.delete_button = tk.Button(button_frame, text="Delete", command=self.delete_job)
|
||||||
add_job_button = tk.Button(button_frame, text="Add Job", command=self.show_new_job_window)
|
add_job_button = tk.Button(button_frame, text="Add Job", command=self.show_new_job_window)
|
||||||
|
|
||||||
self.stop_button.config(state='disabled')
|
self.stop_button.config(state='disabled')
|
||||||
|
|
||||||
# Pack the buttons in the frame
|
# Pack the buttons in the frame
|
||||||
self.stop_button.pack(side=tk.LEFT)
|
self.stop_button.pack(side=tk.LEFT)
|
||||||
delete_button.pack(side=tk.LEFT)
|
self.stop_button.config(state='disabled')
|
||||||
finder_button.pack(side=tk.LEFT)
|
self.delete_button.pack(side=tk.LEFT)
|
||||||
logs_button.pack(side=tk.LEFT)
|
self.delete_button.config(state='disabled')
|
||||||
|
self.show_files_button.pack(side=tk.LEFT)
|
||||||
|
self.show_files_button.config(state='disabled')
|
||||||
|
self.logs_button.pack(side=tk.LEFT)
|
||||||
|
self.logs_button.config(state='disabled')
|
||||||
add_job_button.pack(side=tk.RIGHT)
|
add_job_button.pack(side=tk.RIGHT)
|
||||||
|
|
||||||
# Start the Tkinter event loop
|
# Start the Tkinter event loop
|
||||||
@@ -211,14 +215,25 @@ class DashboardWindow:
|
|||||||
|
|
||||||
# update button status
|
# update button status
|
||||||
job = next((d for d in self.job_cache if d.get('id') == job_id), None)
|
job = next((d for d in self.job_cache if d.get('id') == job_id), None)
|
||||||
button_state = 'normal' if job and job['status'] == 'running' else 'disabled'
|
stop_button_state = 'normal' if job and job['status'] == 'running' else 'disabled'
|
||||||
self.stop_button.config(state=button_state)
|
self.stop_button.config(state=stop_button_state)
|
||||||
|
|
||||||
def reveal_in_finder(self):
|
generic_button_state = 'normal' if job else 'disabled'
|
||||||
|
self.show_files_button.config(state=generic_button_state)
|
||||||
|
self.delete_button.config(state=generic_button_state)
|
||||||
|
self.logs_button.config(state=generic_button_state)
|
||||||
|
|
||||||
|
def show_files(self):
|
||||||
|
output_path = None
|
||||||
if self.selected_job_ids():
|
if self.selected_job_ids():
|
||||||
job = next((d for d in self.job_cache if d.get('id') == self.selected_job_ids()[0]), None)
|
job = next((d for d in self.job_cache if d.get('id') == self.selected_job_ids()[0]), None)
|
||||||
output_dir = os.path.dirname(job['output_path'])
|
output_path = os.path.dirname(job['output_path']) # check local filesystem
|
||||||
launch_url(output_dir)
|
if not os.path.exists(output_path):
|
||||||
|
output_path = file_exists_in_mounts(output_path) # check any attached network shares
|
||||||
|
if output_path:
|
||||||
|
launch_url(output_path)
|
||||||
|
else:
|
||||||
|
messagebox.showerror("File Not Found", "The file could not be found. Check your network mounts.")
|
||||||
|
|
||||||
def open_logs(self):
|
def open_logs(self):
|
||||||
if self.selected_job_ids():
|
if self.selected_job_ids():
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
@@ -13,3 +14,44 @@ def launch_url(url):
|
|||||||
subprocess.run(['start', url]) # windows - need to validate this works
|
subprocess.run(['start', url]) # windows - need to validate this works
|
||||||
else:
|
else:
|
||||||
logger.error(f"No valid launchers found to launch url: {url}")
|
logger.error(f"No valid launchers found to launch url: {url}")
|
||||||
|
|
||||||
|
|
||||||
|
def file_exists_in_mounts(filepath):
|
||||||
|
"""
|
||||||
|
Check if a file exists in any mounted directory.
|
||||||
|
It searches for the file in common mount points like '/Volumes', '/mnt', and '/media'.
|
||||||
|
Returns the path to the file in the mount if found, otherwise returns None.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
Before: filepath = '/path/to/file.txt'
|
||||||
|
After: '/Volumes/ExternalDrive/path/to/file.txt'
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_path_components(path):
|
||||||
|
path = os.path.normpath(path)
|
||||||
|
components = []
|
||||||
|
while True:
|
||||||
|
path, component = os.path.split(path)
|
||||||
|
if component:
|
||||||
|
components.append(component)
|
||||||
|
else:
|
||||||
|
if path:
|
||||||
|
components.append(path)
|
||||||
|
break
|
||||||
|
components.reverse()
|
||||||
|
return components
|
||||||
|
|
||||||
|
# Get path components of the directory of the file
|
||||||
|
path_components = get_path_components(os.path.dirname(filepath).strip('/'))
|
||||||
|
|
||||||
|
# Iterate over possible root paths - this may need to be rethought for Windows support
|
||||||
|
for root in ['/Volumes', '/mnt', '/media']:
|
||||||
|
if os.path.exists(root):
|
||||||
|
# Iterate over mounts in the root path
|
||||||
|
for mount in os.listdir(root):
|
||||||
|
# Since we don't know the home directory, we iterate until we find matching parts of the path
|
||||||
|
matching_components = [s for s in path_components if s in mount]
|
||||||
|
for component in matching_components:
|
||||||
|
possible_mount_path = os.path.join(root, mount, filepath.split(component)[-1].lstrip('/'))
|
||||||
|
if os.path.exists(possible_mount_path):
|
||||||
|
return possible_mount_path
|
||||||
|
|||||||
Reference in New Issue
Block a user