Skip to content

Commit

Permalink
Fix #166 Make it configurable, that picframe
Browse files Browse the repository at this point in the history
follows symbolic links.
  • Loading branch information
helgeerbe committed Sep 8, 2021
1 parent 0687716 commit f4f7ee2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions picframe/config/configuration_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions picframe/image_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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?
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
4 changes: 3 additions & 1 deletion picframe/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f4f7ee2

Please sign in to comment.