Commit efa1113c authored by Michael Murtaugh's avatar Michael Murtaugh

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

parent cd6f3a2b
...@@ -337,6 +337,7 @@ def main (args=None): ...@@ -337,6 +337,7 @@ def main (args=None):
# parser.add_argument('--htdocs', default="~/cookbook/", help='') # parser.add_argument('--htdocs', default="~/cookbook/", help='')
parser.add_argument('--cgibin', default="~/cgi-bin", help='') parser.add_argument('--cgibin', default="~/cgi-bin", help='')
parser.add_argument('--index', default=None, help='default: index.cgi') 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('--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('--alias', nargs="+", action="append", help='Add a folder to serve, syntax is [mountpoint path] ... ')
parser.add_argument('--authentication', default=None, help='') parser.add_argument('--authentication', default=None, help='')
...@@ -386,7 +387,13 @@ def main (args=None): ...@@ -386,7 +387,13 @@ def main (args=None):
listing = args.index listing = args.index
else: else:
# listing = CGIScript(os.path.join(corecgibinpath, "index.cgi")) # 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) root_resource = FileMaker(docroot, make_requests, docroot, listing, makefile)
corehtdocs = File(corehtdocspath) corehtdocs = File(corehtdocspath)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from __future__ import division, print_function from __future__ import division, print_function
import os, urlparse, urllib, subprocess, re, datetime import os, urlparse, urllib, subprocess, re, datetime
from urllib import quote as urlquote, unquote as urlunquote
import jinja2 import jinja2
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
import sys # debug output import sys # debug output
...@@ -97,6 +98,8 @@ class MakeDirectoryListingFactory (object): ...@@ -97,6 +98,8 @@ class MakeDirectoryListingFactory (object):
env = Environment(loader=templates) env = Environment(loader=templates)
env.filters['strftime'] = strftime env.filters['strftime'] = strftime
env.filters['humanize_bytes'] = humanize_bytes env.filters['humanize_bytes'] = humanize_bytes
env.filters['urlquote'] = urlquote
env.filters['urlunquote'] = urlunquote
self.template = env.get_template(tname) self.template = env.get_template(tname)
self.docroot = docroot 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