~ubuntu-branches/ubuntu/utopic/lazygal/utopic

« back to all changes in this revision

Viewing changes to lazygal.py

  • Committer: Package Import Robot
  • Author(s): Michal Čihař, Michal Čihař, Jakub Wilk
  • Date: 2013-06-06 12:05:08 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20130606120508-e3g94vl8w9pw7za7
Tags: 0.8-1
[ Michal Čihař ]
* New upstream release.
  - Uses new Genshi templates (Closes: #696682).
  - Correctly handles wronly encoded artist in EXIF (Closes: #696648).
  - Uses GExiv2 (LP: #1074028).
* Depend on GExiv2 instead of pyexiv2.
* Bump standards to 3.9.4.
* Use debhelper 9.

[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# with this program; if not, write to the Free Software Foundation, Inc.,
18
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
 
20
 
import sys, os, locale, gettext
 
20
import gettext
 
21
import locale
21
22
import logging
 
23
import os
 
24
import sys
22
25
from optparse import OptionParser
23
26
 
24
27
 
38
41
from lazygal.generators import Album
39
42
import lazygal.config
40
43
import lazygal.eyecandy
 
44
import lazygal.log
41
45
 
42
46
 
43
47
usage = _("usage: %prog [options] albumdir")
144
148
                  dest="pic_sort_by", help=_("Sort order for images in a folder: filename, mtime, or exif. Add ':reverse' to reverse the chosen order."))
145
149
parser.add_option("", "--subgal-sort-by",
146
150
                  action="store", metavar=_('ORDER'),
147
 
                  dest="subgal_sort_by", help=_("Sort order for sub galleries in a folder: dirname or mtime. Add ':reverse' to reverse the chosen order."))
 
151
                  dest="subgal_sort_by", help=_("Sort order for sub galleries in a folder: dirname, exif or mtime. Add ':reverse' to reverse the chosen order."))
 
152
parser.add_option("", "--filter-by-tag", type="string",
 
153
                  action="append", metavar=_('TAG'),
 
154
                  dest="filter_by_tag", help=_("Only include in the gallery pics whose IPTC keywords match the supplied filter(s)."))
148
155
parser.add_option("", "--keep-gps-data",
149
 
                    action="store_true",
150
 
                    dest="keep_gps",
151
 
                    help=_("Do not remove GPS location tags from EXIF metadata. Mostly useful with holiday photos."))
 
156
                  action="store_true",
 
157
                  dest="keep_gps",
 
158
                  help=_("Do not remove GPS location tags from EXIF metadata. Mostly useful with holiday photos."))
152
159
(options, args) = parser.parse_args()
153
160
 
154
161
if options.show_version:
176
183
    cmdline_config.set('runtime', 'check-all-dirs', 'Yes')
177
184
 
178
185
if options.dest_dir is not None:
179
 
    cmdline_config.set('global', 'destdir',
 
186
    cmdline_config.set('global', 'output-directory',
180
187
                       options.dest_dir.decode(sys.getfilesystemencoding()))
181
188
if options.force_gen_pages:
182
189
    cmdline_config.set('global', 'force-gen-pages', 'Yes')
206
213
    cmdline_config.set('webgal', 'sort-medias', options.pic_sort_by)
207
214
if options.subgal_sort_by is not None:
208
215
    cmdline_config.set('webgal', 'sort-subgals', options.subgal_sort_by)
 
216
if options.filter_by_tag is not None:
 
217
    cmdline_config.set('webgal', 'filter-by-tag', options.filter_by_tag)
209
218
if options.original:
210
219
    cmdline_config.set('webgal', 'original', 'Yes')
211
220
if options.orig_base is not None:
233
242
        cmdline_config.set('template-vars',
234
243
                           name, value.decode(sys.stdin.encoding))
235
244
 
236
 
logging.basicConfig(format='%(message)s', level=logging.INFO)
 
245
logger = logging.getLogger()
 
246
logger.setLevel(logging.INFO)
 
247
output_log = lazygal.log.ProgressConsoleHandler()
 
248
output_log.setFormatter(logging.Formatter('%(message)s'))
 
249
logger.addHandler(output_log)
237
250
 
238
251
try:
239
252
    album = Album(source_dir, cmdline_config)
240
253
except ValueError, e:
241
254
    print unicode(e)
242
255
    sys.exit(1)
 
256
else:
 
257
    if sys.stdout.isatty():
 
258
        progress = lazygal.generators.AlbumGenProgress(\
 
259
            len(album.stats()['bydir'].keys()), album.stats()['total'])
 
260
 
 
261
        def update_progress():
 
262
            output_log.update_progress(unicode(progress))
 
263
        progress.updated = update_progress
 
264
        progress.updated()
 
265
    else:
 
266
        progress = None
 
267
 
243
268
 
244
269
if options.metadata:
245
270
    album.generate_default_metadata()
246
271
else:
247
272
    try:
248
 
        album.generate()
 
273
        album.generate(progress=progress)
249
274
    except KeyboardInterrupt:
250
275
        print >> sys.stderr, _("Interrupted.")
251
276
        sys.exit(1)