~ubuntu-branches/debian/sid/lazygal/sid

« back to all changes in this revision

Viewing changes to lazygal.py

  • Committer: Package Import Robot
  • Author(s): Michal Čihař
  • Date: 2014-09-22 11:03:44 UTC
  • mfrom: (1.2.18)
  • Revision ID: package-import@ubuntu.com-20140922110344-2wa7dww3jg2rucbt
Tags: 0.8.6-1
* New upstream release.
  - Fixes index out of range error (Closes: #760780).
* Bump standards to 3.9.6.

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
 
 
21
from __future__ import print_function
 
22
 
20
23
import gettext
21
24
import locale
22
25
import logging
26
29
 
27
30
 
28
31
# i18n
 
32
from lazygal import py2compat
29
33
from lazygal import INSTALL_MODE, INSTALL_PREFIX
30
34
if INSTALL_MODE == 'source':
31
35
    LOCALES_PATH = os.path.normpath(os.path.join(os.path.dirname(__file__),
32
36
                                                 'build', 'mo'))
33
37
elif INSTALL_MODE == 'installed':
34
38
    LOCALES_PATH = os.path.join(INSTALL_PREFIX, 'share', 'locale')
35
 
gettext.install('lazygal', LOCALES_PATH, unicode=1)
 
39
gettext.install('lazygal', LOCALES_PATH)
36
40
 
37
41
locale.setlocale(locale.LC_ALL, '')
38
42
 
140
144
                  help=_("Webalbum picture background color. Default is transparent, and implies the PNG format. Any other value, e.g. red, white, blue, uses JPEG."))
141
145
parser.add_option("", "--webalbum-pic-type",
142
146
                  action="store", type="choice",
143
 
                  choices=lazygal.eyecandy.WEBALBUMPIC_TYPES.keys(),
 
147
                  choices=list(lazygal.eyecandy.WEBALBUMPIC_TYPES.keys()),
144
148
                  dest="webalbumpic_type",
145
149
                  help=_("Webalbum picture type. Default is messy."))
146
150
parser.add_option("", "--pic-sort-by",
159
163
(options, args) = parser.parse_args()
160
164
 
161
165
if options.show_version:
162
 
    print _('lazygal version %s') % lazygal.__version__
 
166
    print(_('lazygal version %s') % lazygal.__version__)
163
167
    sys.exit(0)
164
168
 
165
169
if len(args) != 1:
166
170
    parser.print_help()
167
 
    sys.exit(_("Bad command line."))
 
171
    sys.exit(_("Bad command line: wrong number of arguments."))
168
172
 
169
 
source_dir = args[0].decode(sys.getfilesystemencoding())
 
173
source_dir = py2compat.u(args[0], sys.getfilesystemencoding())
170
174
if not os.path.isdir(source_dir):
171
 
    print _("Directory %s does not exist.") % source_dir
 
175
    print(_("Directory %s does not exist.") % source_dir)
172
176
    sys.exit(1)
173
177
 
174
178
 
184
188
 
185
189
if options.dest_dir is not None:
186
190
    cmdline_config.set('global', 'output-directory',
187
 
                       options.dest_dir.decode(sys.getfilesystemencoding()))
 
191
                       py2compat.u(options.dest_dir,
 
192
                                   sys.getfilesystemencoding()))
188
193
if options.force_gen_pages:
189
194
    cmdline_config.set('global', 'force-gen-pages', 'Yes')
190
195
if options.clean_destination:
223
228
    try:
224
229
        os.symlink
225
230
    except AttributeError:
226
 
        print _("Option --orig-symlink is not available on this platform.")
 
231
        print(_("Option --orig-symlink is not available on this platform."))
227
232
        sys.exit(1)
228
233
    else:
229
234
        cmdline_config.set('webgal', 'original-symlink', 'Yes')
240
245
    for single_def in tpl_vars_defs:
241
246
        name, value = single_def.split('=')
242
247
        cmdline_config.set('template-vars',
243
 
                           name, value.decode(sys.stdin.encoding))
 
248
                           name, py2compat.u(value, sys.stdin.encoding))
244
249
 
245
250
logger = logging.getLogger()
246
251
logger.setLevel(logging.INFO)
250
255
 
251
256
try:
252
257
    album = Album(source_dir, cmdline_config)
253
 
except ValueError, e:
254
 
    print unicode(e)
 
258
except ValueError as e:
 
259
    print(py2compat.u(e))
255
260
    sys.exit(1)
256
261
else:
257
262
    if sys.stdout.isatty():
259
264
            len(album.stats()['bydir'].keys()), album.stats()['total'])
260
265
 
261
266
        def update_progress():
262
 
            output_log.update_progress(unicode(progress))
 
267
            output_log.update_progress(py2compat._str(progress))
263
268
        progress.updated = update_progress
264
269
        progress.updated()
265
270
    else:
272
277
    try:
273
278
        album.generate(progress=progress)
274
279
    except KeyboardInterrupt:
275
 
        print >> sys.stderr, _("Interrupted.")
 
280
        print(_("Interrupted."), file=sys.stderr)
276
281
        sys.exit(1)
277
 
    except ValueError, e:
278
 
        print unicode(e)
 
282
    except ValueError as e:
 
283
        print(py2compat.u(e))
279
284
        sys.exit(1)
280
285
 
281
286