From b9870524db1eda84a230336f560164541bc0c41c Mon Sep 17 00:00:00 2001 From: Cedric Leporcq Date: Sun, 8 Aug 2021 13:03:58 +0200 Subject: [PATCH] Add get_items function in filesystem --- dozo/filesystem.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/dozo/filesystem.py b/dozo/filesystem.py index 56f8ef5..0f753c4 100644 --- a/dozo/filesystem.py +++ b/dozo/filesystem.py @@ -28,31 +28,12 @@ class FileSystem(object): def __init__(self, cache=False, day_begins=0, dry_run=False, exclude_regex_list=set(), filter_by_ext=(), logger=logging.getLogger(), max_deep=None, mode='copy', path_format=None): - - self.items = { - 'album': '{album}', - 'basename': '{basename}', - 'camera_make': '{camera_make}', - 'camera_model': '{camera_model}', - 'city': '{city}', - 'custom': '{".*"}', - 'country': '{country}', - # 'folder': '{folder[<>]?[-+]?[1-9]?}', - 'folder': '{folder}', - 'folders': '{folders(\[[0-9:]{0,3}\])?}', - 'location': '{location}', - 'ext': '{ext}', - 'original_name': '{original_name}', - 'state': '{state}', - 'title': '{title}', - 'date': '{(%[a-zA-Z][^a-zA-Z]*){1,8}}' # search for date format string - } - self.cache = cache self.day_begins = day_begins self.dry_run = dry_run self.exclude_regex_list = exclude_regex_list self.filter_by_ext = filter_by_ext + self.items = self.get_items() self.logger = logger self.max_deep = max_deep self.mode = mode @@ -89,6 +70,28 @@ class FileSystem(object): return False + def get_items(self): + return { + 'album': '{album}', + 'basename': '{basename}', + 'camera_make': '{camera_make}', + 'camera_model': '{camera_model}', + 'city': '{city}', + 'custom': '{".*"}', + 'country': '{country}', + # 'folder': '{folder[<>]?[-+]?[1-9]?}', + 'ext': '{ext}', + 'folder': '{folder}', + 'folders': r'{folders(\[[0-9:]{0,3}\])?}', + 'location': '{location}', + 'name': '{name}', + 'original_name': '{original_name}', + 'state': '{state}', + 'title': '{title}', + 'date': '{(%[a-zA-Z][^a-zA-Z]*){1,8}}' # search for date format string + } + + def walklevel(self, src_path, maxlevel=None): """ Walk into input directory recursively until desired maxlevel