From 375072a56b335bbf1d28992d222d37fa5b4a29f3 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Thu, 14 May 2015 18:57:59 -0700 Subject: [PATCH] config: allow custom config.yaml settings for automatic collections. settings in config.yaml are merged with collection-specific settings, which take precedence (before, the config.yaml settings were being overwritten) #103 --- pywb/webapp/handlers.py | 2 ++ pywb/webapp/pywb_init.py | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pywb/webapp/handlers.py b/pywb/webapp/handlers.py index bee9ebe6..010c0e98 100644 --- a/pywb/webapp/handlers.py +++ b/pywb/webapp/handlers.py @@ -1,6 +1,7 @@ import pkgutil import mimetypes import time +import logging from datetime import datetime @@ -144,6 +145,7 @@ class WBHandler(SearchPageWbUrlHandler): def resolve_refs(self, handler_dict): if self.fallback_name: self.fallback_handler = handler_dict.get(self.fallback_name) + logging.debug('Fallback Handler: ' + self.fallback_name) def handle_request(self, wbrequest): cdx_lines, output = self.index_reader.load_for_request(wbrequest) diff --git a/pywb/webapp/pywb_init.py b/pywb/webapp/pywb_init.py index 632fb552..595ce849 100644 --- a/pywb/webapp/pywb_init.py +++ b/pywb/webapp/pywb_init.py @@ -124,8 +124,9 @@ def create_cdx_server_app(passed_config): # collections based on file system if config.get('enable_auto_colls', True): colls_loader_cls = config.get('colls_loader_cls', DirectoryCollsLoader) - dir_loader = colls_loader_cls(config, static_routes) - collections.update(dir_loader()) + dir_loader = colls_loader_cls(config, static_routes, collections) + dir_loader() + #collections.update(dir_loader()) routes = [] @@ -142,12 +143,13 @@ def create_cdx_server_app(passed_config): #================================================================= class DirectoryCollsLoader(object): - def __init__(self, config, static_routes): + def __init__(self, config, static_routes, colls): self.config = config self.static_routes = static_routes + self.colls = colls def __call__(self): - colls = {} + colls = self.colls static_dir = self.config.get('paths')['static_path'] static_shared_prefix = self.config.get('static_shared_prefix') @@ -167,7 +169,11 @@ class DirectoryCollsLoader(object): coll_config = self.load_coll_dir(full, name) if coll_config: - colls[name] = coll_config + # if already exists, override existing config with coll specific + if name in colls: + colls[name].update(coll_config) + else: + colls[name] = coll_config return colls @@ -263,8 +269,9 @@ def create_wb_router(passed_config=None): # collections based on file system if config.get('enable_auto_colls', True): colls_loader_cls = config.get('colls_loader_cls', DirectoryCollsLoader) - dir_loader = colls_loader_cls(config, static_routes) - collections.update(dir_loader()) + dir_loader = colls_loader_cls(config, static_routes, collections) + dir_loader() + #collections.update(dir_loader()) if config.get('enable_memento', False): request_class = MementoRequest