1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

improve docs for config.yaml, group all ui settings together

create seperate test_config.yaml for testing
rename ArchivalRequestRouter -> ArchivalRouter for consistency
This commit is contained in:
Ilya Kreymer 2014-02-05 10:10:33 -08:00
parent 94f8f080c4
commit 3168b80cfa
6 changed files with 45 additions and 36 deletions

View File

@ -31,27 +31,33 @@ surt_ordered: true
archive_paths: ./sample_archive/warcs/ archive_paths: ./sample_archive/warcs/
# ui: optional Jinja2 template to insert into <head> of each replay # ==== Optional UI: HTML/Jinja2 Templates ====
# template for <head> insert into replayed html content
head_insert_html: ./ui/head_insert.html head_insert_html: ./ui/head_insert.html
# ui: optional text to directly insert into <head> # template to for 'calendar' query,
# only loaded if ui_head_insert_template_file is not specified
#head_insert_text: <script src='example.js'></script>
#static_path: /static2/
# ui: optional Jinja2 template to use for 'calendar' query,
# eg, a listing of captures in response to a ../*/<url> # eg, a listing of captures in response to a ../*/<url>
# #
# may be a simple listing or a more complex 'calendar' UI # may be a simple listing or a more complex 'calendar' UI
# if omitted, the capture listing lists raw index # if omitted, will list raw cdx in plain text
query_html: ./ui/query.html query_html: ./ui/query.html
# ui: optional Jinja2 template to use for 'search' page # template for search page, which is displayed when no search url is entered
# this page is displayed when no search url is entered # in a collection
search_html: ./ui/search.html search_html: ./ui/search.html
# template for home page.
# if no other route is set, this will be rendered at /, /index.htm and /index.html
home_html: ./ui/index.html
# error page temlpate for may formatting error message and details
# if omitted, a text response is returned
error_html: ./ui/error.html
# ==== Other Paths ====
# list of host names that pywb will be running from to detect # list of host names that pywb will be running from to detect
# 'fallthrough' requests based on referrer # 'fallthrough' requests based on referrer
# #
@ -62,13 +68,12 @@ search_html: ./ui/search.html
hostpaths: ['http://localhost:8080/'] hostpaths: ['http://localhost:8080/']
# ui: optional Jinja2 template for home page # Custom path for serving html content
# if no other route is set to home page, this template will # Default is hostname[0] + '/static/'
# be rendered at /, /index.htm and /index.html #static_path: /static/
home_html: ./ui/index.html
# ==== New / Experimental Settings ====
# Not yet production ready -- used primarily for testing
# ui: optional Jinja2 template for rendering any errors # enable cdx server api for querying cdx directly (experimental)
# the error page may print a detailed error message enable_cdx_api: false
error_html: ./ui/error.html

View File

@ -7,9 +7,9 @@ from url_rewriter import UrlRewriter
from wburl import WbUrl from wburl import WbUrl
#================================================================= #=================================================================
# ArchivalRequestRouter -- route WB requests in archival mode # ArchivalRouter -- route WB requests in archival mode
#================================================================= #=================================================================
class ArchivalRequestRouter: class ArchivalRouter:
def __init__(self, routes, hostpaths = None, abs_path = True, home_view = None, error_view = None): def __init__(self, routes, hostpaths = None, abs_path = True, home_view = None, error_view = None):
self.routes = routes self.routes = routes
self.fallback = ReferRedirect(hostpaths) self.fallback = ReferRedirect(hostpaths)

View File

@ -4,7 +4,6 @@ import handlers
import indexreader import indexreader
import replay_views import replay_views
import replay_resolvers import replay_resolvers
from archivalrouter import ArchivalRequestRouter, Route
import logging import logging

View File

@ -95,6 +95,9 @@ class CDXHandler(BaseHandler):
def get_wburl_type(): def get_wburl_type():
return None return None
def __str__(self):
return 'CDX Server: ' + str(self.cdx_reader)
#================================================================= #=================================================================
# Debug Handlers # Debug Handlers
#================================================================= #=================================================================

View File

@ -1,6 +1,6 @@
import handlers import handlers
import indexreader import indexreader
from archivalrouter import ArchivalRequestRouter, Route import archivalrouter
import os import os
import yaml import yaml
import config_utils import config_utils
@ -31,40 +31,40 @@ def pywb_config_manual(config = {}):
cdx_source = indexreader.IndexReader.make_best_cdx_source(index_paths, **config) cdx_source = indexreader.IndexReader.make_best_cdx_source(index_paths, **config)
# cdx query handler # cdx query handler
if config.get('enable_cdx_api', True): if config.get('enable_cdx_api', False):
routes.append(Route(name + '-cdx', handlers.CDXHandler(cdx_source))) routes.append(archivalrouter.Route(name + '-cdx', handlers.CDXHandler(cdx_source)))
wb_handler = config_utils.create_wb_handler( wb_handler = config_utils.create_wb_handler(
cdx_source = cdx_source, cdx_source = cdx_source,
archive_paths = config.get('archive_paths', './sample_archive/warcs/'), archive_paths = config.get('archive_paths', './sample_archive/warcs/'),
head_html = config.get('head_insert_html', './ui/head_insert.html'), head_html = config.get('head_insert_html'),
query_html = config.get('query_html', './ui/query.html'), query_html = config.get('query_html'),
search_html = config.get('search_html', './ui/search.html'), search_html = config.get('search_html'),
static_path = config.get('static_path', hostpaths[0] + 'static/') static_path = config.get('static_path', hostpaths[0] + 'static/')
) )
logging.info('Adding Collection: ' + name) logging.info('Adding Collection: ' + name)
routes.append(Route(name, wb_handler)) routes.append(archivalrouter.Route(name, wb_handler))
if config.get('debug_echo_env', False): if config.get('debug_echo_env', False):
routes.append(Route('echo_env', handlers.DebugEchoEnvHandler())) routes.append(archivalrouter.Route('echo_env', handlers.DebugEchoEnvHandler()))
if config.get('debug_echo_req', False): if config.get('debug_echo_req', False):
routes.append(Route('echo_req', handlers.DebugEchoHandler())) routes.append(archivalrouter.Route('echo_req', handlers.DebugEchoHandler()))
# Finally, create wb router # Finally, create wb router
return ArchivalRequestRouter( return archivalrouter.ArchivalRouter(
routes, routes,
# Specify hostnames that pywb will be running on # Specify hostnames that pywb will be running on
# This will help catch occasionally missed rewrites that fall-through to the host # This will help catch occasionally missed rewrites that fall-through to the host
# (See archivalrouter.ReferRedirect) # (See archivalrouter.ReferRedirect)
hostpaths = hostpaths, hostpaths = hostpaths,
home_view = config_utils.load_template_file(config.get('home_html', './ui/index.html'), 'Home Page'), home_view = config_utils.load_template_file(config.get('home_html'), 'Home Page'),
error_view = config_utils.load_template_file(config.get('error_html', './ui/error.html'), 'Error Page') error_view = config_utils.load_template_file(config.get('error_html'), 'Error Page')
) )

View File

@ -3,10 +3,12 @@ import pywb.pywb_init
from pywb.indexreader import CDXCaptureResult from pywb.indexreader import CDXCaptureResult
class TestWb: class TestWb:
TEST_CONFIG = 'test_config.yaml'
def setup(self): def setup(self):
import pywb.wbapp import pywb.wbapp
#self.app = pywb.wbapp.create_wb_app(pywb.pywb_init.pywb_config()) #self.app = pywb.wbapp.create_wb_app(pywb.pywb_init.pywb_config())
self.app = pywb.wbapp.create_wb_app(pywb.pywb_init.pywb_config_manual()) self.app = pywb.wbapp.create_wb_app(pywb.pywb_init.pywb_config(self.TEST_CONFIG))
self.testapp = webtest.TestApp(self.app) self.testapp = webtest.TestApp(self.app)
def _assert_basic_html(self, resp): def _assert_basic_html(self, resp):