Skip to content

Commit

Permalink
Merge pull request #34 from jonpecar/enhancement/improve_photo_sort_f…
Browse files Browse the repository at this point in the history
…uncs_for_GUI

Enhancement/improve photo sort funcs for GUI
  • Loading branch information
jonpecar committed Sep 27, 2022
2 parents 66c1509 + 48384a0 commit b1bf9ab
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "qrImageIndexer"
version = "0.7.1"
version = "0.7.2"
description = "Tool for indexing images with QR codes"
readme = "README.md"
authors = [{name = "Jonathan Pecar", email = "jonathan.pecar@gmail.com"}]
Expand All @@ -31,7 +31,7 @@ dev = ["pytest", "bumpver", "setuptools"]
[project.urls]
Homepage = "https://github.com/jonpecar/qrCodeImageSorter"
[tool.bumpver]
current_version = "0.7.1"
current_version = "0.7.2"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "bump version {old_version} -> {new_version}"
commit = true
Expand Down
2 changes: 1 addition & 1 deletion qrImageIndexer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.1"
__version__ = "0.7.2"
32 changes: 25 additions & 7 deletions qrImageIndexer/photo_sorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def sort_directory(input_dir : str, output_dir : str, string_header : str = '',
List[str] of all paths found in QR codes
"""

found_directories = []


non_image_dir = os.path.join(output_dir, 'non_image_files')

Expand All @@ -215,24 +215,42 @@ def sort_directory(input_dir : str, output_dir : str, string_header : str = '',
os.makedirs(output_dir, exist_ok=True)


found_directories = sort_directory_exisitng_results(results, input_dir, output_dir, verbose)

found_directories.sort()
return found_directories

def sort_directory_exisitng_results(results : Dict[str, str], input_dir : str, output_dir : str, verbose : bool = False) -> List[str]:
"""
Takes results from the QR code scanning and uses that information to sort the images. Function separated from
above for better integration with GUI code.
Parameters:
results: Dictionary of results including image path and QR code result
input_dir: input directory containing photos as string
output_dir: output directory to save images in
verbose: whether or not to write verbose output to the terminal
Returns:
List[str] of all paths found in QR codes
"""
found_directories = []
non_image_dir = os.path.join(output_dir, 'non_image_files')
image_paths = get_image_paths(input_dir, non_image_dir, verbose)

if verbose:
print('Sorting image files')
current_path = os.path.join(output_dir, 'unsorted')
for image_path in tqdm.tqdm(image_paths) if verbose else image_paths:
_, image = os.path.split(image_path)
qr_string = results[image_path]
if qr_string:
if qr_string.startswith(string_header):
qr_string = qr_string[len(string_header):]
qr_string = sanitise_path(qr_string)
current_path = os.path.join(output_dir, qr_string)
if qr_string not in found_directories:
found_directories.append(qr_string)

os.makedirs(current_path, exist_ok=True)
shutil.copyfile(image_path, os.path.join(current_path, image))

found_directories.sort()

return found_directories


0 comments on commit b1bf9ab

Please sign in to comment.