author | Tero Marttila <terom@fixme.fi> |
Mon, 15 Jun 2009 00:29:43 +0300 | |
changeset 123 | 31c4a328ef96 |
parent 119 | e7855eefb4c7 |
child 131 | 7021d949222c |
permissions | -rw-r--r-- |
76 | 1 |
from degal.command import command |
117 | 2 |
from degal.concurrent import task |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
3 |
from degal import templates |
48
20355dd2e61a
new structure for bin/degal, adding degal/commands, degal/main
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
|
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
5 |
def render_image_html (ctx, image) : |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
6 |
""" |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
7 |
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
|
8 |
""" |
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
9 |
|
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
10 |
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
|
11 |
|
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
12 |
# render output |
119 | 13 |
tpl = templates.master(ctx.gallery, image, |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
14 |
templates.image_page(image) |
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 |
|
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
17 |
# write output |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
18 |
tpl.render_file(image.html) |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
19 |
|
117 | 20 |
def update_image_thumbs (image) : |
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
21 |
""" |
117 | 22 |
Render the thubmnails for the given image, returning the image. |
23 |
||
24 |
This /should/ be threadsafe. |
|
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
25 |
""" |
117 | 26 |
|
27 |
# this will unconditionally update the image |
|
28 |
image.update() |
|
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
29 |
|
117 | 30 |
return image |
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
31 |
|
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
32 |
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
|
33 |
""" |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
34 |
Render the given series of images |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
35 |
""" |
118
60b126ff0b74
configuration magic - can now load configuration data from ./degal.cfg, --config, folder/degal.cfg
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
36 |
|
60b126ff0b74
configuration magic - can now load configuration data from ./degal.cfg, --config, folder/degal.cfg
Tero Marttila <terom@fixme.fi>
parents:
117
diff
changeset
|
37 |
# XXX: handle this thumb-update/html-update stuff better |
123
31c4a328ef96
move the uncache-del's from commands.main to Image.cleanup, and call it after rendering each image's thumbs
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
38 |
|
31c4a328ef96
move the uncache-del's from commands.main to Image.cleanup, and call it after rendering each image's thumbs
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
39 |
# render all HTML |
31c4a328ef96
move the uncache-del's from commands.main to Image.cleanup, and call it after rendering each image's thumbs
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
40 |
for image in images : |
31c4a328ef96
move the uncache-del's from commands.main to Image.cleanup, and call it after rendering each image's thumbs
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
41 |
render_image_html(ctx, image) |
31c4a328ef96
move the uncache-del's from commands.main to Image.cleanup, and call it after rendering each image's thumbs
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
42 |
|
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
43 |
|
117 | 44 |
# render the thumbnails concurrently |
45 |
for image in ctx.concurrent.execute( |
|
46 |
task(update_image_thumbs, image) |
|
47 |
||
48 |
for image in images |
|
49 |
||
50 |
# only test if not already filtered for update |
|
51 |
# XXX: externalize logic |
|
52 |
if for_update or ctx.config.force_thumb or image.stale() |
|
53 |
) : |
|
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
54 |
# log image path |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
55 |
ctx.log_info("%s", image) |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
56 |
|
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
57 |
# release large objects that are not needed anymore |
123
31c4a328ef96
move the uncache-del's from commands.main to Image.cleanup, and call it after rendering each image's thumbs
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
58 |
image.cleanup() |
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
59 |
|
117 | 60 |
def render_folder_html (ctx, folder) : |
48
20355dd2e61a
new structure for bin/degal, adding degal/commands, degal/main
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
""" |
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
62 |
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
|
63 |
""" |
20355dd2e61a
new structure for bin/degal, adding degal/commands, degal/main
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
64 |
|
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
65 |
# render each page separately |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
66 |
for page in xrange(folder.page_count) : |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
67 |
# output .html page |
119 | 68 |
html = folder.html_page(page) |
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
69 |
|
119 | 70 |
ctx.log_debug("%s", html) |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
71 |
|
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
72 |
# render template |
119 | 73 |
tpl = templates.master(ctx.gallery, folder, |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
74 |
templates.folder_page(folder, page) |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
75 |
) |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
76 |
|
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
77 |
# write output |
119 | 78 |
tpl.render_file(html) |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
79 |
|
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
80 |
def render_folder (ctx, folder) : |
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
81 |
""" |
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
82 |
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
|
83 |
""" |
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
84 |
|
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
85 |
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
|
86 |
# index all |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
87 |
for_update = False |
94
676c1d201cfe
slightly reoriganize function structure in commands.main
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
88 |
|
101
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
89 |
else : |
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
90 |
# 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
|
91 |
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
|
92 |
|
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
93 |
# 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
|
94 |
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
|
95 |
|
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
96 |
# 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
|
97 |
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
|
98 |
|
698dc68a985d
split --force-update into --force-thumb/--force-html options, implement for main
Tero Marttila <terom@fixme.fi>
parents:
94
diff
changeset
|
99 |
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
|
100 |
# update folder index |
117 | 101 |
render_folder_html(ctx, folder) |
87
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
102 |
|
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
103 |
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
|
104 |
|
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
105 |
# 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
|
106 |
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
|
107 |
|
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
108 |
else : |
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
109 |
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
|
110 |
|
a7a18893730d
implement up-to-date checking for commands.main, and add --force-update option
Tero Marttila <terom@fixme.fi>
parents:
76
diff
changeset
|
111 |
# 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
|
112 |
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
|
113 |
render_folder(ctx, subfolder) |
66
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
114 |
|
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
115 |
@command |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
116 |
def main (ctx) : |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
117 |
""" |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
118 |
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
|
119 |
""" |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
120 |
|
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
121 |
# render the gallery |
322e5cd0cb1f
implement new main() command, remove old one
Tero Marttila <terom@fixme.fi>
parents:
48
diff
changeset
|
122 |
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
|
123 |