Clarify whether name or path is returned in scan directory functions
This commit is contained in:
parent
9b78b4620d
commit
254305a7a5
3 changed files with 23 additions and 21 deletions
|
|
@ -70,10 +70,10 @@ class ScanDirectoryManager:
|
||||||
"""
|
"""
|
||||||
return os.path.join(self._base_scan_dir, scan_name, IMG_DIR_NAME)
|
return os.path.join(self._base_scan_dir, scan_name, IMG_DIR_NAME)
|
||||||
|
|
||||||
def get_file_from(
|
def get_file_path_from(
|
||||||
self, scan_name: str, filename: str, check_exists: bool = False
|
self, scan_name: str, filename: str, check_exists: bool = False
|
||||||
) -> Optional[str]:
|
) -> Optional[str]:
|
||||||
"""Return the file path for the file within a scan directory
|
"""Return the file full path for the file within a scan directory
|
||||||
|
|
||||||
If check_exists is True then None will be returned if the file does
|
If check_exists is True then None will be returned if the file does
|
||||||
not exist.
|
not exist.
|
||||||
|
|
@ -84,10 +84,10 @@ class ScanDirectoryManager:
|
||||||
return None
|
return None
|
||||||
return file_path
|
return file_path
|
||||||
|
|
||||||
def get_file_from_img_dir(
|
def get_file_path_from_img_dir(
|
||||||
self, scan_name: str, filename: str, check_exists: bool = False
|
self, scan_name: str, filename: str, check_exists: bool = False
|
||||||
) -> Optional[str]:
|
) -> Optional[str]:
|
||||||
"""Return the file path for the file within a scan directory
|
"""Return the full file path for the file within a scan directory
|
||||||
|
|
||||||
If check_exists is True, None is returned if the file does not exist. If False
|
If check_exists is True, None is returned if the file does not exist. If False
|
||||||
then the path is returned anyway
|
then the path is returned anyway
|
||||||
|
|
@ -98,15 +98,15 @@ class ScanDirectoryManager:
|
||||||
return None
|
return None
|
||||||
return file_path
|
return file_path
|
||||||
|
|
||||||
def get_final_stitch(self, scan_name: str) -> Optional[str]:
|
def get_final_stitch_path(self, scan_name: str) -> Optional[str]:
|
||||||
"""Return the file full path for the final stitch.
|
"""Return the file full path for the final stitch.
|
||||||
|
|
||||||
If no final stitch is found, return None
|
If no final stitch is found, return None
|
||||||
"""
|
"""
|
||||||
stitch_fname = ScanDirectory(scan_name, self.base_dir).get_final_stitch()
|
stitch_fname = ScanDirectory(scan_name, self.base_dir).get_final_stitch_name()
|
||||||
if stitch_fname is None:
|
if stitch_fname is None:
|
||||||
return None
|
return None
|
||||||
return self.get_file_from_img_dir(scan_name, stitch_fname)
|
return self.get_file_path_from_img_dir(scan_name, stitch_fname)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def all_scans(self) -> list[str]:
|
def all_scans(self) -> list[str]:
|
||||||
|
|
@ -282,7 +282,7 @@ class ScanDirectory:
|
||||||
|
|
||||||
return scan_images, stitches, dzi_files
|
return scan_images, stitches, dzi_files
|
||||||
|
|
||||||
def get_final_stitch(self) -> Optional[str]:
|
def get_final_stitch_name(self) -> Optional[str]:
|
||||||
"""Return the filename for the final stitch (in the images dir)
|
"""Return the filename for the final stitch (in the images dir)
|
||||||
|
|
||||||
If no final stitch is found, return None
|
If no final stitch is found, return None
|
||||||
|
|
|
||||||
|
|
@ -580,7 +580,7 @@ class SmartScanThing(Thing):
|
||||||
|
|
||||||
This endpoint allows files to be downloaded from a scan.
|
This endpoint allows files to be downloaded from a scan.
|
||||||
"""
|
"""
|
||||||
preview_path = self._scan_dir_manager.get_file_from_img_dir(
|
preview_path = self._scan_dir_manager.get_file_path_from_img_dir(
|
||||||
scan_name=scan_name, filename="stitched_thumbnail.jpg", check_exists=True
|
scan_name=scan_name, filename="stitched_thumbnail.jpg", check_exists=True
|
||||||
)
|
)
|
||||||
if preview_path is None:
|
if preview_path is None:
|
||||||
|
|
@ -684,7 +684,7 @@ class SmartScanThing(Thing):
|
||||||
Will only return a file ending in suffix STITCH_SUFFIX
|
Will only return a file ending in suffix STITCH_SUFFIX
|
||||||
Note: when downloading this, the default filename will be `scan_name`.jpeg"""
|
Note: when downloading this, the default filename will be `scan_name`.jpeg"""
|
||||||
|
|
||||||
stitch_path = self._scan_dir_manager.get_final_stitch(scan_name)
|
stitch_path = self._scan_dir_manager.get_final_stitch_path(scan_name)
|
||||||
|
|
||||||
if stitch_path is None:
|
if stitch_path is None:
|
||||||
raise HTTPException(404, "File not found")
|
raise HTTPException(404, "File not found")
|
||||||
|
|
@ -758,7 +758,7 @@ class SmartScanThing(Thing):
|
||||||
if not self.latest_scan_name:
|
if not self.latest_scan_name:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return self._scan_dir_manager.get_file_from_img_dir(
|
return self._scan_dir_manager.get_file_path_from_img_dir(
|
||||||
scan_name=self.latest_scan_name, filename="preview.jpg", check_exists=True
|
scan_name=self.latest_scan_name, filename="preview.jpg", check_exists=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -899,7 +899,7 @@ class SmartScanThing(Thing):
|
||||||
Note that as this is a thing_action it needs the logger passed as
|
Note that as this is a thing_action it needs the logger passed as
|
||||||
a variable if called from another thing action
|
a variable if called from another thing action
|
||||||
"""
|
"""
|
||||||
json_fpath = self._scan_dir_manager.get_file_from_img_dir(
|
json_fpath = self._scan_dir_manager.get_file_path_from_img_dir(
|
||||||
scan_name=scan_name, filename=SCAN_DATA_FILENAME
|
scan_name=scan_name, filename=SCAN_DATA_FILENAME
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,17 +122,19 @@ def test_basic_directory_operations():
|
||||||
assert scan_dir_manager.img_dir_for(scan_name) == scan_im_dir
|
assert scan_dir_manager.img_dir_for(scan_name) == scan_im_dir
|
||||||
|
|
||||||
# Get the path of a fake file
|
# Get the path of a fake file
|
||||||
fake_file = scan_dir_manager.get_file_from(scan_name, "foo.zip")
|
fake_file = scan_dir_manager.get_file_path_from(scan_name, "foo.zip")
|
||||||
assert fake_file == os.path.join(scan_path, "foo.zip")
|
assert fake_file == os.path.join(scan_path, "foo.zip")
|
||||||
# But this is none if we check it exists
|
# But this is none if we check it exists
|
||||||
fake_file = scan_dir_manager.get_file_from(scan_name, "foo.zip", check_exists=True)
|
fake_file = scan_dir_manager.get_file_path_from(
|
||||||
|
scan_name, "foo.zip", check_exists=True
|
||||||
|
)
|
||||||
assert fake_file is None
|
assert fake_file is None
|
||||||
|
|
||||||
# Get the path of another fake file
|
# Get the path of another fake file
|
||||||
fake_file = scan_dir_manager.get_file_from_img_dir(scan_name, "bar.img")
|
fake_file = scan_dir_manager.get_file_path_from_img_dir(scan_name, "bar.img")
|
||||||
assert fake_file == os.path.join(scan_im_dir, "bar.img")
|
assert fake_file == os.path.join(scan_im_dir, "bar.img")
|
||||||
# But this is none if we check it exists
|
# But this is none if we check it exists
|
||||||
fake_file = scan_dir_manager.get_file_from_img_dir(
|
fake_file = scan_dir_manager.get_file_path_from_img_dir(
|
||||||
scan_name, "bar.img", check_exists=True
|
scan_name, "bar.img", check_exists=True
|
||||||
)
|
)
|
||||||
assert fake_file is None
|
assert fake_file is None
|
||||||
|
|
@ -268,11 +270,11 @@ def test_get_final_stitch():
|
||||||
_add_fake_image(scan_dir)
|
_add_fake_image(scan_dir)
|
||||||
|
|
||||||
# No scans, so None should be returned, from both manager and scan dir
|
# No scans, so None should be returned, from both manager and scan dir
|
||||||
assert scan_dir_manager.get_final_stitch(scan_dir.name) is None
|
assert scan_dir_manager.get_final_stitch_path(scan_dir.name) is None
|
||||||
assert scan_dir.get_final_stitch() is None
|
assert scan_dir.get_final_stitch_name() is None
|
||||||
|
|
||||||
fake_scan_name = "fake_scan_0001_stitched.jpg"
|
fake_scan_name = "fake_scan_0001_stitched.jpg"
|
||||||
fake_scan_path = scan_dir_manager.get_file_from_img_dir(
|
fake_scan_path = scan_dir_manager.get_file_path_from_img_dir(
|
||||||
scan_name=scan_dir.name,
|
scan_name=scan_dir.name,
|
||||||
filename="fake_scan_0001_stitched.jpg",
|
filename="fake_scan_0001_stitched.jpg",
|
||||||
check_exists=False,
|
check_exists=False,
|
||||||
|
|
@ -280,9 +282,9 @@ def test_get_final_stitch():
|
||||||
# Add a fake scan
|
# Add a fake scan
|
||||||
_add_fake_file(scan_dir, fake_scan_name, in_im_dir=True)
|
_add_fake_file(scan_dir, fake_scan_name, in_im_dir=True)
|
||||||
# Manager returns full path
|
# Manager returns full path
|
||||||
assert scan_dir_manager.get_final_stitch(scan_dir.name) == fake_scan_path
|
assert scan_dir_manager.get_final_stitch_path(scan_dir.name) == fake_scan_path
|
||||||
# ScanDirectory object returns just the filename
|
# ScanDirectory object returns just the filename
|
||||||
assert scan_dir.get_final_stitch() == fake_scan_name
|
assert scan_dir.get_final_stitch_name() == fake_scan_name
|
||||||
|
|
||||||
|
|
||||||
def test_empty_scan_info():
|
def test_empty_scan_info():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue