mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
improved customization: can setup pywb_init.pywb_config() config,
or specify custom init module <initmodule>.py_config() by setting PYWB_INIT=<initmodule> fix run.sh to support testing with custom mount point
This commit is contained in:
parent
44f68158a9
commit
e1b669fdea
@ -11,14 +11,15 @@ def PrefixResolver(prefix, contains = ''):
|
||||
|
||||
#======================================
|
||||
class RedisResolver:
|
||||
def __init__(self, redisUrl, keyPrefix = 'w:'):
|
||||
self.redisUrl = redisUrl
|
||||
self.keyPrefix = keyPrefix
|
||||
self.redis = redis.StrictRedis.from_url(redisUrl)
|
||||
def __init__(self, redis_url, key_prefix = 'w:'):
|
||||
self.redis_url = redis_url
|
||||
self.key_prefix = key_prefix
|
||||
self.redis = redis.StrictRedis.from_url(redis_url)
|
||||
|
||||
def __call__(self, filename):
|
||||
try:
|
||||
return [self.redis.hget(self.keyPrefix + filename, 'path')]
|
||||
redis_val = self.redis.hget(self.key_prefix + filename, 'path')
|
||||
return [redis_val] if redis_val else None
|
||||
except Exception as e:
|
||||
print e
|
||||
return None
|
||||
|
@ -1,8 +1,13 @@
|
||||
from utils import rel_request_uri
|
||||
import utils
|
||||
import wbexceptions
|
||||
|
||||
from wbrequestresponse import WbResponse, StatusAndHeaders
|
||||
|
||||
import os
|
||||
import importlib
|
||||
import logging
|
||||
|
||||
|
||||
## ===========
|
||||
default_head_insert = """
|
||||
|
||||
@ -79,7 +84,7 @@ def create_wb_app(wb_router):
|
||||
# Top-level wsgi application
|
||||
def application(env, start_response):
|
||||
if env.get('SCRIPT_NAME') or not env.get('REQUEST_URI'):
|
||||
env['REL_REQUEST_URI'] = rel_request_uri(env)
|
||||
env['REL_REQUEST_URI'] = utils.rel_request_uri(env)
|
||||
else:
|
||||
env['REL_REQUEST_URI'] = env['REQUEST_URI']
|
||||
|
||||
@ -95,7 +100,7 @@ def create_wb_app(wb_router):
|
||||
response = WbResponse(StatusAndHeaders(ir.status, ir.httpHeaders))
|
||||
|
||||
except (wbexceptions.NotFoundException, wbexceptions.AccessException) as e:
|
||||
print "[INFO]: " + str(e)
|
||||
logging.info(str(e))
|
||||
response = handle_exception(env, e)
|
||||
|
||||
except Exception as e:
|
||||
@ -119,18 +124,32 @@ def handle_exception(env, exc):
|
||||
return WbResponse.text_response(status + ' Error: ' + str(exc), status = status)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = create_wb_app(sample_wb_settings())
|
||||
|
||||
|
||||
#=================================================================
|
||||
def main():
|
||||
try:
|
||||
# Attempt to load real settings from globalwb module
|
||||
import globalwb
|
||||
application = create_wb_app(globalwb.create_global_wb(default_head_insert))
|
||||
except ImportError as e:
|
||||
logging.basicConfig(format = '%(asctime)s: [%(levelname)s]: %(message)s', level = logging.DEBUG)
|
||||
|
||||
config_name = os.environ.get('PYWB_CONFIG')
|
||||
|
||||
if not config_name:
|
||||
config_name = 'pywb_init'
|
||||
logging.info('PYWB_CONFIG not specified, attempting to load config from default module {0}'.format(config_name))
|
||||
|
||||
module = importlib.import_module(config_name)
|
||||
|
||||
app = create_wb_app(module.pywb_config(default_head_insert))
|
||||
logging.info('\n\n*** pywb inited with settings from {0}.pywb_config()!\n'.format(config_name))
|
||||
return app
|
||||
|
||||
except Exception as e:
|
||||
# Otherwise, start with the sample settings
|
||||
application = create_wb_app(sample_wb_settings())
|
||||
logging.exception('\n\n*** pywb could not init with settings from {0}.pywb_config()!\n'.format(config_name))
|
||||
raise e
|
||||
|
||||
#=================================================================
|
||||
|
||||
|
||||
if __name__ == "__main__" or utils.enable_doctests():
|
||||
# Test sample settings
|
||||
application = create_wb_app(sample_wb_settings())
|
||||
else:
|
||||
application = main()
|
||||
|
22
run.sh
22
run.sh
@ -2,17 +2,23 @@
|
||||
|
||||
mypath=$(cd `dirname $0` && pwd)
|
||||
|
||||
app=$2
|
||||
#cd $mypath/pywb
|
||||
if [ -z "$app" ]; then
|
||||
app=pywb.wbapp
|
||||
fi
|
||||
# Setup init module
|
||||
export 'PYWB_CONFIG=globalwb'
|
||||
|
||||
app="pywb.wbapp"
|
||||
|
||||
params="--static-map /static=$mypath/static --http-socket :8080 -b 65536"
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
# Standard root config
|
||||
uwsgi --static-map /static=$mypath/static --http-socket :8080 -b 65536 --wsgi $app
|
||||
params="$params --wsgi pywb.wbapp"
|
||||
else
|
||||
# Test on non-root mount
|
||||
uwsgi --static-map /static=$mypath/static --http-socket :8080 --mount "$1=$app" --no-default-app --manage-script-name
|
||||
# run with --mount
|
||||
# requires a file not a package, so creating a mount_run.py to load the package
|
||||
echo "#!/bin/python\n" > $mypath/mount_run.py
|
||||
echo "import $app\napplication = $app.application" >> $mypath/mount_run.py
|
||||
params="$params --mount $1=mount_run.py --no-default-app --manage-script-name"
|
||||
fi
|
||||
|
||||
uwsgi $params
|
||||
|
||||
|
@ -23,7 +23,8 @@ function initBanner()
|
||||
if (!banner) {
|
||||
banner = document.createElement("wb_div");
|
||||
banner.setAttribute("id", BANNER_ID);
|
||||
banner.innerHTML = "PyWb Test Banner!"
|
||||
banner.setAttribute("lang", "en");
|
||||
banner.innerHTML = "PyWb Archived Content"
|
||||
document.body.insertBefore(banner, document.body.firstChild);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user