author | Tero Marttila <terom@fixme.fi> |
Fri, 05 Jun 2009 21:50:49 +0300 | |
changeset 64 | 4ebd563214d2 |
parent 44 | 533b7e8b5d3b |
child 70 | 67dd32adf159 |
permissions | -rw-r--r-- |
64
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
1 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
2 |
Per-directory gallery state |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
3 |
""" |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
4 |
|
64
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
5 |
import filesystem, image, html |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
6 |
|
64
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
7 |
from utils import lazy_load |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
8 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
9 |
class Folder (filesyste.Directory) : |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
10 |
""" |
64
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
11 |
A Folder is a filesystem Directory that contains any number of other Folders and Images. |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
12 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
13 |
|
64
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
14 |
def __init__ (self, node) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
15 |
super(Folder, self).__init__(node) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
16 |
|
64
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
17 |
# info |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
18 |
self.title = None |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
19 |
self.description = None |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
20 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
21 |
@lazy_load |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
22 |
def preview_dir (self) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
23 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
24 |
Load and return the Directory for previews |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
25 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
26 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
27 |
return self.subdir(self.config.preview_dir, create=True) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
28 |
|
64
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
29 |
@lazy_load |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
30 |
def thumb_dir (self) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
31 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
32 |
Load and return the Directory for thumbs |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
33 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
34 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
35 |
return self.subdir(self.config.thumb_dir, create=True) |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
36 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
37 |
@lazy_load_iter |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
38 |
def subnodes (self) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
39 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
40 |
Load and return an ordered list of child-Nodes |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
41 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
42 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
43 |
return super(Folder, self).subnodes(skip_dotfiles=True, sorted=True) |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
44 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
45 |
@lazy_load_iter |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
46 |
def subfolders (self) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
47 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
48 |
Load and return an ordered list of sub-Folders |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
49 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
50 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
51 |
return (Folder(node) for node in self.subnodes if isinstance(node, filesystem.Directory)) |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
52 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
53 |
@lazy_load_iter |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
54 |
def images (self) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
55 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
56 |
Load and return an ordered/linked list of sub-Images |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
57 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
58 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
59 |
prev = None |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
60 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
61 |
for node in self.subnodes : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
62 |
# skip non-relevant ones |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
63 |
# XXX: node should need to be a File |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
64 |
if not isinstance(node, filesystem.File) or not self.config.is_image(node) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
65 |
continue |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
66 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
67 |
# create new |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
68 |
img = image.Image(node, prev) |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
69 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
70 |
# link up |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
71 |
if prev : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
72 |
prev.next = img |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
73 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
74 |
# yield the linked-up prev |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
75 |
yield prev |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
76 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
77 |
# continue |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
78 |
prev = img |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
79 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
80 |
# and the last one |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
81 |
if prev : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
82 |
yield prev |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
83 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
84 |
@property |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
85 |
def page_count (self) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
86 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
87 |
Returns the number of pages needed to show this folder's images |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
88 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
89 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
90 |
return math.ceil(len(self.images) / float(self.config.images_per_page)) |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
91 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
92 |
def images_for_page (self, page) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
93 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
94 |
Returns the list of Images to be displayed for the given page, if any |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
95 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
96 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
97 |
# offset to first image |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
98 |
offset = page * self.config.images_per_page |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
99 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
100 |
# slice |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
101 |
return self.images[offset : offset + self.config.images_per_page] |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
102 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
103 |
def html_file (self, page=0) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
104 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
105 |
Returns the File representing the .html for the given page |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
106 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
107 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
108 |
if page : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
109 |
return self.subfile("index_%d.html" % page) |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
110 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
111 |
else : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
112 |
return self.subfile("index.html") |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
113 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
114 |
def index (self) : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
115 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
116 |
Recursively index this Folder, yielding a series of all Folder objects inside. |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
117 |
""" |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
118 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
119 |
# and subfolders |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
120 |
for subfolder in self.subfolders : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
121 |
yield subfolder |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
122 |
|
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
123 |
for item in subfolder.index_subfolders() : |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
124 |
yield item |
4ebd563214d2
begin implementation of folder, gallery
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
125 |
|
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
126 |
class Folder (object) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
127 |
def __init__ (self, name='.', parent=None) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
128 |
# the directory name, no trailing / |
27
301d738b1181
fix some unicode issues, and not-alive-dirs-in-subdirs-list issues
terom
parents:
26
diff
changeset
|
129 |
self.name = unicode(name.rstrip(os.sep)) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
130 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
131 |
# our parent Folder, or None |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
132 |
self.parent = parent |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
133 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
134 |
# the path to this dir, as a relative path to the root of the image gallery, always starts with . |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
135 |
if parent and name : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
136 |
self.path = parent.pathFor(self.name) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
137 |
else : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
138 |
self.path = self.name |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
139 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
140 |
# the url-path to the index.html file |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
141 |
self.html_path = self.path |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
142 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
143 |
# dict of fname -> Folder |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
144 |
self.subdirs = {} |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
145 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
146 |
# dict of fname -> Image |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
147 |
self.images = {} |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
148 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
149 |
# our human-friendly title |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
150 |
self.title = None |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
151 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
152 |
# our long-winded description |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
153 |
self.descr = '' |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
154 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
155 |
# is this folder non-empty? |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
156 |
self.alive = None |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
157 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
158 |
# self.images.values(), but sorted by filename |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
159 |
self.sorted_images = [] |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
160 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
161 |
# the ShortURL key to this dir |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
162 |
self.shorturl_code = None |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
163 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
164 |
# were we filtered out? |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
165 |
self.filtered = False |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
166 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
167 |
def pathFor (self, *fnames) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
168 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
169 |
Return a root-relative path to the given path inside this dir |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
170 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
171 |
return os.path.join(self.path, *fnames) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
172 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
173 |
def index (self, filters=None) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
174 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
175 |
Look for other dirs and images inside this dir. Filters must be either None, |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
176 |
whereupon all files will be included, or a dict of {filename -> next_filter}. |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
177 |
If given, only filenames that are present in the dict will be indexed, and in |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
178 |
the case of dirs, the next_filter will be passed on to that Folder's index |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
179 |
method. |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
180 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
181 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
182 |
if filters : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
183 |
self.filtered = True |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
184 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
185 |
# iterate through listdir |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
186 |
for fname in os.listdir(self.path) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
187 |
# the full filesystem path to it |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
188 |
fpath = self.pathFor(fname) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
189 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
190 |
# ignore dotfiles |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
191 |
if fname.startswith('.') : |
28 | 192 |
log.debug("Skipping dotfile %s", fname) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
193 |
continue |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
194 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
195 |
# apply filters |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
196 |
if filters : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
197 |
if fname in filters : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
198 |
next_filter = filters[fname] |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
199 |
else : |
28 | 200 |
log.debug("Skip `%s' as we have a filter", fname) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
201 |
continue |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
202 |
else : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
203 |
next_filter = None |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
204 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
205 |
# recurse into subdirs, but not thumbs/previews |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
206 |
if (os.path.isdir(fpath) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
207 |
and (fname not in (settings.THUMB_DIR, settings.PREVIEW_DIR)) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
208 |
and (self.parent or fname not in settings.ROOT_IGNORE) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
209 |
) : |
28 | 210 |
log.down(fname) |
211 |
||
27
301d738b1181
fix some unicode issues, and not-alive-dirs-in-subdirs-list issues
terom
parents:
26
diff
changeset
|
212 |
f = Folder(fname, self) |
31
09776792a91c
skip folders that result in exceptions, forgotten style.css
terom
parents:
30
diff
changeset
|
213 |
|
09776792a91c
skip folders that result in exceptions, forgotten style.css
terom
parents:
30
diff
changeset
|
214 |
try : |
09776792a91c
skip folders that result in exceptions, forgotten style.css
terom
parents:
30
diff
changeset
|
215 |
if f.index(next_filter) : # recursion |
09776792a91c
skip folders that result in exceptions, forgotten style.css
terom
parents:
30
diff
changeset
|
216 |
# if a subdir is alive, we are alive as well |
09776792a91c
skip folders that result in exceptions, forgotten style.css
terom
parents:
30
diff
changeset
|
217 |
self.subdirs[fname] = f |
09776792a91c
skip folders that result in exceptions, forgotten style.css
terom
parents:
30
diff
changeset
|
218 |
self.alive = True |
09776792a91c
skip folders that result in exceptions, forgotten style.css
terom
parents:
30
diff
changeset
|
219 |
except Exception, e : |
09776792a91c
skip folders that result in exceptions, forgotten style.css
terom
parents:
30
diff
changeset
|
220 |
log.warning("skip - %s: %s" % (type(e), e)) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
221 |
|
28 | 222 |
log.up() |
223 |
||
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
224 |
# handle images |
23 | 225 |
elif os.path.isfile(fpath) and utils.isImage(fname) : |
28 | 226 |
log.next(fname) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
227 |
self.images[fname] = image.Image(self, fname) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
228 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
229 |
# ignore everything else |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
230 |
else : |
28 | 231 |
log.debug("Ignoring file %s", fname) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
232 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
233 |
# sort and link the images |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
234 |
if self.images : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
235 |
self.alive = True |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
236 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
237 |
# sort the images |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
238 |
fnames = self.images.keys() |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
239 |
fnames.sort() |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
240 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
241 |
prev = None |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
242 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
243 |
# link |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
244 |
for fname in fnames : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
245 |
img = self.images[fname] |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
246 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
247 |
img.prev = prev |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
248 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
249 |
if prev : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
250 |
prev.next = img |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
251 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
252 |
prev = img |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
253 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
254 |
# add to the sorted images list |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
255 |
self.sorted_images.append(img) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
256 |
|
26
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
257 |
# figure out our title/ descr. Must be done before our parent dir is rendered (self.title) |
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
258 |
title_path = self.pathFor(settings.TITLE_FILE) |
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
259 |
|
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
260 |
self.title, self.descr = utils.readTitleDescr(title_path) |
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
261 |
|
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
262 |
# default title for the root dir |
27
301d738b1181
fix some unicode issues, and not-alive-dirs-in-subdirs-list issues
terom
parents:
26
diff
changeset
|
263 |
if self.title or self.descr : |
26
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
264 |
self.alive = True |
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
265 |
pass # use what was in the title file |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
266 |
|
26
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
267 |
elif not self.parent : |
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
268 |
self.title = 'Index' |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
269 |
|
26
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
270 |
else : |
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
271 |
self.title = self.name |
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
272 |
|
27
301d738b1181
fix some unicode issues, and not-alive-dirs-in-subdirs-list issues
terom
parents:
26
diff
changeset
|
273 |
if not self.alive : |
28 | 274 |
log.debug("Dir %s isn't alive" % self.path) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
275 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
276 |
return self.alive |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
277 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
278 |
def getObjInfo (self) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
279 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
280 |
Metadata for shorturls2.db |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
281 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
282 |
return 'dir', self.path, '' |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
283 |
|
13
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
284 |
def breadcrumb (self, forImg=None) : |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
285 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
286 |
Returns a [(fname, title)] list of this dir's parent dirs |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
287 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
288 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
289 |
f = self |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
290 |
b = [] |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
291 |
d = 0 |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
292 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
293 |
while f : |
13
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
294 |
# functionality of the slightly-hacked-in variety |
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
295 |
if f is self and forImg is not None : |
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
296 |
url = helpers.url_for_page(self.getPageNumber(forImg)) |
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
297 |
else : |
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
298 |
url = dirUp(d) |
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
299 |
|
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
300 |
b.insert(0, (url, f.title)) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
301 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
302 |
d += 1 |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
303 |
f = f.parent |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
304 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
305 |
return b |
13
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
306 |
|
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
307 |
def getPageNumber (self, img) : |
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
308 |
""" |
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
309 |
Get the page number that the given image is on |
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
310 |
""" |
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
311 |
|
c229bcb1de41
image breadcrumb links back to page that said image is on
terom
parents:
12
diff
changeset
|
312 |
return self.sorted_images.index(img) // settings.IMAGE_COUNT |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
313 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
314 |
def countParents (self, acc=0) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
315 |
if self.parent : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
316 |
return self.parent.countParents(acc+1) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
317 |
else : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
318 |
return acc |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
319 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
320 |
def inRoot (self, *fnames) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
321 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
322 |
Return a relative URL from this dir to the given path in the root dir |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
323 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
324 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
325 |
c = self.countParents() |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
326 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
327 |
return utils.url_join(*((['..']*c) + list(fnames))) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
328 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
329 |
def render (self) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
330 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
331 |
Render the index.html, Images, and recurse into subdirs |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
332 |
""" |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
333 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
334 |
# ded folders are skipped |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
335 |
if not self.alive : |
28 | 336 |
# dead, skip, no output |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
337 |
return |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
338 |
|
28 | 339 |
index_mtime = utils.mtime(self.pathFor("index.html")) |
340 |
dir_mtime = utils.mtime(self.path) |
|
341 |
||
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
342 |
# if this dir's contents were filtered out, then we can't render the index.html, as we aren't aware of all the images in here |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
343 |
if self.filtered : |
28 | 344 |
log.warning("Dir `%s' contents were filtered, so we won't render the gallery index again", self.path) |
345 |
||
346 |
elif index_mtime > dir_mtime : |
|
347 |
# no changes, pass, ignored |
|
348 |
pass |
|
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
349 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
350 |
else : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
351 |
# create the thumb/preview dirs if needed |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
352 |
for dir in (settings.THUMB_DIR, settings.PREVIEW_DIR) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
353 |
path = self.pathFor(dir) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
354 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
355 |
if not os.path.isdir(path) : |
28 | 356 |
log.info("mkdir %s", dir) |
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
357 |
os.mkdir(path) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
358 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
359 |
# sort the subdirs |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
360 |
subdirs = self.subdirs.values() |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
361 |
subdirs.sort(key=lambda d: d.name) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
362 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
363 |
# paginate! |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
364 |
images = self.sorted_images |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
365 |
image_count = len(images) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
366 |
pages = [] |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
367 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
368 |
while images : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
369 |
pages.append(images[:settings.IMAGE_COUNT]) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
370 |
images = images[settings.IMAGE_COUNT:] |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
371 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
372 |
pagination_required = len(pages) > 1 |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
373 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
374 |
if pagination_required : |
28 | 375 |
log.info("%d pages @ %d images", len(pages), settings.IMAGE_COUNT) |
26
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
376 |
elif not pages : |
28 | 377 |
log.info("no images, render for subdirs") |
26
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
378 |
pages = [[]] |
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
379 |
|
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
380 |
for cur_page, images in enumerate(pages) : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
381 |
if pagination_required and cur_page > 0 : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
382 |
shorturl = "%s/%s" % (self.shorturl_code, cur_page+1) |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
383 |
else : |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
384 |
shorturl = self.shorturl_code |
26
81d6679d50d0
updated shorturls.py to write new shorturls to the db, also adding support for dir-shorturls
terom
parents:
23
diff
changeset
|
385 |
|
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
386 |
# render to index.html |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
387 |
gallery_tpl.render_to(self.pathFor(url_for_page(cur_page)), |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
388 |
stylesheet_url = self.inRoot('style.css'), |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
389 |
title = self.title, |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
390 |
breadcrumb = self.breadcrumb(), |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
391 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
392 |
dirs = subdirs, |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
393 |
images = images, |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
394 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
395 |
num_pages = len(pages), |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
396 |
cur_page = cur_page, |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
397 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
398 |
description = self.descr, |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
399 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
400 |
shorturl = self.inRoot('s', shorturl), |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
401 |
shorturl_code = shorturl, |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
402 |
) |
28 | 403 |
|
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
404 |
# render images |
28 | 405 |
image_count = len(self.sorted_images) |
406 |
for i, img in enumerate(self.images.itervalues()) : |
|
30 | 407 |
log.next("[%-4d/%4d] %s", i + 1, image_count, img.name) |
28 | 408 |
|
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
409 |
img.render() |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
410 |
|
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
411 |
# recurse into subdirs |
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
412 |
for dir in self.subdirs.itervalues() : |
28 | 413 |
log.down(dir.name) |
414 |
||
12
c2d8e9a754a1
Major code restructuring. Version is now 0.5, templates use Mako, and the code is split off into several files under lib/
terom
parents:
diff
changeset
|
415 |
dir.render() |
28 | 416 |
|
417 |
log.up() |
|
418 |