diff --git a/pywb/default_config.yaml b/pywb/default_config.yaml index 61137db9..9311c3f2 100644 --- a/pywb/default_config.yaml +++ b/pywb/default_config.yaml @@ -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 diff --git a/pywb/manager/manager.py b/pywb/manager/manager.py index 8ab79d13..9bd57a6b 100644 --- a/pywb/manager/manager.py +++ b/pywb/manager/manager.py @@ -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()) diff --git a/pywb/webapp/pywb_init.py b/pywb/webapp/pywb_init.py index 42de9e19..cad3d1a6 100644 --- a/pywb/webapp/pywb_init.py +++ b/pywb/webapp/pywb_init.py @@ -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 diff --git a/setup.py b/setup.py index e68285d9..b0e89c60 100755 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/tests/test_auto_colls.py b/tests/test_auto_colls.py index 5d636b7f..6b140b15 100644 --- a/tests/test_auto_colls.py +++ b/tests/test_auto_colls.py @@ -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 diff --git a/tests/test_proxy_http_cookie.py b/tests/test_proxy_http_cookie.py index 16138d01..498ec056 100644 --- a/tests/test_proxy_http_cookie.py +++ b/tests/test_proxy_http_cookie.py @@ -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 diff --git a/tests/test_proxy_https_cookie.py b/tests/test_proxy_https_cookie.py index 97a23a3f..753d380b 100644 --- a/tests/test_proxy_https_cookie.py +++ b/tests/test_proxy_https_cookie.py @@ -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