From 737db1d641c6d17cdf2700912c413eb2b6dd4ba6 Mon Sep 17 00:00:00 2001 From: Deniz Turgut Date: Wed, 21 Jan 2015 18:06:04 -0500 Subject: [PATCH] Fix static path watchers There was an issue with static path watchers, where they were watching wrong paths. They need to be prefixed with the 'content' path. So, they were not working at all. It was also possible to overwrite default watchers like 'content', 'settings' and 'theme' by mistake if any of them were present in `STATIC_PATHS`. This is fixed by adding a prefix to static watchers. And static watchers were "too static", meaning, they stayed the same even if `STATIC_PATHS` was changed in the settings during autoreload. Now static watchers reflect those changes (i.e. new paths are added to watch list, and removed ones are no longer watched). --- pelican/__init__.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index 967360c9..53025e71 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -359,8 +359,13 @@ def main(): pelican.ignore_files), 'settings': file_watcher(args.settings)} - for static_path in settings.get("STATIC_PATHS", []): - watchers[static_path] = folder_watcher(static_path, [''], pelican.ignore_files) + old_static = settings.get("STATIC_PATHS", []) + for static_path in old_static: + # use a prefix to avoid possible overriding of standard watchers above + watchers['[static]%s' % static_path] = folder_watcher( + os.path.join(pelican.path, static_path), + [''], + pelican.ignore_files) try: if args.autoreload: @@ -386,6 +391,29 @@ def main(): original_load_cache = settings['LOAD_CONTENT_CACHE'] _ignore_cache(pelican) + # Adjust static watchers if there are any changes + new_static = settings.get("STATIC_PATHS", []) + + # Added static paths + # Add new watchers and set them as modified + for static_path in set(new_static).difference(old_static): + static_key = '[static]%s' % static_path + watchers[static_key] = folder_watcher( + os.path.join(pelican.path, static_path), + [''], + pelican.ignore_files) + modified[static_key] = next(watchers[static_key]) + + # Removed static paths + # Remove watchers and modified values + for static_path in set(old_static).difference(new_static): + static_key = '[static]%s' % static_path + watchers.pop(static_key) + modified.pop(static_key) + + # Replace old_static with the new one + old_static = new_static + if any(modified.values()): print('\n-> Modified: {}. re-generating...'.format( ', '.join(k for k, v in modified.items() if v)))