Commit efa1113c authored by murtaugh's avatar murtaugh

added index-template option to customize dirlisting (edit link)

parent cd6f3a2b
......@@ -337,6 +337,7 @@ def main (args=None):
# parser.add_argument('--htdocs', default="~/cookbook/", help='')
parser.add_argument('--cgibin', default="~/cgi-bin", help='')
parser.add_argument('--index', default=None, help='default: index.cgi')
parser.add_argument('--index-template', default=None, help='set to override default index.html template')
parser.add_argument('--makefile', default=None, help='location of the makefile to use, default ./makefile')
parser.add_argument('--alias', nargs="+", action="append", help='Add a folder to serve, syntax is [mountpoint path] ... ')
parser.add_argument('--authentication', default=None, help='')
......@@ -386,7 +387,13 @@ def main (args=None):
listing = args.index
else:
# listing = CGIScript(os.path.join(corecgibinpath, "index.cgi"))
listing = MakeDirectoryListingFactory(makefile, os.path.join(getDataPath("templates"), "index.html"), docroot)
if args.index_template:
index_template_path = os.path.abspath(args.index_template)
print ("Using custom index template: {0}".format(index_template_path), file=sys.stderr)
else:
index_template_path = os.path.join(getDataPath("templates"), "index.html")
listing = MakeDirectoryListingFactory(makefile, index_template_path, docroot)
root_resource = FileMaker(docroot, make_requests, docroot, listing, makefile)
corehtdocs = File(corehtdocspath)
......
......@@ -2,6 +2,7 @@
from __future__ import division, print_function
import os, urlparse, urllib, subprocess, re, datetime
from urllib import quote as urlquote, unquote as urlunquote
import jinja2
from jinja2 import Environment, FileSystemLoader
import sys # debug output
......@@ -97,6 +98,8 @@ class MakeDirectoryListingFactory (object):
env = Environment(loader=templates)
env.filters['strftime'] = strftime
env.filters['humanize_bytes'] = humanize_bytes
env.filters['urlquote'] = urlquote
env.filters['urlunquote'] = urlunquote
self.template = env.get_template(tname)
self.docroot = docroot
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment