-
Notifications
You must be signed in to change notification settings - Fork 0
/
HBmain.py
245 lines (151 loc) · 7.12 KB
/
HBmain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
"""
<O /
WWW
|
"""
from __future__ import print_function
from __future__ import division
import numpy
import matplotlib
import matplotlib.pyplot as plt
import Hummingbird.DataClasses as DC
import Hummingbird.HBalbum as HBAL
import Hummingbird.HBhtml as HBHTML
import Hummingbird.HBfunctions as HBFUN
reload(HBAL)
def init_new_album(album_title, album_path, default_source_path, verbose):
"""
init_new_album: start or restart an album
20130103/RB: started function
INPUT:
- album_title: title of the page (as seen on the web page)
- album_path: path to where the album is located on the computer
- default_source_path: the default path to the folder with the originals
INTERACTION:
- the album will be saved. If it already exists it will ask for confirmation before it overwrites the old album.
"""
HBFUN.verbose("== INIT NEW ALBUM ==", True)
# make new album
album = HBAL.album(album_title = album_title, album_path = album_path, default_source_path = default_source_path, verbose = verbose)
# save it, if it already exists, ask for confirmation
if HBFUN.check_path_exists(pickle_path):
if HBFUN.ask_user_confirmation("This will overwrite the old pickle. Destroy it? y/n"):
HBAL.save_album(album, pickle_path)
else:
HBAL.save_album(album, pickle_path)
def load_events_from_csv(pickle_path, verbose):
"""
load_events_from_csv: should only be used if you had to re-init an album
20130105/RB: started function
INPUT:
- events_csv_filename (str): the filename, without extension, of the csv file. Warning: save_file_in_csv will number filenames!
- pickle_path: path and filename of the pickle
"""
HBFUN.verbose("load_events_from_csv", verbose)
album = HBAL.load_album(pickle_path)
album.load_events_from_csv(verbose)
HBAL.save_album(album, pickle_path)
def add_event(pickle_path, event_index, event_title, event_dir, event_dir_src = "", source_path = "", verbose = False):
"""
add_event: add an event to the album and add the photos to the event
20130103/RB: started function
INPUT:
- pickle_path (str): path and filename of the pickle
- index (int): position of the new album. Use 'list_events' to find the correct position. The newest event should have index = 0
- event_title (str): the title of the event. It usually has the format 'Some event (July 2012)'
- event_dir (str): the directory name of the event on the web
- event_dir_src (str, opt): if the source directory (with the original photos) has a different directory name
- source_path (str, opt): if the source_path of the original photos is not the default.
"""
HBFUN.verbose("Add event", verbose)
album = HBAL.load_album(pickle_path)
album.add_event(event_index, event_title, event_dir, event_dir_src, source_path = source_path, verbose = verbose)
album.add_photos(event_index, flag_new_properties_list = False, flag_redo_resize = False, flag_redo_thumbs = False, verbose = verbose)
HBAL.save_album(album, pickle_path)
def list_events(pickle_path, show_photos = False, verbose = False):
"""
list_events: list events, and maybe also photos
20130103/RB: started function
INPUT:
- pickle_path (str): path and filename of the pickle
- show_photos (BOOL, False): if True, it will also list the photos
"""
HBFUN.verbose("List events", verbose)
album = HBAL.load_album(pickle_path)
album.list_events(show_photos)
def disable_event(pickle_path, event_index, disable, verbose = False):
"""
disable_event: disable an event. This will exclude it from the events gallery, but it will not remove the html code itself
20130103/RB: started function
- event_index (int): index of the event in event_array. Use 'list_events' to find the correct index. If index is -1, it will affect all albums.
- disable (BOOL): True to disable, False to enable. If you try to re-disable an event, it will give a warning and continue
"""
HBFUN.verbose("Disable event", verbose)
album = HBAL.load_album(pickle_path)
album.disable_event(index = event_index, disable = disable, verbose = verbose)
HBAL.save_album(album, pickle_path)
def disable_photo(pickle_path, event_index, photo_index, disable, verbose = False):
"""
disable_photo: see disable_event for info
20130103/RB: started function
"""
HBFUN.verbose("Disable photo", verbose)
album = HBAL.load_album(pickle_path)
album.disable_photo(event_index, photo_index, disable, verbose = True)
HBAL.save_album(album, pickle_path)
def make_html(pickle_path, verbose):
"""
make_html: compile the html
20130103/RB: started function
"""
HBFUN.verbose("Make html", verbose)
album = HBAL.load_album(pickle_path)
album = HBHTML.make_html(album, verbose = verbose)
HBAL.save_album(album, pickle_path) # to save the newly imported properties
def change_event_thumb(pickle_path, event_index, photo_index, verbose):
"""
change_event_thumb: change the thumbnail used for the event
20130103/RB: started function
INPUT:
- event_index (int): a valid index of an event
- photo_index: a valid index of a photo
"""
HBFUN.verbose("Change event thumbnail", verbose)
album = HBAL.load_album(pickle_path)
album.set_folder_thumbnail(event_index, photo_index)
HBAL.save_album(album, pickle_path)
def change_event_title(pickle_path, event_index, new_title, verbose):
HBFUN.verbose("Change event title", verbose)
album = HBAL.load_album(pickle_path)
album.change_event_title(event_index, new_title)
HBAL.save_album(album, pickle_path)
def save_events_in_csv(pickle_path, verbose):
"""
save_events_in_csv: if you want to specifically save a csv file... this is done automatically, so no real need to use this function
20130105/RB: started function
INPUT:
- pickle_path
- events_csv_filename (str): a filename, without extension, where the csv is saved. It will not overwrite older files, instead they will be numbered.
"""
album = HBAL.load_album(pickle_path)
album.save_events_in_csv(verbose)
def redo_resize_photos(pickle_path, event_index, redo_pics = False, redo_thumbs = False, verbose = False):
"""
redo_resize_photos: if needed, you can redo the resizing of the photos.
20130105/RB: started function
INPUT:
- pickle_path
- event_index
- redo_pics
- redo_thumbs
"""
album = HBAL.load_album(pickle_path)
album.add_photos(event_index, flag_new_properties_list = False, flag_redo_resize = redo_pics, flag_redo_thumbs = redo_thumbs, verbose = verbose)
HBAL.save_album(album, pickle_path)
if __name__ == "__main__":
# album_path = "/Users/robbert/Pictures/Web/"
# pickle_path = album_path + "web.pickle"
#
# album = HBAL.load_album(pickle_path)
# HBHTML.generate_rss(album)
pass