47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import argparse
|
|
from pathlib import Path
|
|
from photo import Photo
|
|
import os
|
|
|
|
|
|
|
|
def get_args():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('main', type=Path)
|
|
parser.add_argument('new', type=Path)
|
|
return parser.parse_args()
|
|
|
|
|
|
def main(main_dir: Path, new: Path):
|
|
main_files = {}
|
|
|
|
generate_photo_dict(main_dir, main_files, new)
|
|
|
|
|
|
def generate_photo_dict(path: Path, file_list: dict, exclude: Path):
|
|
if not path.is_dir():
|
|
raise Exception(f"{path} is not a directory.")
|
|
|
|
for entry in path.iterdir():
|
|
if entry.is_file():
|
|
filename = entry.name
|
|
if filename in file_list:
|
|
print(f"Duplicate photo: {filename}")
|
|
file_list[filename] = Photo(entry)
|
|
elif entry.is_dir():
|
|
if entry == exclude:
|
|
print(f"Excluding: {entry}")
|
|
continue
|
|
generate_photo_dict(entry, file_list, exclude)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
args = get_args()
|
|
main_directory = args.main
|
|
new_directory = args.new
|
|
|
|
if len(new_directory.parts) < 3:
|
|
raise Exception("Paths too short")
|
|
|
|
main(main_directory, new_directory)
|