degal/commands/main.py
author Tero Marttila <terom@fixme.fi>
Thu, 11 Jun 2009 21:46:20 +0300
changeset 94 676c1d201cfe
parent 87 a7a18893730d
child 101 698dc68a985d
permissions -rw-r--r--
slightly reoriganize function structure in commands.main
76
e22d9f699081 misc. fixes
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
     1
from degal.command import command
66
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
     2
from degal import templates
48
20355dd2e61a new structure for bin/degal, adding degal/commands, degal/main
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
94
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
     4
def render_image_html (ctx, image) :
66
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
     5
    """
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
     6
        Render the thumbnails and .html for one image
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
     7
    """
87
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
     8
66
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
     9
    # render output
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    10
    tpl = templates.master(ctx.gallery, image.title, image.html, 
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    11
        templates.image_page(image)
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    12
    )
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    13
    
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    14
    # write output
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    15
    tpl.render_file(image.html)
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    16
94
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    17
def render_image_thumbs (image) :
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    18
    """
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    19
        Render the thubmnails for the given image
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    20
    """
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    21
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    22
    image.update()
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    23
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    24
def render_folder_images (ctx, images) :
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    25
    """
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    26
        Render the given series of images
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    27
    """
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    28
    
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    29
    # render them in parallel as required
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    30
    for image in images :
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    31
        # log image path
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    32
        ctx.log_info("%s", image)
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    33
        
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    34
        # render output thumbs
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    35
        render_image_thumbs(image)
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    36
        
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    37
        # render HTML
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    38
        render_image_html(ctx, image)
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    39
87
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    40
def render_folder_page (ctx, folder) :
48
20355dd2e61a new structure for bin/degal, adding degal/commands, degal/main
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
    """
87
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    42
        Render the .html output for one folder
48
20355dd2e61a new structure for bin/degal, adding degal/commands, degal/main
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
    """
20355dd2e61a new structure for bin/degal, adding degal/commands, degal/main
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
87
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    45
    # render each page separately
66
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    46
    for page in xrange(folder.page_count) :
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    47
        # output .html page
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    48
        html_file = folder.html_file(page)
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    49
        
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    50
        # render template
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    51
        tpl = templates.master(ctx.gallery, folder.title, html_file,
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    52
            templates.folder_page(folder, page)
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    53
        )
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    54
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    55
        # write output
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    56
        tpl.render_file(html_file)
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    57
87
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    58
def render_folder (ctx, folder) :
94
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    59
    """
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    60
        Render the HTML/images for this folder if needed, and recrurse into subfolders.
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    61
    """
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    62
87
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    63
    # index images that require updating
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    64
    image_count = len(folder.images)
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    65
    new_images = list(folder.index_images(for_update=(not ctx.config.force_update)))
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    66
    
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    67
    if new_images or ctx.config.force_update:
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    68
        # update folder index
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    69
        render_folder_page(ctx, folder)
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    70
        
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    71
        ctx.log_info("%s - render %d/%d images", folder, len(new_images), image_count)
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    72
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    73
        # update images
94
676c1d201cfe slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    74
        render_folder_images(ctx, new_images)
87
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    75
    
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    76
    else :
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    77
        ctx.log_info("%s - up to date", folder)
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    78
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    79
    # index subfolders
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    80
    for subfolder in folder.subfolders :
a7a18893730d implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents: 76
diff changeset
    81
        render_folder(ctx, subfolder)
66
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    82
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    83
@command
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    84
def main (ctx) :
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    85
    """
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    86
        Scan the gallery for new folders/images, and render updated ones
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    87
    """
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    88
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    89
    # render the gallery
322e5cd0cb1f implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    90
    render_folder(ctx, ctx.gallery)
48
20355dd2e61a new structure for bin/degal, adding degal/commands, degal/main
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    91