diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..4ba9ef5 --- /dev/null +++ b/src/main.py @@ -0,0 +1,46 @@ +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) diff --git a/src/photo.py b/src/photo.py new file mode 100644 index 0000000..cbd2b60 --- /dev/null +++ b/src/photo.py @@ -0,0 +1,10 @@ +from pathlib import Path +import os + +class Photo: + def __init__(self, path: Path): + self.path = path + + @property + def size(self): + return os.path.getsize(self.path) \ No newline at end of file