upgrade to Python 3.7

- just launched 2to3-3.7 -- seems to be working!
- had to fix string decoding in calmagick.py
This commit is contained in:
George Tzoumas 2020-02-19 00:56:16 +01:00
parent 98f16ddd3c
commit f81c788687
22 changed files with 123 additions and 124 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python3.7
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# callirhoe - high quality calendar rendering # callirhoe - high quality calendar rendering
@ -93,7 +93,7 @@ def import_plugin(plugin_paths, cat, longcat, longcat2, listopt, preset):
def print_examples(): def print_examples():
"""print usage examples""" """print usage examples"""
print """Examples: print("""Examples:
Create a calendar of the current year (by default in a 4x3 grid): Create a calendar of the current year (by default in a 4x3 grid):
$ callirhoe my_calendar.pdf $ callirhoe my_calendar.pdf
@ -124,7 +124,7 @@ Create a calendar as a full-hd wallpaper (1920x1080):
and do some magic with ImageMagick! ;) and do some magic with ImageMagick! ;)
$ convert wallpaper.png -negate fancy.png $ convert wallpaper.png -negate fancy.png
""" """)
def add_list_option(parser, opt): def add_list_option(parser, opt):
@ -198,20 +198,20 @@ def main_program():
list_and_exit = False list_and_exit = False
if options.list_languages: if options.list_languages:
for x in plugin_list("lang"): print x[0], for x in plugin_list("lang"): print(x[0], end=' ')
print print()
list_and_exit = True list_and_exit = True
if options.list_styles: if options.list_styles:
for x in plugin_list("style"): print x[0], for x in plugin_list("style"): print(x[0], end=' ')
print print()
list_and_exit = True list_and_exit = True
if options.list_geometries: if options.list_geometries:
for x in plugin_list("geom"): print x[0], for x in plugin_list("geom"): print(x[0], end=' ')
print print()
list_and_exit = True list_and_exit = True
if options.list_layouts: if options.list_layouts:
for x in plugin_list("layouts"): print x[0], for x in plugin_list("layouts"): print(x[0], end=' ')
print print()
list_and_exit = True list_and_exit = True
if list_and_exit: return if list_and_exit: return
@ -248,11 +248,11 @@ def main_program():
# the usual "beware of exec()" crap applies here... but come on, # the usual "beware of exec()" crap applies here... but come on,
# this is a SCRIPTING language, you can always hack the source code!!! # this is a SCRIPTING language, you can always hack the source code!!!
if options.lang_assign: if options.lang_assign:
for x in options.lang_assign: exec "Language.%s" % x for x in options.lang_assign: exec("Language.%s" % x)
if options.style_assign: if options.style_assign:
for x in options.style_assign: exec "Style.%s" % x for x in options.style_assign: exec("Style.%s" % x)
if options.geom_assign: if options.geom_assign:
for x in options.geom_assign: exec "Geometry.%s" % x for x in options.geom_assign: exec("Geometry.%s" % x)
calendar.long_month_name = Language.long_month_name calendar.long_month_name = Language.long_month_name
calendar.long_day_name = Language.long_day_name calendar.long_day_name = Language.long_day_name

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python3.7
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# callirhoe - high quality calendar rendering # callirhoe - high quality calendar rendering
@ -31,7 +31,7 @@ import tempfile
import glob import glob
import random import random
import optparse import optparse
import Queue import queue
import threading import threading
import lib import lib
@ -84,17 +84,17 @@ class PNMImage(object):
state = 0; state = 0;
for i in range(len(strlist)): for i in range(len(strlist)):
# skip comments # skip comments
if strlist[i].startswith('#'): continue if strlist[i].startswith(b'#'): continue
# skip empty lines # skip empty lines
if len(strlist[i]) == 0: continue if len(strlist[i]) == 0: continue
# parse header # parse header
if state == 0: if state == 0:
if not strlist[i].startswith('P2'): if not strlist[i].startswith(b'P2'):
raise RuntimeError('invalid PNM image format: %s' % strlist[i]) raise RuntimeError('invalid PNM image format: %s' % strlist[i])
state += 1 state += 1
# parse size # parse size
elif state == 1: elif state == 1:
w,h = map(int,strlist[i].split()) w,h = list(map(int,strlist[i].split()))
if w != h: if w != h:
raise RuntimeError('non-square PNM image') raise RuntimeError('non-square PNM image')
self.size = (w,h) self.size = (w,h)
@ -105,14 +105,14 @@ class PNMImage(object):
state += 1 state += 1
# bitmap # bitmap
else: else:
data = ' '.join(filter(lambda s: not s.startswith('#'), strlist[i:])) data = ' '.join([s.decode('utf-8') for s in strlist[i:] if not s.startswith(b'#')])
intlist = map(int,data.split()) intlist = list(map(int,data.split()))
self.data = [intlist[x:x+w] for x in range(0, len(intlist), w)] self.data = [intlist[x:x+w] for x in range(0, len(intlist), w)]
break break
self._rsum_cache=(-1,-1,0) # y,x,s self._rsum_cache=(-1,-1,0) # y,x,s
# self.xsum = [map(lambda x: sum(self.data[y][0:x]), range(w+1)) for y in range(0,h)] # self.xsum = [map(lambda x: sum(self.data[y][0:x]), range(w+1)) for y in range(0,h)]
self.xsum = [map(lambda x: self._rsum(y,x), range(w+1)) for y in range(0,h)] self.xsum = [[self._rsum(y,x) for x in range(w+1)] for y in range(0,h)]
def _rsum(self,y,x): def _rsum(self,y,x):
"""running sum with cache """running sum with cache
@ -171,13 +171,13 @@ class PNMImage(object):
w,h = self.size w,h = self.size
sz_lo = _bound(int(w*size_range[0]+0.5),1,w) sz_lo = _bound(int(w*size_range[0]+0.5),1,w)
sz_hi = _bound(int(w*size_range[1]+0.5),1,w) sz_hi = _bound(int(w*size_range[1]+0.5),1,w)
szv_range = range(sz_lo, sz_hi+1) szv_range = list(range(sz_lo, sz_hi+1))
if rr == 1: if rr == 1:
sz_range = zip(szv_range, szv_range) sz_range = list(zip(szv_range, szv_range))
elif rr > 1: elif rr > 1:
sz_range = zip(szv_range, map(lambda x: _bound(int(x/rr+0.5),1,w), szv_range)) sz_range = list(zip(szv_range, [_bound(int(x/rr+0.5),1,w) for x in szv_range]))
else: else:
sz_range = zip(map(lambda x: _bound(int(x*rr+0.5),1,w), szv_range), szv_range) sz_range = list(zip([_bound(int(x*rr+0.5),1,w) for x in szv_range], szv_range))
best = self.lowest_block_avg(*sz_range[0]) best = self.lowest_block_avg(*sz_range[0])
# we do not use at_least because non-global minimum, when relaxed, may jump well above threshold # we do not use at_least because non-global minimum, when relaxed, may jump well above threshold
entropy_thres = max(at_least, best[0]*(1+relax)) entropy_thres = max(at_least, best[0]*(1+relax))
@ -427,17 +427,17 @@ def _entropy_placement(img, size, args, options, r):
R = float(w)/h R = float(w)/h
if r == 0: r = R if r == 0: r = R
if options.verbose: if options.verbose:
print "Calculating image entropy..." print("Calculating image entropy...")
qresize = '%dx%d!' % ((options.quantum,)*2) qresize = '%dx%d!' % ((options.quantum,)*2)
pnm_entropy = PNMImage(subprocess.check_output([_prog_im, img] + args + _IM_entropy_args(options.alt) + pnm_entropy = PNMImage(subprocess.check_output([_prog_im, img] + args + _IM_entropy_args(options.alt) +
[qresize, '-normalize'] + (['-negate'] if options.placement == 'max' else []) + "-compress None pnm:-".split()).splitlines()) [qresize, '-normalize'] + (['-negate'] if options.placement == 'max' else []) + "-compress None pnm:-".split()).splitlines())
# find optimal fit # find optimal fit
if options.verbose: print "Fitting... ", if options.verbose: print("Fitting... ", end=' ')
best = pnm_entropy.fit_rect((options.min_size,options.max_size), options.low_entropy, options.relax, r/R) best = pnm_entropy.fit_rect((options.min_size,options.max_size), options.low_entropy, options.relax, r/R)
if options.verbose: if options.verbose:
print "ent=%0.2f frac=(%0.2f,%0.2f) pos=(%d,%d) bs=(%d,%d) min=%0.2f r=%0.2f" % ( print("ent=%0.2f frac=(%0.2f,%0.2f) pos=(%d,%d) bs=(%d,%d) min=%0.2f r=%0.2f" % (
best[0], best[1][0], best[1][1], best[2][0], best[2][1], best[3][0], best[3][1], best[4], R*best[3][0]/best[3][1]) best[0], best[1][0], best[1][1], best[2][0], best[2][1], best[3][0], best[3][1], best[4], R*best[3][0]/best[3][1]))
# (W,H,X,Y) # (W,H,X,Y)
w,h = size w,h = size
@ -511,17 +511,17 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No
if img in cache: if img in cache:
geometry, dark = cache[img] geometry, dark = cache[img]
if options.verbose and geometry: if options.verbose and geometry:
if stats: print "[%d/%d]" % stats, if stats: print("[%d/%d]" % stats, end=' ')
print "Reusing image info from cache...", geometry, "DARK" if dark else "LIGHT" print("Reusing image info from cache...", geometry, "DARK" if dark else "LIGHT")
if geometry is None: if geometry is None:
if options.verbose: if options.verbose:
if stats: print "[%d/%d]" % stats, if stats: print("[%d/%d]" % stats, end=' ')
print "Extracting image info..." print("Extracting image info...")
w,h = _IM_get_image_size(img, magick_args[0]) w,h = _IM_get_image_size(img, magick_args[0])
qresize = '%dx%d!' % ((options.quantum,)*2) qresize = '%dx%d!' % ((options.quantum,)*2)
if options.verbose: if options.verbose:
print "%s %dx%d %dmp R=%0.2f" % (img, w, h, int(w*h/1000000.0+0.5), float(w)/h) print("%s %dx%d %dmp R=%0.2f" % (img, w, h, int(w*h/1000000.0+0.5), float(w)/h))
if '/' in options.ratio: if '/' in options.ratio:
tmp = options.ratio.split('/') tmp = options.ratio.split('/')
@ -547,14 +547,14 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No
'-compose', 'multiply', img, '-composite', '-region', '%dx%d+%d+%d' % geometry, '-compose', 'multiply', img, '-composite', '-region', '%dx%d+%d+%d' % geometry,
'-negate', outimg]) '-negate', outimg])
elif options.test == 'print': elif options.test == 'print':
print ' '.join(map(str,geometry)) print(' '.join(map(str,geometry)))
elif options.test == 'crop': elif options.test == 'crop':
subprocess.call([_prog_im, img] + magick_args[0] + ['-crop', '%dx%d+%d+%d' % geometry, subprocess.call([_prog_im, img] + magick_args[0] + ['-crop', '%dx%d+%d+%d' % geometry,
outimg]) outimg])
return return
# generate callirhoe calendar # generate callirhoe calendar
if options.verbose: print "Generating calendar image (%s) ... [&]" % options.style if options.verbose: print("Generating calendar image (%s) ... [&]" % options.style)
if not options.vanilla: callirhoe_args = callirhoe_args + ['--no-footer', '--border=0'] if not options.vanilla: callirhoe_args = callirhoe_args + ['--no-footer', '--border=0']
calimg = mktemp('.png') calimg = mktemp('.png')
try: try:
@ -562,14 +562,14 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No
if dark is None: if dark is None:
# measure luminance # measure luminance
if options.verbose: print "Measuring luminance...", if options.verbose: print("Measuring luminance...", end=' ')
if options.negative > 0 and options.negative < 255: if options.negative > 0 and options.negative < 255:
luma = _IM_get_image_luminance(img, magick_args[0], geometry) luma = _IM_get_image_luminance(img, magick_args[0], geometry)
if options.verbose: print "(%s)" % luma, if options.verbose: print("(%s)" % luma, end=' ')
else: else:
luma = 255 - options.negative luma = 255 - options.negative
dark = luma < options.negative dark = luma < options.negative
if options.verbose: print "DARK" if dark else "LIGHT" if options.verbose: print("DARK" if dark else "LIGHT")
if cache is not None: if cache is not None:
with _mutex: with _mutex:
cache[img] = (geometry, dark) cache[img] = (geometry, dark)
@ -578,7 +578,7 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No
if pcal.returncode != 0: raise RuntimeError("calmagick: calendar creation failed") if pcal.returncode != 0: raise RuntimeError("calmagick: calendar creation failed")
# perform final composition # perform final composition
if options.verbose: print "Composing overlay (%s)..." % outimg if options.verbose: print("Composing overlay (%s)..." % outimg)
overlay = ['(', '-negate', calimg, ')'] if dark else [calimg] overlay = ['(', '-negate', calimg, ')'] if dark else [calimg]
subprocess.call([_prog_im, img] + magick_args[0] + ['-region', '%dx%d+%d+%d' % geometry] + subprocess.call([_prog_im, img] + magick_args[0] + ['-region', '%dx%d+%d+%d' % geometry] +
([] if options.brightness == 0 else ['-brightness-contrast', '%d' % (-options.brightness if dark else options.brightness)]) + ([] if options.brightness == 0 else ['-brightness-contrast', '%d' % (-options.brightness if dark else options.brightness)]) +
@ -602,7 +602,7 @@ def parse_range(s,hint=None):
if hint and span == 0: span = hint if hint and span == 0: span = hint
year = lib.parse_year(t[1]) year = lib.parse_year(t[1])
margs = [] margs = []
for m in xrange(span): for m in range(span):
margs += [(month,year)] margs += [(month,year)]
month += 1 month += 1
if month > 12: month = 1; year += 1 if month > 12: month = 1; year += 1
@ -626,7 +626,7 @@ def range_worker(q,ev,i):
try: try:
compose_calendar(*item) compose_calendar(*item)
except Exception as e: except Exception as e:
print >> sys.stderr, "Exception in Thread-%d: %s" % (i,e.args) print("Exception in Thread-%d: %s" % (i,e.args), file=sys.stderr)
ev.set() ev.set()
finally: finally:
q.task_done() q.task_done()
@ -655,14 +655,14 @@ def main_program():
if options.range: if options.range:
flist = sorted(glob.glob(args[0])) flist = sorted(glob.glob(args[0]))
mrange = parse_range(options.range,hint=len(flist)) mrange = parse_range(options.range,hint=len(flist))
if options.verbose: print "Composing %d photos..." % len(mrange) if options.verbose: print("Composing %d photos..." % len(mrange))
if options.sample is not None: if options.sample is not None:
flist = random.sample(flist, options.sample if options.sample else min(len(mrange),len(flist))) flist = random.sample(flist, options.sample if options.sample else min(len(mrange),len(flist)))
nf = len(flist) nf = len(flist)
if nf > 0: if nf > 0:
if len(mrange) > nf and options.prefix == 'no?': options.prefix = 'yes' if len(mrange) > nf and options.prefix == 'no?': options.prefix = 'yes'
if options.jobs > 1: if options.jobs > 1:
q = Queue.Queue() q = queue.Queue()
ev = threading.Event() ev = threading.Event()
for i in range(options.jobs): for i in range(options.jobs):
t = threading.Thread(target=range_worker,args=(q,ev,i)) t = threading.Thread(target=range_worker,args=(q,ev,i))

View File

@ -18,7 +18,7 @@
"""module defining the sloppy geometry""" """module defining the sloppy geometry"""
import default from . import default
class dom(default.dom): pass class dom(default.dom): pass

View File

@ -19,18 +19,18 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/ # along with this program. If not, see http://www.gnu.org/licenses/
long_day_name = [ u'Montag', u'Dienstag', u'Mittwoch', long_day_name = [ 'Montag', 'Dienstag', 'Mittwoch',
u'Donnerstag', u'Freitag', u'Samstag', u'Sonntag' ] 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag' ]
short_day_name = [ u'Mo', u'Di', u'Mi', u'Do', u'Fr', u'Sa', u'So' ] short_day_name = [ 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So' ]
long_month_name = [ '', long_month_name = [ '',
u'Januar', u'Februar', u'März', u'April', 'Januar', 'Februar', 'März', 'April',
u'Mai', u'Juni', u'Juli', u'August', 'Mai', 'Juni', 'Juli', 'August',
u'September', u'Oktober', u'November', u'Dezember' ] 'September', 'Oktober', 'November', 'Dezember' ]
short_month_name = [ '', short_month_name = [ '',
u'Jan', u'Feb', u'Mrz', u'Apr', u'Mai', u'Jun', 'Jan', 'Feb', 'Mrz', 'Apr', 'Mai', 'Jun',
u'Jul', u'Aug', u'Sep', u'Okt', u'Nov', u'Dez' ] 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez' ]
week_of_year_prefix = u'W' week_of_year_prefix = 'W'

View File

@ -18,16 +18,16 @@
"""Greek language definition file""" """Greek language definition file"""
long_day_name = [ u'Δευτέρα', u'Τρίτη', u'Τετάρτη', long_day_name = [ 'Δευτέρα', 'Τρίτη', 'Τετάρτη',
u'Πέμπτη', u'Παρασκευή', u'Σάββατο', u'Κυριακή' ] 'Πέμπτη', 'Παρασκευή', 'Σάββατο', 'Κυριακή' ]
short_day_name = [ u'Δε', u'Τρ', u'Τε', u'Πε', u'Πα', u'Σα', u'Κυ' ] short_day_name = [ 'Δε', 'Τρ', 'Τε', 'Πε', 'Πα', 'Σα', 'Κυ' ]
long_month_name = [ '', u'Ιανουάριος', u'Φεβρουάριος', u'Μάρτιος', u'Απρίλιος', long_month_name = [ '', 'Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 'Απρίλιος',
u'Μάιος', u'Ιούνιος', u'Ιούλιος', u'Αύγουστος', 'Μάιος', 'Ιούνιος', 'Ιούλιος', 'Αύγουστος',
u'Σεπτέμβριος', u'Οκτώβριος', u'Νοέμβριος', u'Δεκέμβριος' ] 'Σεπτέμβριος', 'Οκτώβριος', 'Νοέμβριος', 'Δεκέμβριος' ]
short_month_name = [ '', u'Ιαν', u'Φεβ', u'Μαρ', u'Απρ', u'Μαϊ', u'Ιον', u'Ιολ', short_month_name = [ '', 'Ιαν', 'Φεβ', 'Μαρ', 'Απρ', 'Μαϊ', 'Ιον', 'Ιολ',
u'Αυγ', u'Σεπ', u'Οκτ', u'Νοε', u'Δεκ' ] 'Αυγ', 'Σεπ', 'Οκτ', 'Νοε', 'Δεκ' ]
week_of_year_prefix = u'Ε' week_of_year_prefix = 'Ε'

View File

@ -18,18 +18,18 @@
"""English language definition file""" """English language definition file"""
long_day_name = [ u'Monday', u'Tuesday', u'Wednesday', long_day_name = [ 'Monday', 'Tuesday', 'Wednesday',
u'Thursday', u'Friday', u'Saturday', u'Sunday' ] 'Thursday', 'Friday', 'Saturday', 'Sunday' ]
short_day_name = [ u'Mo', u'Tu', u'We', u'Th', u'Fr', u'Sa', u'Su' ] short_day_name = [ 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su' ]
long_month_name = [ '', long_month_name = [ '',
u'January', u'February', u'March', u'April', 'January', 'February', 'March', 'April',
u'May', u'June', u'July', u'August', 'May', 'June', 'July', 'August',
u'September', u'October', u'November', u'December' ] 'September', 'October', 'November', 'December' ]
short_month_name = [ '', short_month_name = [ '',
u'Jan', u'Feb', u'Mar', u'Apr', u'May', u'Jun', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
u'Jul', u'Aug', u'Sep', u'Oct', u'Nov', u'Dec' ] 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
week_of_year_prefix = u'W' week_of_year_prefix = 'W'

View File

@ -18,17 +18,17 @@
"""French language definition file""" """French language definition file"""
long_day_name = [ u'Lundi', u'Mardi', u'Mercredi', long_day_name = [ 'Lundi', 'Mardi', 'Mercredi',
u'Jeudi', u'Vendredi', u'Samedi', u'Dimanche' ] 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche' ]
short_day_name = [ u'Lu', u'Ma', u'Me', u'Je', u'Ve', u'Sa', u'Di' ] short_day_name = [ 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa', 'Di' ]
long_month_name = [ '', long_month_name = [ '',
u'Janvier', u'Février', u'Mars', u'Avril', 'Janvier', 'Février', 'Mars', 'Avril',
u'Mai', u'Juin', u'Juillet', u'Août', 'Mai', 'Juin', 'Juillet', 'Août',
u'Septembre', u'Octobre', u'Novembre', u'Décembre' ] 'Septembre', 'Octobre', 'Novembre', 'Décembre' ]
short_month_name = [ '', u'Jan', u'Fév', u'Mar', u'Avr', u'Mai', u'Jun', u'Jul', short_month_name = [ '', 'Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Jun', 'Jul',
u'Aoû', u'Sep', u'Oct', u'Nov', u'Déc' ] 'Aoû', 'Sep', 'Oct', 'Nov', 'Déc' ]
week_of_year_prefix = u'S' week_of_year_prefix = 'S'

View File

@ -19,15 +19,15 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/ # along with this program. If not, see http://www.gnu.org/licenses/
long_day_name = [ u'Pazartesi', u'Salı', u' Çarşamba ', long_day_name = [ 'Pazartesi', 'Salı', ' Çarşamba ',
u'Perşembe', u'Cuma', u'Cumartesi', u'Pazar' ] 'Perşembe', 'Cuma', 'Cumartesi', 'Pazar' ]
short_day_name = [ u'Pt', u'Sa', u'Ça', u'Pe', u'Cu', u'Ct', u'Pa' ] short_day_name = [ 'Pt', 'Sa', 'Ça', 'Pe', 'Cu', 'Ct', 'Pa' ]
long_month_name = [ '', u'Ocak', u'Şubat', u'Mart', u'Nisan', long_month_name = [ '', 'Ocak', 'Şubat', 'Mart', 'Nisan',
u'Mayıs', u'Haziran', u'Temmuz', u'Ağustos', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos',
u'Eylül', u'Ekim', u'Kasım', u'Aralık' ] 'Eylül', 'Ekim', 'Kasım', 'Aralık' ]
short_month_name = long_month_name short_month_name = long_month_name
week_of_year_prefix = u'H' week_of_year_prefix = 'H'

View File

@ -241,7 +241,7 @@ class CalendarRenderer(object):
try: try:
page = PageWriter(self.Outfile, G.pagespec, not self.options.opaque, G.landscape, G.border) page = PageWriter(self.Outfile, G.pagespec, not self.options.opaque, G.landscape, G.border)
except InvalidFormat as e: except InvalidFormat as e:
print >> sys.stderr, "invalid output format", e.args[0] print("invalid output format", e.args[0], file=sys.stderr)
sys.exit(1) sys.exit(1)
if rows == 0 and cols == 0: if rows == 0 and cols == 0:
@ -277,9 +277,9 @@ class CalendarRenderer(object):
cur_year = self.Year cur_year = self.Year
num_placed = 0 num_placed = 0
page_layout = [] page_layout = []
for k in xrange(num_pages): for k in range(num_pages):
page_layout.append([]) page_layout.append([])
for i in xrange(mpp): for i in range(mpp):
page_layout[k].append((cur_month,cur_year)) page_layout[k].append((cur_month,cur_year))
num_placed += 1 num_placed += 1
cur_month += 1 cur_month += 1

View File

@ -24,7 +24,7 @@ import optparse
import sys import sys
from datetime import date, timedelta from datetime import date, timedelta
import _base from . import _base
parser = _base.get_parser(__name__) parser = _base.get_parser(__name__)
parser.set_defaults(rows=2) parser.set_defaults(rows=2)
@ -36,7 +36,7 @@ class CalendarRenderer(_base.CalendarRenderer):
make_sloppy_rect(cr, rect, G.month.sloppy_dx, G.month.sloppy_dy, G.month.sloppy_rot) make_sloppy_rect(cr, rect, G.month.sloppy_dx, G.month.sloppy_dy, G.month.sloppy_rot)
day, span = calendar.monthrange(year, month) day, span = calendar.monthrange(year, month)
mmeasure = 'A'*max(map(len,L.month_name)) mmeasure = 'A'*max(list(map(len,L.month_name)))
if self.options.month_with_year: if self.options.month_with_year:
mmeasure += 'A'*(len(str(year))+1) mmeasure += 'A'*(len(str(year))+1)

View File

@ -23,7 +23,7 @@ import calendar
import sys import sys
from datetime import date, timedelta from datetime import date, timedelta
import _base from . import _base
parser = _base.get_parser(__name__) parser = _base.get_parser(__name__)
parser.add_option("--phantom-days", action="store_true", default=False, parser.add_option("--phantom-days", action="store_true", default=False,
@ -53,8 +53,8 @@ class CalendarRenderer(_base.CalendarRenderer):
day, span = calendar.monthrange(year, month) day, span = calendar.monthrange(year, month)
weekrows = 6 if G.month.symmetric else _weekrows_of_month(year, month) weekrows = 6 if G.month.symmetric else _weekrows_of_month(year, month)
dom = -day + 1; dom = -day + 1;
wmeasure = 'A'*max(map(len,L.day_name)) wmeasure = 'A'*max(list(map(len,L.day_name)))
mmeasure = 'A'*max(map(len,L.month_name)) mmeasure = 'A'*max(list(map(len,L.month_name)))
if self.options.month_with_year: if self.options.month_with_year:
mmeasure += 'A'*(len(str(year))+1) mmeasure += 'A'*(len(str(year))+1)

View File

@ -27,7 +27,7 @@ import optparse
import sys import sys
from datetime import date, timedelta from datetime import date, timedelta
import _base from . import _base
# TODO: merge with base parser... # TODO: merge with base parser...
def get_parser(layout_name): def get_parser(layout_name):
@ -139,8 +139,8 @@ class CalendarRenderer(_base.CalendarRenderer):
make_sloppy_rect(cr, rect, G.month.sloppy_dx, G.month.sloppy_dy, G.month.sloppy_rot) make_sloppy_rect(cr, rect, G.month.sloppy_dx, G.month.sloppy_dy, G.month.sloppy_rot)
day, span = calendar.monthrange(year, month) day, span = calendar.monthrange(year, month)
wmeasure = 'A'*max(map(len,L.day_name)) wmeasure = 'A'*max(list(map(len,L.day_name)))
mmeasure = 'A'*max(map(len,L.month_name)) mmeasure = 'A'*max(list(map(len,L.month_name)))
rows = 31 if G.month.symmetric else span rows = 31 if G.month.symmetric else span
grid = VLayout(rect_from_origin(rect), 32) # title bar always symmetric grid = VLayout(rect_from_origin(rect), 32) # title bar always symmetric

View File

@ -124,7 +124,7 @@ def color_mix(a, b, frac):
@param frac: amount of first color @param frac: amount of first color
@rtype: tuple @rtype: tuple
""" """
return map(lambda (x,y): x*frac + y*(1 - frac), zip(a,b)) return [x_y[0]*frac + x_y[1]*(1 - frac) for x_y in zip(a,b)]
def color_scale(a, frac): def color_scale(a, frac):
"""scale color values """scale color values
@ -133,7 +133,7 @@ def color_scale(a, frac):
@param frac: scale amount (to be multiplied) @param frac: scale amount (to be multiplied)
@rtype: tuple @rtype: tuple
""" """
return map(lambda x: min(1.0,x*frac), a) return [min(1.0,x*frac) for x in a]
def color_auto_fg(bg, light = (1,1,1), dark = (0,0,0)): def color_auto_fg(bg, light = (1,1,1), dark = (0,0,0)):
"""return I{light} or I{dark} foreground color based on an ad-hoc evaluation of I{bg} """return I{light} or I{dark} foreground color based on an ad-hoc evaluation of I{bg}
@ -196,7 +196,7 @@ class VLayout(object):
@rtype: (float,float,float,float),... @rtype: (float,float,float,float),...
""" """
return map(self.item, range(self.count())) return list(map(self.item, list(range(self.count()))))
class HLayout(VLayout): class HLayout(VLayout):
"""horizontal layout manager defined as a transpose of L{VLayout}""" """horizontal layout manager defined as a transpose of L{VLayout}"""
@ -282,21 +282,21 @@ class GLayout(object):
@rtype: (float,float,float,float),... @rtype: (float,float,float,float),...
""" """
return map(self.item_seq, range(self.count())) return list(map(self.item_seq, list(range(self.count()))))
def row_items(self, row): def row_items(self, row):
"""get sequence of cell rects of a row """get sequence of cell rects of a row
@rtype: (float,float,float,float),... @rtype: (float,float,float,float),...
""" """
return map(lambda x: self.item(row, x), range(self.col_count())) return [self.item(row, x) for x in range(self.col_count())]
def col_items(self, col): def col_items(self, col):
"""get sequence of cell rects of a column """get sequence of cell rects of a column
@rtype: (float,float,float,float),... @rtype: (float,float,float,float),...
""" """
return map(lambda x: self.item(x, col), range(self.row_count())) return [self.item(x, col) for x in range(self.row_count())]
def item_span(self, nr, nc, row = -1, col = -1): def item_span(self, nr, nc, row = -1, col = -1):

View File

@ -59,7 +59,7 @@ def _strip_empty(sl):
@rtype: [str,...] @rtype: [str,...]
""" """
return filter(lambda z: z, sl) if sl else [] return [z for z in sl if z] if sl else []
def _flatten(sl): def _flatten(sl):
"""join list I{sl} into a comma-separated string """join list I{sl} into a comma-separated string
@ -281,8 +281,7 @@ class HolidayProvider(object):
footer_tuple = (footer, None, footer, None) footer_tuple = (footer, None, footer, None)
else: else:
footer_tuple = (None, None, None, None) footer_tuple = (None, None, None, None)
return tuple(map(lambda k: Holiday([header_tuple[k]], [footer_tuple[k]], flags), return tuple([Holiday([header_tuple[k]], [footer_tuple[k]], flags) for k in range(4)])
range(4)))
def load_holiday_file(self, filename): def load_holiday_file(self, filename):
"""load a holiday file into the C{HolidayProvider} object """load a holiday file into the C{HolidayProvider} object
@ -386,7 +385,7 @@ class HolidayProvider(object):
if not dt in self.cache: self.cache[dt] = Holiday() if not dt in self.cache: self.cache[dt] = Holiday()
self.cache[dt].merge_with(self.monthly[m0]) self.cache[dt].merge_with(self.monthly[m0])
# fixed # fixed
for dt in filter(lambda z: z.year == y, self.fixed): for dt in [z for z in self.fixed if z.year == y]:
if not dt in self.cache: self.cache[dt] = Holiday() if not dt in self.cache: self.cache[dt] = Holiday()
self.cache[dt].merge_with(self.fixed[dt]) self.cache[dt].merge_with(self.fixed[dt])
# orthodox easter # orthodox easter
@ -454,5 +453,5 @@ if __name__ == '__main__':
while cur <= d2: while cur <= d2:
y,m,d = cur.year, cur.month, cur.day y,m,d = cur.year, cur.month, cur.day
hol = hp.get_holiday(y,m,d) hol = hp.get_holiday(y,m,d)
if hol: print cur.strftime("%a %b %d %Y"),hol if hol: print(cur.strftime("%a %b %d %Y"),hol)
cur += timedelta(1) cur += timedelta(1)

View File

@ -26,14 +26,14 @@ import cairo
import math import math
import random import random
from os.path import splitext from os.path import splitext
from geom import * from .geom import *
XDPI = 72.0 XDPI = 72.0
"""dots per inch of output device""" """dots per inch of output device"""
# decreasing order # decreasing order
# [1188, 840, 594, 420, 297, 210, 148, 105, 74, 52, 37] # [1188, 840, 594, 420, 297, 210, 148, 105, 74, 52, 37]
ISOPAGE = map(lambda x: int(210*math.sqrt(2)**x+0.5), range(5,-6,-1)) ISOPAGE = [int(210*math.sqrt(2)**x+0.5) for x in range(5,-6,-1)]
"""ISO page height list, index k for height of Ak paper""" """ISO page height list, index k for height of Ak paper"""
def page_spec(spec = None): def page_spec(spec = None):

View File

@ -6,6 +6,6 @@ res = dict()
for x in ['lang', 'style', 'layouts', 'geom']: for x in ['lang', 'style', 'layouts', 'geom']:
res[x] = glob.glob('%s/*.py' % x) res[x] = glob.glob('%s/*.py' % x)
print 'resource_list = {}' print('resource_list = {}')
for x in res.keys(): for x in list(res.keys()):
print 'resource_list["%s"] = %s' % (x, str(res[x])) print('resource_list["%s"] = %s' % (x, str(res[x])))

View File

@ -18,7 +18,7 @@
"""module defining Greek Font Society fonts for black & white style""" """module defining Greek Font Society fonts for black & white style"""
import bw as base from . import bw as base
# day of week # day of week
class dow(base.dow): class dow(base.dow):

View File

@ -18,7 +18,7 @@
"""module defining Greek Font Society fonts for black & white sparse style""" """module defining Greek Font Society fonts for black & white sparse style"""
import bw_sparse as base from . import bw_sparse as base
# day of week # day of week
class dow(base.dow): class dow(base.dow):

View File

@ -18,7 +18,7 @@
"""module defining Greek Font Society fonts for default style""" """module defining Greek Font Society fonts for default style"""
import default from . import default
# day of week # day of week
class dow(default.dow): class dow(default.dow):

View File

@ -18,7 +18,7 @@
"""module defining rainbow color style""" """module defining rainbow color style"""
import default from . import default
# day of week # day of week
class dow(default.dow): pass class dow(default.dow): pass
@ -52,6 +52,6 @@ class month(default.month):
color_mix(spring,summer,0.66), color_mix(spring,summer,0.33), summer, # july color_mix(spring,summer,0.66), color_mix(spring,summer,0.33), summer, # july
color_mix(summer,autumn,0.66), color_mix(summer,autumn,0.33), autumn, # october color_mix(summer,autumn,0.66), color_mix(summer,autumn,0.33), autumn, # october
color_mix(autumn,winter,0.66), color_mix(autumn,winter,0.33)) # december color_mix(autumn,winter,0.66), color_mix(autumn,winter,0.33)) # december
color_map_bg = (map(lambda x: color_scale(x, 0.5), _c1), _c1) color_map_bg = ([color_scale(x, 0.5) for x in _c1], _c1)
color_map_fg = (((1,1,1),)*13, ((0,0,0),)*13) color_map_fg = (((1,1,1),)*13, ((0,0,0),)*13)
# map(lambda x: color_auto_fg(x), color_map_bg[1] # map(lambda x: color_auto_fg(x), color_map_bg[1]

View File

@ -18,7 +18,7 @@
"""module defining rainbow color & gfs style""" """module defining rainbow color & gfs style"""
import gfs from . import gfs
# day of week # day of week
class dow(gfs.dow): pass class dow(gfs.dow): pass
@ -52,6 +52,6 @@ class month(gfs.month):
color_mix(spring,summer,0.66), color_mix(spring,summer,0.33), summer, # july color_mix(spring,summer,0.66), color_mix(spring,summer,0.33), summer, # july
color_mix(summer,autumn,0.66), color_mix(summer,autumn,0.33), autumn, # october color_mix(summer,autumn,0.66), color_mix(summer,autumn,0.33), autumn, # october
color_mix(autumn,winter,0.66), color_mix(autumn,winter,0.33)) # december color_mix(autumn,winter,0.66), color_mix(autumn,winter,0.33)) # december
color_map_bg = (map(lambda x: color_scale(x, 0.5), _c1), _c1) color_map_bg = ([color_scale(x, 0.5) for x in _c1], _c1)
color_map_fg = (((1,1,1),)*13, ((0,0,0),)*13) color_map_fg = (((1,1,1),)*13, ((0,0,0),)*13)
# map(lambda x: color_auto_fg(x), color_map_bg[1] # map(lambda x: color_auto_fg(x), color_map_bg[1]

View File

@ -18,7 +18,7 @@
"""module defining Greek Font Society fonts for transparent style""" """module defining Greek Font Society fonts for transparent style"""
import transparent as base from . import transparent as base
# day of week # day of week
class dow(base.dow): class dow(base.dow):