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:
parent
0b8fd1e82e
commit
bfe590996b
@ -38,11 +38,14 @@ not_found_html: templates/not_found.html
|
|||||||
proxy_cert_download_html: templates/proxy_cert_download.html
|
proxy_cert_download_html: templates/proxy_cert_download.html
|
||||||
proxy_select_html: templates/proxy_select.html
|
proxy_select_html: templates/proxy_select.html
|
||||||
|
|
||||||
|
static_default_prefix: &static_default_prefix static/__pywb
|
||||||
|
static_shared_prefix: static/__shared
|
||||||
|
|
||||||
template_globals:
|
template_globals:
|
||||||
static_path: static/default
|
static_path: *static_default_prefix
|
||||||
|
|
||||||
static_routes:
|
static_routes:
|
||||||
static/default: pywb/static/
|
*static_default_prefix: pywb/static/
|
||||||
|
|
||||||
enable_memento: true
|
enable_memento: true
|
||||||
|
|
||||||
|
@ -50,6 +50,10 @@ directory structure expected by pywb
|
|||||||
if os.path.isdir(os.path.join(self.root_dir, d)):
|
if os.path.isdir(os.path.join(self.root_dir, d)):
|
||||||
print('- ' + 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):
|
def _get_dir(self, name):
|
||||||
return os.path.join(self.coll_dir,
|
return os.path.join(self.coll_dir,
|
||||||
self.default_config['paths'][name])
|
self.default_config['paths'][name])
|
||||||
@ -69,6 +73,9 @@ directory structure expected by pywb
|
|||||||
self._create_dir(self.static_dir)
|
self._create_dir(self.static_dir)
|
||||||
self._create_dir(self.templates_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):
|
def _assert_coll_exists(self):
|
||||||
if not os.path.isdir(self.coll_dir):
|
if not os.path.isdir(self.coll_dir):
|
||||||
raise IOError('Collection {0} does not exist'.
|
raise IOError('Collection {0} does not exist'.
|
||||||
@ -224,10 +231,6 @@ directory structure expected by pywb
|
|||||||
filename = shared_templates[template_name]
|
filename = shared_templates[template_name]
|
||||||
full_path = os.path.join(os.getcwd(), filename)
|
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:
|
except KeyError:
|
||||||
msg = 'template name must be one of {0} or {1}'
|
msg = 'template name must be one of {0} or {1}'
|
||||||
msg = msg.format(templates.keys(), shared_templates.keys())
|
msg = msg.format(templates.keys(), shared_templates.keys())
|
||||||
|
@ -134,6 +134,13 @@ class DirectoryCollsLoader(object):
|
|||||||
def __call__(self):
|
def __call__(self):
|
||||||
colls = {}
|
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', '')
|
root_dir = self.config.get('collections_root', '')
|
||||||
if not root_dir or not os.path.isdir(root_dir):
|
if not root_dir or not os.path.isdir(root_dir):
|
||||||
return colls
|
return colls
|
||||||
|
2
setup.py
2
setup.py
@ -90,7 +90,7 @@ setup(
|
|||||||
cdx-indexer = pywb.warc.cdxindexer:main
|
cdx-indexer = pywb.warc.cdxindexer:main
|
||||||
live-rewrite-server = pywb.apps.live_rewrite_server:main
|
live-rewrite-server = pywb.apps.live_rewrite_server:main
|
||||||
proxy-cert-auth = pywb.framework.certauth: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=[
|
classifiers=[
|
||||||
'Development Status :: 4 - Beta',
|
'Development Status :: 4 - Beta',
|
||||||
|
@ -195,6 +195,20 @@ class TestManagedColls(object):
|
|||||||
assert resp.content_type == 'application/javascript'
|
assert resp.content_type == 'application/javascript'
|
||||||
assert '/* Some JS File */' in resp.body
|
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):
|
def test_add_title_metadata_index_page(self):
|
||||||
""" Test adding title metadata to a collection, test
|
""" Test adding title metadata to a collection, test
|
||||||
retrieval on default index page
|
retrieval on default index page
|
||||||
|
@ -153,7 +153,7 @@ class TestProxyHttpCookie:
|
|||||||
|
|
||||||
# static replay
|
# static replay
|
||||||
def test_replay_static(self):
|
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 resp.status_code == 200
|
||||||
assert 'function init_banner' in resp.text
|
assert 'function init_banner' in resp.text
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ class TestProxyHttpsCookie:
|
|||||||
|
|
||||||
# static replay
|
# static replay
|
||||||
def test_replay_static(self):
|
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 resp.status_code == 200
|
||||||
assert 'function init_banner' in resp.text
|
assert 'function init_banner' in resp.text
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user