pic_scanner.helpers package
Subpackages
- pic_scanner.helpers.filesystem package
- Submodules
- pic_scanner.helpers.filesystem.classes module
FileFileCollectionFileCollection.get_total_size_in_lowest_unit()FileCollection.get_total_extension_size_in_lowest_unit()FileCollection.remove_file()FileCollection.reprocess_files()FileCollection.__init__()FileCollection._process_files()FileCollection.extensionsFileCollection.get_total_extension_size_in_lowest_unit()FileCollection.get_total_size_in_lowest_unit()FileCollection.needs_reprocessingFileCollection.pathsFileCollection.remove_file()FileCollection.reprocess_files()FileCollection.total_filesFileCollection.total_size
NeedsReprocessingTagget_lowest_unit_size()
- pic_scanner.helpers.filesystem.units module
- Module contents
Submodules
pic_scanner.helpers.images module
- pic_scanner.helpers.images.draw_bounding_boxes(image_path, concerns, box_color=(255, 0, 0), text_color=(255, 255, 255), save_path=None, save_annotated=False)
Draw bounding boxes around areas of concern in an image.
- Parameters:
image_path (str) – The path to the image.
concerns (list) – The areas of concern in the image.
save_path (str) – The path to save the annotated image.
save_annotated (bool) – A flag indicating whether to save the annotated image.
- Returns:
The image with the bounding boxes drawn.
- Return type:
Image
- pic_scanner.helpers.images.get_image_checksum(image_path)
Get the checksum of an image file.
- Parameters:
image_path (Union[str, Path]) – The path to the image file.
- Returns:
The checksum of the image file.
- Return type:
str
- pic_scanner.helpers.images.get_image_data(file_or_bytes, maxsize=(1200, 850))
Get image data from a file or a bytes object.
This function opens an image file or a bytes object, resizes it to fit within the given maximum size, and returns the image data in PNG format as bytes.
- Parameters:
file_or_bytes (Union[str, bytes]) – The path to the image file or a bytes object containing the image data.
maxsize (Tuple[int, int], optional) – The maximum size of the image as a (width, height) tuple. Default is (1200, 850).
- Returns:
The image data as a byte-string object in PNG format.
- Return type:
bytes
- Raises:
FileNotFoundError – If the specified file does not exist.
OSError – If the file cannot be opened and identified as an image file.
ValueError – If the input bytes object cannot be decoded into an image.
pic_scanner.helpers.locks module
- pic_scanner.helpers.locks.flag_lock(instance, flag_name)
Context manager to set and unset a private flag attribute in an instance.
This context manager ensures that a specified private flag attribute in the given instance is set to True when entering the context and reset to False upon exiting the context. This is useful for indicating that an operation is in progress within a specific scope.
- Parameters:
instance (object) – The instance containing the private flag attribute.
flag_name (str) – The name of the flag attribute (without leading underscore).
- Raises:
AttributeError – If the instance does not have the specified private flag attribute.
- Example usage:
handler = OperationHandler() with flag_lock(handler, ‘flag’):
# Perform some operation pass
This will automatically set handler._flag to True within the context and reset it to False when exiting the context.
pic_scanner.helpers.properties module
- class pic_scanner.helpers.properties.FrozenProperty(*args, **kwargs)
Bases:
RestrictedSetter- __init__(*args, **kwargs)
Initialize the FrozenProperty object.
- Parameters:
initial (any) – Initial value of the property.
allowed_types (type or tuple of types, optional) – Allowed types for the property value.
- Raises:
AttributeError – If the initial value is not of the correct type.
- class pic_scanner.helpers.properties.ReactiveProperty(default_value=None, callback=None, *args, **kwargs)
Bases:
object- __init__(default_value=None, callback=None, *args, **kwargs)
- add_callback(callback, *args, **kwargs)
- pic_scanner.helpers.properties.freeze_property(cls)
- pic_scanner.helpers.properties.validate_float_between(min_value=0.0, max_value=1.0)
Decorator to ensure that a property setter only accepts floats between a given range.
- Parameters:
min_value (Union[float, int], optional) – The minimum value that the property can be.
max_value (Union[float, int], optional) – The maximum value that the property can be.
- Returns:
The decorated function.
- Return type:
function
- Raises:
ValueError – If the value is not between the specified range.
Examples
>>> class Test: ... @validate_float_between(0.0, 1.0) ... def test(self, value): ... return value ... >>> t = Test() >>> t.test(0.5) 0.5 >>> t.test(1.5) Traceback (most recent call last): ... AttributeError: Value must be between 0.0 and 1.0
Module contents
- pic_scanner.helpers.get_caller_name()
Get the name of the calling function.
- Returns:
The name of the calling function.
- Return type:
str
Example
>>> get_caller_name() 'get_caller_name'
- pic_scanner.helpers.get_file_collection(directory, recursive=False, do_not_provision=False, exclude_dir_names=None, **kwargs)
Get a FileCollection object for a directory.
This function searches a directory for picture files and returns a FileCollection object containing the picture files found. The search can be performed recursively and specific directories can be excluded from the search.
Note
Use of the exclude_dir_names parameter is case-insensitive, and directory-depth is not considered when excluding directories. If a nested directory contains an excluded directory name, the nested directory will be excluded.
- Parameters:
directory (str or Path) – The directory to search for picture files.
recursive (bool) – A flag indicating whether to search recursively.
do_not_provision (bool) – A flag indicating whether to provision the directory.
exclude_dir_names (list) – A list of directory names to exclude.
**kwargs – Additional keyword arguments.
- Returns:
A FileCollection object containing the picture files in the directory.
- Return type:
Example
>>> get_file_collection('path/to/directory', recursive=True) FileCollection(paths=[Path('path/to/directory/image1.jpg'), Path('path/to/directory/image2.jpg')])
- pic_scanner.helpers.get_picture_files(directory, recursive=False, do_not_provision=False, exclude_dir_names=None, **kwargs)
Get a list of picture files in a directory.
This function searches a directory for picture files and returns a list of the picture files found. The search can be performed recursively and specific directories can be excluded from the search.
Note
Use of the exclude_dir_names parameter is case-insensitive, and directory-depth is not considered when excluding directories. If a nested directory contains an excluded directory name, the nested directory will be excluded.
- Parameters:
directory (str or Path) – The directory to search for picture files.
recursive (bool) – A flag indicating whether to search recursively.
do_not_provision (bool) – A flag indicating whether to provision the directory.
exclude_dir_names (list) – A list of directory names to exclude.
**kwargs – Additional keyword arguments.
- Returns:
A list of picture files in the directory.
- Return type:
list[Path]
Example
>>> get_picture_files('path/to/directory', recursive=True) [Path('path/to/directory/image1.jpg'), Path('path/to/directory/image2.jpg')]
- pic_scanner.helpers.is_class(obj)
Determine if an object is a class.
- Parameters:
obj – The object to check.
- Returns:
True if the object is a class; False otherwise.
- Return type:
bool
Example
>>> is_class(str) True >>> is_class('string') False
- pic_scanner.helpers.is_instance(obj)
Determine if an object is an instance of a class.
- Parameters:
obj – The object to check.
- Returns:
True if the object is an instance of a class; False otherwise.
- Return type:
bool
Example
>>> is_instance(str) False >>> is_instance('string') True