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

auto-config: add support for loading from root ./static/ directory,

available under /static/__shared/ path
default path changed from /static/default -> /static/__pywb/
rename wayback-manager to wb-manager
This commit is contained in:
Ilya Kreymer 2015-03-17 19:05:39 -07:00
parent 0b8fd1e82e
commit bfe590996b
7 changed files with 36 additions and 9 deletions

View File

@ -38,11 +38,14 @@ not_found_html: templates/not_found.html
proxy_cert_download_html: templates/proxy_cert_download.html
proxy_select_html: templates/proxy_select.html
static_default_prefix: &static_default_prefix static/__pywb
static_shared_prefix: static/__shared
template_globals:
static_path: static/default
static_path: *static_default_prefix
static_routes:
static/default: pywb/static/
*static_default_prefix: pywb/static/
enable_memento: true

View File

@ -50,6 +50,10 @@ directory structure expected by pywb
if os.path.isdir(os.path.join(self.root_dir, d)):
print('- ' + d)
def _get_root_dir(self, name):
return os.path.join(os.getcwd(),
self.default_config['paths'][name])
def _get_dir(self, name):
return os.path.join(self.coll_dir,
self.default_config['paths'][name])
@ -69,6 +73,9 @@ directory structure expected by pywb
self._create_dir(self.static_dir)
self._create_dir(self.templates_dir)
self._create_dir(self._get_root_dir('static_path'))
self._create_dir(self._get_root_dir('templates_dir'))
def _assert_coll_exists(self):
if not os.path.isdir(self.coll_dir):
raise IOError('Collection {0} does not exist'.
@ -224,10 +231,6 @@ directory structure expected by pywb
filename = shared_templates[template_name]
full_path = os.path.join(os.getcwd(), filename)
# Create templates dir on demand
dir_ = os.path.dirname(full_path)
if not os.path.isdir(dir_):
os.makedirs(dir_)
except KeyError:
msg = 'template name must be one of {0} or {1}'
msg = msg.format(templates.keys(), shared_templates.keys())

View File

@ -134,6 +134,13 @@ class DirectoryCollsLoader(object):
def __call__(self):
colls = {}
static_dir = self.config.get('paths')['static_path']
static_shared_prefix = self.config.get('static_shared_prefix')
if static_dir and static_shared_prefix and os.path.isdir(static_dir):
static_dir = os.path.abspath(static_dir) + os.path.sep
self.static_routes[static_shared_prefix] = static_dir
root_dir = self.config.get('collections_root', '')
if not root_dir or not os.path.isdir(root_dir):
return colls

View File

@ -90,7 +90,7 @@ setup(
cdx-indexer = pywb.warc.cdxindexer:main
live-rewrite-server = pywb.apps.live_rewrite_server:main
proxy-cert-auth = pywb.framework.certauth:main
wayback-manager = pywb.manager.manager:main_wrap_exc
wb-manager = pywb.manager.manager:main_wrap_exc
""",
classifiers=[
'Development Status :: 4 - Beta',

View File

@ -195,6 +195,20 @@ class TestManagedColls(object):
assert resp.content_type == 'application/javascript'
assert '/* Some JS File */' in resp.body
def test_add_shared_static(self):
""" Test adding shared static file to root static/ dir, check access
"""
a_static = os.path.join(self.root_dir, 'static', 'foo.css')
with open(a_static, 'w+b') as fh:
fh.write('/* Some CSS File */')
self._create_app()
resp = self.testapp.get('/static/__shared/foo.css')
assert resp.status_int == 200
assert resp.content_type == 'text/css'
assert '/* Some CSS File */' in resp.body
def test_add_title_metadata_index_page(self):
""" Test adding title metadata to a collection, test
retrieval on default index page

View File

@ -153,7 +153,7 @@ class TestProxyHttpCookie:
# static replay
def test_replay_static(self):
resp = self.get_url('http://pywb.proxy/static/default/wb.js')
resp = self.get_url('http://pywb.proxy/static/__pywb/wb.js')
assert resp.status_code == 200
assert 'function init_banner' in resp.text

View File

@ -171,7 +171,7 @@ class TestProxyHttpsCookie:
# static replay
def test_replay_static(self):
resp = self.get_url('https://pywb.proxy/static/default/wb.js')
resp = self.get_url('https://pywb.proxy/static/__pywb/wb.js')
assert resp.status_code == 200
assert 'function init_banner' in resp.text