comparison piecrust/serving/procloop.py @ 663:3ceeca7bb71c

themes: Add support for a `--theme` argument to `chef`.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 01 Mar 2016 22:27:28 -0800
parents 7dabfdd056a1
children 81d9c3a3a0b5
comparison
equal deleted inserted replaced
662:cbd5cdec0695 663:3ceeca7bb71c
4 import json 4 import json
5 import queue 5 import queue
6 import logging 6 import logging
7 import itertools 7 import itertools
8 import threading 8 import threading
9 from piecrust import CONFIG_PATH, THEME_CONFIG_PATH
9 from piecrust.app import PieCrust 10 from piecrust.app import PieCrust
10 from piecrust.processing.pipeline import ProcessorPipeline 11 from piecrust.processing.pipeline import ProcessorPipeline
11 12
12 13
13 logger = logging.getLogger(__name__) 14 logger = logging.getLogger(__name__)
72 self._proc_loop.removeObserver(self) 73 self._proc_loop.removeObserver(self)
73 self._running = 2 74 self._running = 2
74 75
75 76
76 class ProcessingLoop(threading.Thread): 77 class ProcessingLoop(threading.Thread):
77 def __init__(self, root_dir, out_dir, sub_cache_dir=None, debug=False): 78 def __init__(self, root_dir, out_dir, sub_cache_dir=None,
79 theme_site=False, debug=False):
78 super(ProcessingLoop, self).__init__( 80 super(ProcessingLoop, self).__init__(
79 name='pipeline-reloader', daemon=True) 81 name='pipeline-reloader', daemon=True)
80 self.root_dir = root_dir 82 self.root_dir = root_dir
81 self.out_dir = out_dir 83 self.out_dir = out_dir
82 self.sub_cache_dir = sub_cache_dir 84 self.sub_cache_dir = sub_cache_dir
83 self.debug = debug 85 self.debug = debug
86 self.theme_site = theme_site
84 self.last_status_id = 0 87 self.last_status_id = 0
85 self.interval = 1 88 self.interval = 1
86 self.app = None 89 self.app = None
87 self._roots = [] 90 self._roots = []
88 self._monitor_assets_root = False 91 self._monitor_assets_root = False
89 self._paths = set() 92 self._paths = set()
90 self._config_path = os.path.join(root_dir, 'config.yml')
91 self._record = None 93 self._record = None
92 self._last_bake = 0 94 self._last_bake = 0
93 self._last_config_mtime = 0 95 self._last_config_mtime = 0
94 self._obs = [] 96 self._obs = []
95 self._obs_lock = threading.Lock() 97 self._obs_lock = threading.Lock()
98 if theme_site:
99 self._config_path = os.path.join(root_dir, THEME_CONFIG_PATH)
100 else:
101 self._config_path = os.path.join(root_dir, CONFIG_PATH)
96 102
97 def addObserver(self, obs): 103 def addObserver(self, obs):
98 with self._obs_lock: 104 with self._obs_lock:
99 self._obs.append(obs) 105 self._obs.append(obs)
100 106
154 160
155 time.sleep(self.interval) 161 time.sleep(self.interval)
156 162
157 def _initPipeline(self): 163 def _initPipeline(self):
158 # Create the app and pipeline. 164 # Create the app and pipeline.
159 self.app = PieCrust(root_dir=self.root_dir, debug=self.debug) 165 self.app = PieCrust(root_dir=self.root_dir, debug=self.debug,
166 theme_site=self.theme_site)
160 if self.sub_cache_dir: 167 if self.sub_cache_dir:
161 self.app._useSubCacheDir(self.sub_cache_dir) 168 self.app._useSubCacheDir(self.sub_cache_dir)
162 self.pipeline = ProcessorPipeline(self.app, self.out_dir) 169 self.pipeline = ProcessorPipeline(self.app, self.out_dir)
163 170
164 # Get the list of assets directories. 171 # Get the list of assets directories.