Moved capture management into separate object
This commit is contained in:
parent
1a6088a816
commit
caf553db7a
14 changed files with 302 additions and 227 deletions
|
|
@ -6,8 +6,8 @@ from labthings.server.find import find_component
|
|||
|
||||
from openflexure_microscope.paths import settings_file_path, check_rw
|
||||
from openflexure_microscope.config import OpenflexureSettingsFile
|
||||
from openflexure_microscope.camera.base import BASE_CAPTURE_PATH
|
||||
from openflexure_microscope.camera.capture import build_captures_from_exif
|
||||
from openflexure_microscope.captures.capture_manager import BASE_CAPTURE_PATH
|
||||
from openflexure_microscope.captures.capture import build_captures_from_exif
|
||||
|
||||
from openflexure_microscope.api.utilities.gui import build_gui
|
||||
|
||||
|
|
@ -37,17 +37,17 @@ def get_permissive_locations():
|
|||
]
|
||||
|
||||
|
||||
def get_current_location(camera):
|
||||
return camera.paths.get("default")
|
||||
def get_current_location(capture_manager):
|
||||
return capture_manager.paths.get("default")
|
||||
|
||||
|
||||
def set_current_location(camera, location: str):
|
||||
def set_current_location(capture_manager, location: str):
|
||||
if not os.path.isdir(location):
|
||||
os.makedirs(location)
|
||||
logging.debug("Updating location...")
|
||||
camera.paths.update({"default": location})
|
||||
capture_manager.paths.update({"default": location})
|
||||
logging.debug("Rebuilding captures...")
|
||||
camera.rebuild_captures()
|
||||
capture_manager.rebuild_captures()
|
||||
logging.debug("Capture location changed successfully.")
|
||||
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ class AutostorageExtension(BaseExtension):
|
|||
)
|
||||
|
||||
# We'll store a reference to a camera object, who's capture paths will be modified
|
||||
self.camera = None
|
||||
self.capture_manager = None
|
||||
|
||||
self.initial_location = get_default_location()
|
||||
|
||||
|
|
@ -107,9 +107,9 @@ class AutostorageExtension(BaseExtension):
|
|||
logging.debug(f"Autostorage extension bound to camera {self.camera}")
|
||||
|
||||
# Store a reference to the camera
|
||||
self.camera = microscope_obj.camera
|
||||
self.capture_manager = microscope_obj.captures
|
||||
# Store the initial storage location
|
||||
self.initial_location = get_current_location(self.camera)
|
||||
self.initial_location = get_current_location(self.capture_manager)
|
||||
|
||||
# If preferred path does not exist, or cannot be written to
|
||||
self.check_location(self.initial_location)
|
||||
|
|
@ -118,20 +118,20 @@ class AutostorageExtension(BaseExtension):
|
|||
|
||||
def check_location(self, location=None):
|
||||
if not location:
|
||||
location = get_current_location(self.camera)
|
||||
location = get_current_location(self.capture_manager)
|
||||
# If preferred path does not exist, or cannot be written to
|
||||
if not (os.path.isdir(location) and check_rw(location)):
|
||||
logging.error(
|
||||
f"Preferred capture path {location} is missing or cannot be written to. Restoring defaults."
|
||||
)
|
||||
# Reset the storage location to default
|
||||
set_current_location(self.camera, get_default_location())
|
||||
set_current_location(self.capture_manager, get_default_location())
|
||||
|
||||
def get_locations(self):
|
||||
if self.camera:
|
||||
locations = get_all_locations()
|
||||
|
||||
current_location = get_current_location(self.camera)
|
||||
current_location = get_current_location(self.capture_manager)
|
||||
if current_location not in locations.values():
|
||||
locations.update({"Custom": current_location})
|
||||
# Add location from the cameras settings file
|
||||
|
|
@ -140,7 +140,7 @@ class AutostorageExtension(BaseExtension):
|
|||
return {}
|
||||
|
||||
def get_preferred_key(self):
|
||||
current = get_current_location(self.camera)
|
||||
current = get_current_location(self.capture_manager)
|
||||
locations = self.get_locations()
|
||||
|
||||
matches = [k for k, v in locations.items() if v == current]
|
||||
|
|
@ -157,7 +157,7 @@ class AutostorageExtension(BaseExtension):
|
|||
raise KeyError(f"No location named {new_path_key}")
|
||||
|
||||
location = self.get_locations().get(new_path_key)
|
||||
set_current_location(self.camera, location)
|
||||
set_current_location(self.capture_manager, location)
|
||||
|
||||
def key_to_title(self, path_key: str):
|
||||
if not path_key in self.get_locations().keys():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue