author | Tero Marttila <terom@fixme.fi> |
Sun, 14 Jun 2009 18:08:55 +0300 | |
changeset 115 | d5aa320697df |
parent 113 | 3e0bbacc917e |
child 117 | a2e4562deaab |
permissions | -rw-r--r-- |
76 | 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 |
|
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
9 |
ctx.log_debug("%s", image.html) |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
10 |
|
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
11 |
# render output |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
12 |
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
|
13 |
templates.image_page(image) |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
14 |
) |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
15 |
|
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
16 |
# write output |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
17 |
tpl.render_file(image.html) |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
18 |
|
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
19 |
def render_image_thumbs (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 |
Render the thubmnails for the given image |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
22 |
""" |
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 |
image.update() |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
25 |
|
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
26 |
def render_folder_images (ctx, images, for_update=True) : |
94
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 |
Render the given series of images |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
29 |
""" |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
30 |
|
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
31 |
# render them in parallel as required |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
32 |
for image in images : |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
33 |
# log image path |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
34 |
ctx.log_info("%s", image) |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
35 |
|
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
36 |
# only test if not already filtered for update |
113
3e0bbacc917e
fix commands.main to force-render thumbs if asked to
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
37 |
if for_update or ctx.config.force_thumb or image.stale() : |
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
38 |
# render output thumbs |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
39 |
render_image_thumbs(image) |
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
40 |
|
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
41 |
# render HTML |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
42 |
render_image_html(ctx, image) |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
43 |
|
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
44 |
# release large objects that are not needed anymore |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
45 |
# XXX: verify that this works |
115
d5aa320697df
rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents:
113
diff
changeset
|
46 |
del image.img |
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
47 |
|
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
48 |
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
|
49 |
""" |
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
50 |
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
|
51 |
""" |
20355dd2e61a
new structure for bin/degal, adding degal/commands, degal/main
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
52 |
|
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
53 |
# render each page separately |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
54 |
for page in xrange(folder.page_count) : |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
55 |
# output .html page |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
56 |
html_file = folder.html_file(page) |
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
57 |
|
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
58 |
ctx.log_debug("%s", html_file) |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
59 |
|
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
60 |
# render template |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
61 |
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
|
62 |
templates.folder_page(folder, page) |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
63 |
) |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
64 |
|
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
65 |
# write output |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
66 |
tpl.render_file(html_file) |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
67 |
|
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
68 |
def render_folder (ctx, folder) : |
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
69 |
""" |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
70 |
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
|
71 |
""" |
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
72 |
|
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
73 |
if ctx.config.force_html or ctx.config.force_thumb : |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
74 |
# index all |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
75 |
for_update = False |
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
76 |
|
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
77 |
else : |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
78 |
# only new images |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
79 |
for_update = True |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
80 |
|
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
81 |
# full count of 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
|
82 |
image_count = len(folder.images) |
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
83 |
|
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
84 |
# index selected images |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
85 |
new_images = list(folder.index_images(for_update=for_update)) |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
86 |
|
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
87 |
if new_images or ctx.config.force_html : |
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
88 |
# 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
|
89 |
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
|
90 |
|
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
91 |
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
|
92 |
|
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
93 |
# update images |
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
94 |
render_folder_images(ctx, new_images, for_update) |
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
95 |
|
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
96 |
else : |
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
97 |
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
|
98 |
|
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
99 |
# 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
|
100 |
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
|
101 |
render_folder(ctx, subfolder) |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
102 |
|
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
103 |
@command |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
104 |
def main (ctx) : |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
105 |
""" |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
106 |
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
|
107 |
""" |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
108 |
|
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
109 |
# render the gallery |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
110 |
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
|
111 |