comparison piecrust/processing/base.py @ 208:989d0abd7c17

processing: Use the correct full path for mounts.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 22 Jan 2015 22:23:43 -0800
parents c5330cb35794
children e34a6826a3d4
comparison
equal deleted inserted replaced
207:c5330cb35794 208:989d0abd7c17
126 self.tmp_dir = os.path.join(tmp_dir, 'proc') 126 self.tmp_dir = os.path.join(tmp_dir, 'proc')
127 127
128 baker_params = app.config.get('baker') or {} 128 baker_params = app.config.get('baker') or {}
129 129
130 assets_dirs = baker_params.get('assets_dirs', app.assets_dirs) 130 assets_dirs = baker_params.get('assets_dirs', app.assets_dirs)
131 self.mounts = make_mount_info(assets_dirs) 131 self.mounts = make_mount_infos(assets_dirs, self.app.root_dir)
132 132
133 self.num_workers = baker_params.get('workers', 4) 133 self.num_workers = baker_params.get('workers', 4)
134 134
135 ignores = baker_params.get('ignore', []) 135 ignores = baker_params.get('ignore', [])
136 ignores += [ 136 ignores += [
210 pool.append(worker) 210 pool.append(worker)
211 211
212 if src_dir_or_file is not None: 212 if src_dir_or_file is not None:
213 # Process only the given path. 213 # Process only the given path.
214 # Find out what mount point this is in. 214 # Find out what mount point this is in.
215 for path, info in self.mounts.items(): 215 for name, info in self.mounts.items():
216 path = info['path']
216 if src_dir_or_file[:len(path)] == path: 217 if src_dir_or_file[:len(path)] == path:
217 base_dir = path 218 base_dir = path
218 mount_info = info 219 mount_info = info
219 break 220 break
220 else: 221 else:
222 known_roots = [i['path'] for i in self.mounts.values()]
221 raise Exception("Input path '%s' is not part of any known " 223 raise Exception("Input path '%s' is not part of any known "
222 "mount point: %s" % 224 "mount point: %s" %
223 (src_dir_or_file, self.mounts.keys())) 225 (src_dir_or_file, known_roots))
224 226
225 ctx = ProcessingContext(base_dir, mount_info, queue, record) 227 ctx = ProcessingContext(base_dir, mount_info, queue, record)
226 logger.debug("Initiating processing pipeline on: %s" % src_dir_or_file) 228 logger.debug("Initiating processing pipeline on: %s" % src_dir_or_file)
227 if os.path.isdir(src_dir_or_file): 229 if os.path.isdir(src_dir_or_file):
228 self.processDirectory(ctx, src_dir_or_file, new_only) 230 self.processDirectory(ctx, src_dir_or_file, new_only)
229 elif os.path.isfile(src_dir_or_file): 231 elif os.path.isfile(src_dir_or_file):
230 self.processFile(ctx, src_dir_or_file, new_only) 232 self.processFile(ctx, src_dir_or_file, new_only)
231 233
232 else: 234 else:
233 # Process everything. 235 # Process everything.
234 for path, info in self.mounts.items(): 236 for name, info in self.mounts.items():
237 path = info['path']
235 ctx = ProcessingContext(path, info, queue, record) 238 ctx = ProcessingContext(path, info, queue, record)
236 logger.debug("Initiating processing pipeline on: %s" % path) 239 logger.debug("Initiating processing pipeline on: %s" % path)
237 self.processDirectory(ctx, path, new_only) 240 self.processDirectory(ctx, path, new_only)
238 241
239 # Wait on all workers. 242 # Wait on all workers.
386 except ProcessingTreeError as ex: 389 except ProcessingTreeError as ex:
387 record_entry.errors.append(str(ex)) 390 record_entry.errors.append(str(ex))
388 logger.error("Error processing %s: %s" % (rel_path, ex)) 391 logger.error("Error processing %s: %s" % (rel_path, ex))
389 392
390 393
391 def make_mount_info(mounts): 394 def make_mount_infos(mounts, root_dir):
392 if isinstance(mounts, list): 395 if isinstance(mounts, list):
393 mounts = {m: {} for m in mounts} 396 mounts = {m: {} for m in mounts}
394 397
395 for name, info in mounts.items(): 398 for name, info in mounts.items():
396 if not isinstance(info, dict): 399 if not isinstance(info, dict):
397 raise Exception("Asset directory info for '%s' is not a " 400 raise Exception("Asset directory info for '%s' is not a "
398 "dictionary." % name) 401 "dictionary." % name)
399 info.setdefault('processors', 'all -uglifyjs -cleancss') 402 info.setdefault('processors', 'all -uglifyjs -cleancss')
403 info['path'] = os.path.join(root_dir, name)
400 404
401 return mounts 405 return mounts
402 406
403 407
404 def make_re(patterns): 408 def make_re(patterns):