diff piecrust/serving/procloop.py @ 553:cc6f3dbe3048

serve: Extract some of the server's functionality into WSGI middlewares.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 08 Aug 2015 22:01:47 -0700
parents 9612cfc6455a
children ff714d7f074d
line wrap: on
line diff
--- a/piecrust/serving/procloop.py	Sat Aug 08 16:12:04 2015 -0700
+++ b/piecrust/serving/procloop.py	Sat Aug 08 22:01:47 2015 -0700
@@ -6,6 +6,8 @@
 import logging
 import itertools
 import threading
+from piecrust.app import PieCrust
+from piecrust.processing.pipeline import ProcessorPipeline
 
 
 logger = logging.getLogger(__name__)
@@ -72,10 +74,14 @@
 
 
 class ProcessingLoop(threading.Thread):
-    def __init__(self, pipeline):
+    def __init__(self, root_dir, out_dir, sub_cache_dir=None, debug=False):
         super(ProcessingLoop, self).__init__(
                 name='pipeline-reloader', daemon=True)
-        self.pipeline = pipeline
+        # TODO: re-create the app when `config.yml` is changed.
+        self.app = PieCrust(root_dir=root_dir, debug=debug)
+        if sub_cache_dir:
+            self.app._useSubCacheDir(sub_cache_dir)
+        self.pipeline = ProcessorPipeline(self.app, out_dir)
         self.last_status_id = 0
         self.interval = 1
         self._paths = set()
@@ -94,8 +100,7 @@
 
     def run(self):
         # Build the first list of known files and run the pipeline once.
-        app = self.pipeline.app
-        roots = [os.path.join(app.root_dir, r)
+        roots = [os.path.join(self.app.root_dir, r)
                  for r in self.pipeline.mounts.keys()]
         for root in roots:
             for dirpath, dirnames, filenames in os.walk(root):