# HG changeset patch # User Tero Marttila # Date 1244232038 -10800 # Node ID 322e5cd0cb1f020e968e264517bb046e2d0ea16f # Parent 97e1bc208574ea92aab8f1a73cf2b4fd8db3dedc implement new main() command, remove old one diff -r 97e1bc208574 -r 322e5cd0cb1f degal/commands.py --- a/degal/commands.py Fri Jun 05 23:00:21 2009 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -""" - Implementations of the core CLI commands -""" - -import log, shorturl, folder - -def main (dir='.', targets=()) : - """ - Scan the given root dir for all images, and render updated ones - """ - - root_filter = {} - - # parse the targets into the hierarchial root_filter that we use - for target in targets : - f = root_filter - for path_part in target.split('/') : - if path_part : - if path_part not in f : - f[path_part] = {} - - f = f[path_part] - - # build the index - log.title("Indexing %s...", dir) - root = folder.Folder(dir) - root.index(root_filter) - log.up() - - # XXX: maintain shorturls stuff - if False : - log.title("Syncing ShortURLs...") - shorturl.updateDB(root) - log.up() - - # render output - log.title("Rendering updated dirs...") - root.render() - log.up() - - return 0 - diff -r 97e1bc208574 -r 322e5cd0cb1f degal/commands/main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/degal/commands/main.py Fri Jun 05 23:00:38 2009 +0300 @@ -0,0 +1,53 @@ +from degal.commands import command +from degal import templates + +def render_image (ctx, image) : + """ + Render the thumbnails and .html for one image + """ + + # log image path + ctx.log_debug("%s", image) + + # render output + tpl = templates.master(ctx.gallery, image.title, image.html, + templates.image_page(image) + ) + + # write output + tpl.render_file(image.html) + +def render_folder (ctx, folder) : + """ + Render the .html output for one folder, recursively + """ + + # log folder path + ctx.log_debug("%s", folder) + + # render folder index + for page in xrange(folder.page_count) : + # output .html page + html_file = folder.html_file(page) + + # render template + tpl = templates.master(ctx.gallery, folder.title, html_file, + templates.folder_page(folder, page) + ) + + # write output + tpl.render_file(html_file) + + # render images + for image in folder.images : + render_image(ctx, image) + +@command +def main (ctx) : + """ + Scan the gallery for new folders/images, and render updated ones + """ + + # render the gallery + render_folder(ctx, ctx.gallery) +