Apply suggestions from code review of branch split-scan-dir-operations

Co-authored-by: Beth Probert <beth_probert@outlook.com>
This commit is contained in:
Julian Stirling 2025-06-30 15:30:05 +00:00
parent a6e48f8882
commit ad838e8643
7 changed files with 55 additions and 43 deletions

View file

@ -35,7 +35,7 @@ class ScanInfo(BaseModel):
class ScanDirectoryManager:
"""
A class for managinging interactions with scan directories
A class for managing interactions with scan directories
"""
_base_scan_dir: str
@ -57,7 +57,7 @@ class ScanDirectoryManager:
def path_for(self, scan_name: str) -> str:
"""Return the path for a given scan name
Returns the path even if it doesn't exist)
Returns the path even if it doesn't exist
"""
return os.path.join(self._base_scan_dir, scan_name)
@ -97,7 +97,7 @@ class ScanDirectoryManager:
return file_path
@property
def all_scans(self):
def all_scans(self) -> list[str]:
"""Return a list of the scan names in the base directory"""
return [f.name for f in os.scandir(self._base_scan_dir) if f.is_dir()]
@ -138,11 +138,11 @@ class ScanDirectoryManager:
return f"{scan_name}_{scan_num:0{SCAN_ZERO_PAD_DIGITS}d}"
def new_scan_dir(self, scan_name: str) -> str:
def new_scan_dir(self, scan_name: str) -> "ScanDirectory":
"""Get a unique name for this scan and create a directory for it
The scan will be named `{scan_name}_0001` where the number is
zero-padded to be 4 digits long (to allow correct sorting if the
zero-padded to be SCAN_ZERO_PAD_DIGITS digits long (to allow correct sorting if the
scans are ordered alphanumerically).
Creates a new empty folder, into which scans are saved
@ -161,11 +161,11 @@ class ScanDirectoryManager:
os.makedirs(self.img_dir_for(full_scan_name))
return ScanDirectory(full_scan_name, self.base_dir)
def delete_scan(self, scan_name: str):
def delete_scan(self, scan_name: str) -> None:
"""Delete a scan"""
shutil.rmtree(self.path_for(scan_name))
def zip_scan(self, scan_name: str, final_version: bool = False) -> str:
def zip_scan(self, scan_name: str, final_version: bool = False) -> "ScanDirectory":
"""Zips any images from the scan not yet zipped, return full path to zip
`final_version` Set true to stitch all files not just the scan images
@ -213,7 +213,7 @@ class ScanDirectory:
)
@property
def name(self):
def name(self) -> str:
"""The name of the scan"""
return self._name
@ -249,7 +249,7 @@ class ScanDirectory:
return max(os.stat(root).st_mtime for root, _, _ in os.walk(self.dir_path))
def scan_info(self):
"""Return the inforomation for the scan directory as a ScanInfo object"""
"""Return the information for the scan directory as a ScanInfo object"""
folder_contents = self.get_scan_files()
if folder_contents:
scan_images = [i for i in folder_contents if IMAGE_REGEX.search(i)]

View file

@ -155,7 +155,7 @@ class SmartScanThing(Thing):
if self._scan_data is not None:
self._return_to_starting_position()
if not isinstance(e, scan_directories.NotEnoughFreeSpaceError):
# Don't stich if drive is full (already logged)
# Don't stitch if drive is full (already logged)
self._perform_final_stitch()
# Error must be raised so UI gives correct output
raise e
@ -671,7 +671,7 @@ class SmartScanThing(Thing):
"scans/{scan_name}",
responses={
200: {"description": "Successfully deleted scan"},
400: {"description": "Scan not deleted does"},
400: {"description": "An error occurred while trying to delete scan"},
},
)
def delete_scan(self, scan_name: str, logger: InvocationLogger) -> None:
@ -744,7 +744,7 @@ class SmartScanThing(Thing):
This will return None (`null` to JS) if there is no preview image to return.
This is used for two things reasons:
This is used for two reasons:
1. If all caching was turned off this stitch would be sent over the network
repeatedly
2. If caching was is on, then the stitch will not update when needed.