diff --git a/picframe/config/configuration_example.yaml b/picframe/config/configuration_example.yaml index 2daaf6d..3873942 100644 --- a/picframe/config/configuration_example.yaml +++ b/picframe/config/configuration_example.yaml @@ -41,6 +41,7 @@ viewer: model: pic_dir: "~/Pictures" # default="~/Pictures", root folder for images deleted_pictures: "~/DeletedPictures" # move deleted pictures here + follow_links: False # default=False, By default, picframe will not walk down into symbolic links that resolve to directories. Set follow_links to True to visit directories pointed to by symlinks, on systems that support them. no_files_img: "~/picframe_data/data/no_pictures.jpg" # default="PictureFrame2020img.jpg", image to show if none selected subdirectory: "" # default="", subdir of pic_dir - can be changed by MQTT" recent_n: 7 # default=7 (days), when shuffling file change date more recent than this number of days play before the rest diff --git a/picframe/image_cache.py b/picframe/image_cache.py index c03aa62..388cb7d 100644 --- a/picframe/image_cache.py +++ b/picframe/image_cache.py @@ -22,7 +22,7 @@ class ImageCache: 'IPTC Object Name': 'title'} - def __init__(self, picture_dir, db_file, geo_reverse, portrait_pairs=False): + def __init__(self, picture_dir, follow_links, db_file, geo_reverse, portrait_pairs=False): # TODO these class methods will crash if Model attempts to instantiate this using a # different version from the latest one - should this argument be taken out? self.__modified_folders = [] @@ -32,6 +32,7 @@ def __init__(self, picture_dir, db_file, geo_reverse, portrait_pairs=False): self.__logger = logging.getLogger("image_cache.ImageCache") self.__logger.debug('Creating an instance of ImageCache') self.__picture_dir = picture_dir + self.__follow_links = follow_links self.__db_file = db_file self.__geo_reverse = geo_reverse self.__portrait_pairs = portrait_pairs #TODO have a function to turn this on and off? @@ -349,7 +350,7 @@ def __update_schema(self, required_db_schema_version): def __get_modified_folders(self): out_of_date_folders = [] sql_select = "SELECT * FROM folder WHERE name = ?" - for dir in [d[0] for d in os.walk(self.__picture_dir)]: + for dir in [d[0] for d in os.walk(self.__picture_dir, followlinks=self.__follow_links)]: mod_tm = int(os.stat(dir).st_mtime) found = self.__db.execute(sql_select, (dir,)).fetchone() if not found or found['last_modified'] < mod_tm or found['missing'] == 1: @@ -501,7 +502,7 @@ def __get_exif_info(self, file_path_name): # If being executed (instead of imported), kick it off... if __name__ == "__main__": - cache = ImageCache(picture_dir='/home/pi/Pictures', db_file='/home/pi/db.db3', geo_reverse=None) + cache = ImageCache(picture_dir='/home/pi/Pictures', follow_links=False, db_file='/home/pi/db.db3', geo_reverse=None) #cache.update_cache() # items = cache.query_cache("make like '%google%'", "exif_datetime asc") #info = cache.get_file_info(12) diff --git a/picframe/model.py b/picframe/model.py index a8a87a6..3cf8cb1 100644 --- a/picframe/model.py +++ b/picframe/model.py @@ -53,6 +53,7 @@ 'pic_dir': '~/Pictures', 'no_files_img': '~/picframe_data/data/no_pictures.jpg', + 'follow_links': False, 'subdirectory': '', 'recent_n': 3, 'reshuffle_num': 1, @@ -170,6 +171,7 @@ def __init__(self, configfile = DEFAULT_CONFIGFILE): self.__load_geoloc = model_config['load_geoloc'] self.__geo_reverse = geo_reverse.GeoReverse(model_config['geo_key'], key_list=self.get_model_config()['key_list']) self.__image_cache = image_cache.ImageCache(self.__pic_dir, + model_config['follow_links'], os.path.expanduser(model_config['db_file']), self.__geo_reverse, model_config['portrait_pairs']) @@ -264,7 +266,7 @@ def get_directory_list(self): actual_dir = root if self.subdirectory != '': actual_dir = self.subdirectory - subdir_list = next(os.walk(self.__pic_dir))[1] + subdir_list = next(os.walk(self.__pic_dir, self.get_model_config()['follow_links']))[1] subdir_list[:] = [d for d in subdir_list if not d[0] == '.'] subdir_list.insert(0,root) return actual_dir, subdir_list