diff --git a/pywb/default_config.yaml b/pywb/default_config.yaml index be51bc3c..61137db9 100644 --- a/pywb/default_config.yaml +++ b/pywb/default_config.yaml @@ -1,8 +1,3 @@ -#collections: -# pywb: ./sample_archive/cdx/ - -#archive_paths: ./sample_archive/warcs/ - collections_root: collections paths: diff --git a/pywb/manager/manager.py b/pywb/manager/manager.py index 335b1bb3..8ab79d13 100644 --- a/pywb/manager/manager.py +++ b/pywb/manager/manager.py @@ -217,17 +217,20 @@ directory structure expected by pywb 'a collection name: template --{1} {0}') raise IOError(msg.format(template_name, verb)) - full_path = os.path.join(self.templates_dir, - os.path.basename(filename)) + full_path = os.path.join(self.templates_dir, os.path.basename(filename)) except KeyError: try: filename = shared_templates[template_name] - full_path = os.path.join(os.getcwd(), - os.path.basename(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: msg = 'template name must be one of {0} or {1}' - msg.format(templates.keys(), shared_templates.keys()) + msg = msg.format(templates.keys(), shared_templates.keys()) raise KeyError(msg) return full_path, filename diff --git a/pywb/templates/index.html b/pywb/templates/index.html index af9db3cb..fa2c2a4f 100644 --- a/pywb/templates/index.html +++ b/pywb/templates/index.html @@ -1,3 +1,6 @@ + + +

pywb Wayback Machine

This archive contains the following collections: @@ -14,4 +17,5 @@ This archive contains the following collections: {% endif %} {% endfor %} - + + diff --git a/tests/test_auto_colls.py b/tests/test_auto_colls.py index e4446ae8..5d636b7f 100644 --- a/tests/test_auto_colls.py +++ b/tests/test_auto_colls.py @@ -274,17 +274,13 @@ class TestManagedColls(object): resp = self.testapp.get('/test/20140103030321/http://example.com?example=1') assert resp.status_int == 200 - def test_add_default_templates(self): - """ Test add default templates: shared, collection, + def test_add_default_coll_templates(self): + """ Test add default templates: collection, and overwrite collection template """ # list main(['template', 'foo', '--list']) - # Add shared template - main(['template', '--add', 'home_html']) - assert os.path.isfile(os.path.join(self.root_dir, 'index.html')) - # Add collection template main(['template', 'foo', '--add', 'query_html']) assert os.path.isfile(os.path.join(self.root_dir, 'collections', 'foo', 'templates', 'query.html')) @@ -292,6 +288,24 @@ class TestManagedColls(object): # overwrite -- force main(['template', 'foo', '--add', 'query_html', '-f']) + def test_add_modify_home_template(self): + # Add shared template + main(['template', '--add', 'home_html']) + + filename = os.path.join(self.root_dir, 'templates', 'index.html') + assert os.path.isfile(filename) + + with open(filename, 'r+b') as fh: + buf = fh.read() + buf = buf.replace('', 'Custom Test Homepage') + fh.seek(0) + fh.write(buf) + + self._create_app() + resp = self.testapp.get('/') + assert resp.content_type == 'text/html' + assert 'Custom Test Homepage' in resp.body, resp.body + @patch('pywb.manager.manager.get_input', lambda x: 'y') def test_add_template_input_yes(self): """ Test answer 'yes' to overwrite