diff piecrust/serving/procloop.py @ 666:81d9c3a3a0b5

internal: Get rid of the whole "sub cache" business. * Compute cache keys up front, so the cache directory is only chosen once. * Buffer up config variants to apply before loading the config. Makes it possible to cache variant-resulting configs, too. * Make a factory class to reuse the logic that creates the `PieCrust` object correctly for multi-process workers and such. * Add a test.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 03 Mar 2016 08:22:41 -0800
parents 3ceeca7bb71c
children c2ea75e37540
line wrap: on
line diff
--- a/piecrust/serving/procloop.py	Thu Mar 03 08:19:28 2016 -0800
+++ b/piecrust/serving/procloop.py	Thu Mar 03 08:22:41 2016 -0800
@@ -75,15 +75,10 @@
 
 
 class ProcessingLoop(threading.Thread):
-    def __init__(self, root_dir, out_dir, sub_cache_dir=None,
-                 theme_site=False, debug=False):
+    def __init__(self, appfactory):
         super(ProcessingLoop, self).__init__(
                 name='pipeline-reloader', daemon=True)
-        self.root_dir = root_dir
-        self.out_dir = out_dir
-        self.sub_cache_dir = sub_cache_dir
-        self.debug = debug
-        self.theme_site = theme_site
+        self.appfactory = appfactory
         self.last_status_id = 0
         self.interval = 1
         self.app = None
@@ -95,7 +90,7 @@
         self._last_config_mtime = 0
         self._obs = []
         self._obs_lock = threading.Lock()
-        if theme_site:
+        if appfactory.theme_site:
             self._config_path = os.path.join(root_dir, THEME_CONFIG_PATH)
         else:
             self._config_path = os.path.join(root_dir, CONFIG_PATH)
@@ -162,10 +157,7 @@
 
     def _initPipeline(self):
         # Create the app and pipeline.
-        self.app = PieCrust(root_dir=self.root_dir, debug=self.debug,
-                            theme_site=self.theme_site)
-        if self.sub_cache_dir:
-            self.app._useSubCacheDir(self.sub_cache_dir)
+        self.app = self.appfactory.create()
         self.pipeline = ProcessorPipeline(self.app, self.out_dir)
 
         # Get the list of assets directories.