degal/commands.py
author Tero Marttila <terom@fixme.fi>
Wed, 03 Jun 2009 20:33:15 +0300
branchuse-distutils
changeset 48 20355dd2e61a
permissions -rw-r--r--
new structure for bin/degal, adding degal/commands, degal/main
"""
    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