#! /usr/bin/python
if __name__ == "__main__":
import locale ; locale.setlocale(locale.LC_ALL, '')
import os, sys
import kid
kid.enable_import()
# Parse the arguments. At the moment this is total overkill, but I might
# pass options to this at some point.
import optparse
parser = optparse.OptionParser("usage: %prog ")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose logging to stderr")
parser.add_option("-t", "--template", dest="formatter", default="rss2galleryhtml", help="Name of the template to use (default rss2galleryhtml)", metavar="TEMPLATE")
(options, args) = parser.parse_args()
if len(args) != 2:
parser.error("Wrong number of arguments")
# Split the arguments up
(base_uri, path) = args
# Work out the file names we'll be dealing with
rssfile = os.path.join(path, "index.rss")
htmlfile = os.path.join(path, "index.html")
# Generate the RSS
import GalleryRSSGenerator
rss = GalleryRSSGenerator.generate_rss(path=path, baseurl=base_uri, verbose=options.verbose)
file(rssfile, "w").write(str(rss))
if options.verbose:
sys.stderr.write("Written RSS file %s\n" % rssfile)
# Generate the HTML
formatter = __import__(options.formatter)
t = formatter.Template(rssdata=rss)
t.write(file=file(htmlfile, "w"), encoding="ascii", output='xhtml')
if options.verbose:
sys.stderr.write("Written HTML file %s\n" % htmlfile)
# Copy the CSS file to the right location
# TODO: also pass a site base URL and copy the CSS there, after passing the
# same URL to the template so it loads the CSS
import shutil
shutil.copy("/home/ross/Programming/tate/gallery.css", path)