create dictionary of photos
- exclude 'new' directory
This commit is contained in:
parent
00408dfb40
commit
2c6353494e
46
src/main.py
Normal file
46
src/main.py
Normal file
|
|
@ -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)
|
||||
10
src/photo.py
Normal file
10
src/photo.py
Normal file
|
|
@ -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)
|
||||
Loading…
Reference in New Issue
Block a user