Add punctuation to docstrings
This commit is contained in:
parent
4dc41bb008
commit
80beeea07b
34 changed files with 232 additions and 235 deletions
|
|
@ -20,7 +20,7 @@ class NotEnoughFreeSpaceError(IOError):
|
|||
|
||||
|
||||
class ScanInfo(BaseModel):
|
||||
"""Summary information about a scan folder"""
|
||||
"""Summary information about a scan folder."""
|
||||
|
||||
name: str
|
||||
created: float
|
||||
|
|
@ -31,7 +31,7 @@ class ScanInfo(BaseModel):
|
|||
|
||||
|
||||
class ScanDirectoryManager:
|
||||
"""A class for managing interactions with scan directories"""
|
||||
"""A class for managing interactions with scan directories."""
|
||||
|
||||
_base_scan_dir: str
|
||||
|
||||
|
|
@ -42,22 +42,22 @@ class ScanDirectoryManager:
|
|||
|
||||
@property
|
||||
def base_dir(self) -> str:
|
||||
"""The base directory scans are saved to"""
|
||||
"""The base directory scans are saved to."""
|
||||
return self._base_scan_dir
|
||||
|
||||
def exists(self, scan_name: str) -> bool:
|
||||
"""Return True if scan of this name exists on disk"""
|
||||
"""Return True if scan of this name exists on disk."""
|
||||
return os.path.isdir(self.path_for(scan_name))
|
||||
|
||||
def path_for(self, scan_name: str) -> str:
|
||||
"""Return the path for a given scan name
|
||||
"""Return the path for a given scan name.
|
||||
|
||||
Returns the path even if it doesn't exist
|
||||
"""
|
||||
return os.path.join(self._base_scan_dir, scan_name)
|
||||
|
||||
def img_dir_for(self, scan_name: str) -> str:
|
||||
"""Return the path for the image dir for a given scan name
|
||||
"""Return the path for the image dir for a given scan name.
|
||||
|
||||
Returns the path even if it doesn't exist
|
||||
"""
|
||||
|
|
@ -66,7 +66,7 @@ class ScanDirectoryManager:
|
|||
def get_file_path_from(
|
||||
self, scan_name: str, filename: str, check_exists: bool = False
|
||||
) -> Optional[str]:
|
||||
"""Return the full 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 then None will be returned if the file does
|
||||
not exist.
|
||||
|
|
@ -80,7 +80,7 @@ class ScanDirectoryManager:
|
|||
def get_file_path_from_img_dir(
|
||||
self, scan_name: str, filename: str, check_exists: bool = False
|
||||
) -> Optional[str]:
|
||||
"""Return the full 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
|
||||
then the path is returned anyway
|
||||
|
|
@ -103,18 +103,18 @@ class ScanDirectoryManager:
|
|||
|
||||
@property
|
||||
def all_scans(self) -> list[str]:
|
||||
"""Return a list of the scan names in the base directory"""
|
||||
"""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()]
|
||||
|
||||
def all_scans_info(self) -> list[ScanInfo]:
|
||||
"""Return a lists of ScanInfo objects for each scan"""
|
||||
"""Return a lists of ScanInfo objects for each scan."""
|
||||
all_info: list[ScanInfo] = []
|
||||
for scan_name in self.all_scans:
|
||||
all_info.append(ScanDirectory(scan_name, self.base_dir).scan_info())
|
||||
return all_info
|
||||
|
||||
def _unique_scan_name(self, scan_name: str) -> str:
|
||||
"""Get the next unique scan name starting with the given name
|
||||
"""Get the next unique scan name starting with the given name.
|
||||
|
||||
For more explanation on the scan naming see `new_scan_dir`
|
||||
"""
|
||||
|
|
@ -143,7 +143,7 @@ class ScanDirectoryManager:
|
|||
return f"{scan_name}_{scan_num:0{SCAN_ZERO_PAD_DIGITS}d}"
|
||||
|
||||
def new_scan_dir(self, scan_name: str) -> "ScanDirectory":
|
||||
"""Get a unique name for this scan and create a directory for it
|
||||
"""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 SCAN_ZERO_PAD_DIGITS digits long (to allow correct sorting if the
|
||||
|
|
@ -165,11 +165,11 @@ class ScanDirectoryManager:
|
|||
return ScanDirectory(full_scan_name, self.base_dir)
|
||||
|
||||
def delete_scan(self, scan_name: str) -> None:
|
||||
"""Delete a scan"""
|
||||
"""Delete a scan."""
|
||||
shutil.rmtree(self.path_for(scan_name))
|
||||
|
||||
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
|
||||
"""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
|
||||
this should only be done at the end as it is not possible to update a file
|
||||
|
|
@ -178,7 +178,7 @@ class ScanDirectoryManager:
|
|||
return ScanDirectory(scan_name, self.base_dir).zip_files(final_version)
|
||||
|
||||
def check_free_disk_space(self, min_space: int = 500000000) -> None:
|
||||
"""Raise an exception if there is not enough free disk space to continue scanning
|
||||
"""Raise an exception if there is not enough free disk space to continue scanning.
|
||||
|
||||
:param min_space: the minimum space required in bytes.
|
||||
Default = 500,000,000 (500MB)
|
||||
|
|
@ -194,7 +194,7 @@ class ScanDirectoryManager:
|
|||
|
||||
|
||||
class ScanDirectory:
|
||||
"""A class for handling interactions with scan directories
|
||||
"""A class for handling interactions with scan directories.
|
||||
|
||||
Initalisation parameters:
|
||||
name: the name of the scan (the scan directory basename)
|
||||
|
|
@ -214,12 +214,12 @@ class ScanDirectory:
|
|||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""The name of the scan"""
|
||||
"""The name of the scan."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def dir_path(self) -> str:
|
||||
"""The full path to the scan directory"""
|
||||
"""The full path to the scan directory."""
|
||||
return os.path.join(self._base_scan_dir, self._name)
|
||||
|
||||
@property
|
||||
|
|
@ -235,17 +235,17 @@ class ScanDirectory:
|
|||
|
||||
@property
|
||||
def created_time(self) -> float:
|
||||
"""The time the directory was created on disk"""
|
||||
"""The time the directory was created on disk."""
|
||||
return os.path.getctime(self.dir_path)
|
||||
|
||||
def get_scan_files(self):
|
||||
"""Return a list of the files in the images dir"""
|
||||
"""Return a list of the files in the images dir."""
|
||||
if self.images_dir is None:
|
||||
return []
|
||||
return os.listdir(self.images_dir)
|
||||
|
||||
def _extract_scan_images(self, file_list: list[str]):
|
||||
"""Extract files which match the naming convention for scan images
|
||||
"""Extract files which match the naming convention for scan images.
|
||||
|
||||
:param file_list: The list of files to search. Normally this would be
|
||||
``self.get_scan_files()``
|
||||
|
|
@ -255,7 +255,7 @@ class ScanDirectory:
|
|||
return [i for i in file_list if IMAGE_REGEX.search(i)]
|
||||
|
||||
def _extract_final_stitches(self, file_list: list[str]):
|
||||
"""Extract files which match the naming convention for final stitches
|
||||
"""Extract files which match the naming convention for final stitches.
|
||||
|
||||
:param file_list: The list of files to search.
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ class ScanDirectory:
|
|||
return [i for i in file_list if STITCH_REGEX.search(i)]
|
||||
|
||||
def _extract_dzi_files(self, file_list: list[str]):
|
||||
"""Extract files which match the naming convention for dzi_files
|
||||
"""Extract files which match the naming convention for dzi_files.
|
||||
|
||||
:param file_list: The list of files to search.
|
||||
|
||||
|
|
@ -273,7 +273,7 @@ class ScanDirectory:
|
|||
return [i for i in file_list if i.endswith("dzi")]
|
||||
|
||||
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
|
||||
"""
|
||||
|
|
@ -283,11 +283,11 @@ class ScanDirectory:
|
|||
return stitches[0]
|
||||
|
||||
def get_modified_time(self) -> float:
|
||||
"""Return the modified time of the directory"""
|
||||
"""Return the modified time of the directory."""
|
||||
return max(os.stat(root).st_mtime for root, _, _ in os.walk(self.dir_path))
|
||||
|
||||
def scan_info(self) -> ScanInfo:
|
||||
"""Return the information for the scan directory as a ScanInfo object"""
|
||||
"""Return the information for the scan directory as a ScanInfo object."""
|
||||
scan_files = self.get_scan_files()
|
||||
scan_images = self._extract_scan_images(scan_files)
|
||||
stitches = self._extract_final_stitches(scan_files)
|
||||
|
|
@ -325,7 +325,7 @@ class ScanDirectory:
|
|||
return files
|
||||
|
||||
def zip_files(self, final_version: bool = False) -> str:
|
||||
"""Zips any images from the scan not yet zipped, return full path to zip
|
||||
"""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
|
||||
this should only be done at the end as it is not possible to update a file
|
||||
|
|
@ -357,6 +357,6 @@ class ScanDirectory:
|
|||
|
||||
|
||||
def get_files_in_zip(zip_path):
|
||||
"""List the relative paths of all files and folders in the zip folder specified"""
|
||||
"""List the relative paths of all files and folders in the zip folder specified."""
|
||||
scan_zip = zipfile.ZipFile(zip_path)
|
||||
return [os.path.normpath(i) for i in scan_zip.namelist()]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue