From 1cceec25f6b018ba268ed4ee298f9812babd7cda Mon Sep 17 00:00:00 2001 From: "geortz@gmail.com" Date: Thu, 30 Oct 2014 21:47:35 +0000 Subject: [PATCH 02/71] test commit git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@163 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- callirhoe.py | 1 + 1 file changed, 1 insertion(+) diff --git a/callirhoe.py b/callirhoe.py index 09d051a..67cace3 100755 --- a/callirhoe.py +++ b/callirhoe.py @@ -21,6 +21,7 @@ # TODO: +# test # fix auto-measure rendering (cairo) # fix plugin loading (without global vars) # week markers selectable From 8e8026e1a964cea42e957393f14aa11bf4056956 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 30 Oct 2014 21:53:31 +0000 Subject: [PATCH 03/71] git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@164 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- callirhoe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/callirhoe.py b/callirhoe.py index 67cace3..735b8c1 100755 --- a/callirhoe.py +++ b/callirhoe.py @@ -21,7 +21,7 @@ # TODO: -# test + # fix auto-measure rendering (cairo) # fix plugin loading (without global vars) # week markers selectable From ec02bd6bc0e67016d58e076cbbbdfd23fa453a39 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 30 Oct 2014 21:55:10 +0000 Subject: [PATCH 04/71] Changed some stuff to make it zip-package friendly git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@165 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- callirhoe.py | 20 +++++++++----------- lib/plugin.py | 33 +++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/callirhoe.py b/callirhoe.py index 735b8c1..3c6ea0d 100755 --- a/callirhoe.py +++ b/callirhoe.py @@ -21,7 +21,6 @@ # TODO: - # fix auto-measure rendering (cairo) # fix plugin loading (without global vars) # week markers selectable @@ -63,7 +62,7 @@ class Abort(Exception): from lib.plugin import * # TODO: SEE IF IT CAN BE MOVED INTO lib.plugin ... -def import_plugin(plugin_paths, cat, longcat, longcat2, listopt, preset): +def import_plugin(plugin_path, cat, longcat, longcat2, listopt, preset): """import a plugin making it visible I{Example:} @@ -81,12 +80,9 @@ def import_plugin(plugin_paths, cat, longcat, longcat2, listopt, preset): @note: Aimed for internal use with I{lang}, I{style}, I{geom}, I{layouts}. """ try: - found = available_files(plugin_paths[0], cat, preset) + available_files(plugin_paths[1], cat, preset) + found = available_files(plugin_path, cat, preset) if len(found) == 0: raise IOError - old = sys.path[0]; - sys.path[0] = found[0][1] m = __import__("%s.%s" % (cat,preset), globals(), locals(), [ "*" ]) - sys.path[0] = old return m except IOError: sys.exit("callirhoe: %s definition '%s' not found, use %s to see available definitions" % (longcat, @@ -312,11 +308,11 @@ def main_program(): list_and_exit = True if list_and_exit: return - plugin_paths = get_plugin_paths() - Language = import_plugin(plugin_paths, "lang", "language", "languages", "--list-languages", options.lang) - Style = import_plugin(plugin_paths, "style", "style", "styles", "--list-styles", options.style) - Geometry = import_plugin(plugin_paths, "geom", "geometry", "geometries", "--list-geometries", options.geom) - Layout = import_plugin(plugin_paths, "layouts", "layout", "layouts", "--list-layouts", options.layout) + plugin_path = "/" + Language = import_plugin(plugin_path, "lang", "language", "languages", "--list-languages", options.lang) + Style = import_plugin(plugin_path, "style", "style", "styles", "--list-styles", options.style) + Geometry = import_plugin(plugin_path, "geom", "geometry", "geometries", "--list-geometries", options.geom) + Layout = import_plugin(plugin_path, "layouts", "layout", "layouts", "--list-layouts", options.layout) for x in argv2: if '=' in x: x = x[0:x.find('=')] @@ -401,6 +397,8 @@ def main_program(): if __name__ == "__main__": try: +# import pkg_resources +# print pkg_resources.resource_listdir(__name__,"/") main_program() except Abort as e: sys.exit(e.args[0]) diff --git a/lib/plugin.py b/lib/plugin.py index 911cc98..db58a13 100644 --- a/lib/plugin.py +++ b/lib/plugin.py @@ -24,7 +24,21 @@ import sys import os.path -import glob +import pkg_resources + +def glob(path, pattern): + tmplist = pkg_resources.resource_listdir("__main__", "/"+path) + filelist = [] + for i in tmplist: + if i == "": + continue + if pkg_resources.resource_isdir("__main__", "/"+path+"/"+i): + filelist.extend(glob(path+"/"+i, pattern)) + else: + if i.lower()[-3:] == pattern.lower(): + name = path+"/"+i + filelist.append(name) + return filelist def available_files(parent, dir, fmatch = None): """find parent/dir/*.py files to be used for plugins @@ -37,17 +51,16 @@ def available_files(parent, dir, fmatch = None): """ good = False res = [] - pattern = parent + "/" + dir + "/*.py" - for x in glob.glob(pattern): + for x in glob(dir,".py"): basex = os.path.basename(x) if basex == "__init__.py": good = True elif basex.startswith('_'): # ignore files aimed for internal use # safer than [a-z]-style matching... continue - else: + else: base = os.path.splitext(basex)[0] - if base and ((not fmatch) or (fmatch == base)): res.append((base,parent)) + if base and ((not fmatch) or (fmatch == base)): res.append((base,"/"+dir+parent)) return res if good else [] def plugin_list(cat): @@ -55,18 +68,10 @@ def plugin_list(cat): @rtype: [str,...] """ - plugin_paths = get_plugin_paths() - return available_files(plugin_paths[0], cat) + available_files(plugin_paths[1], cat) + return available_files("../", cat) # cat = lang (category) # longcat = language # longcat2 = languages # listopt = --list-lang # preset = "EN" - -def get_plugin_paths(): - """return the plugin search paths - - @rtype: [str,str] - """ - return [ os.path.expanduser("~/.callirhoe"), sys.path[0] if sys.path[0] else "." ] From ca627b55659217eb7dc000e8eb340c8a818c30c2 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 30 Oct 2014 21:57:41 +0000 Subject: [PATCH 05/71] added makefile and make_pkg Makefile is, well, self explanatory, and completely experimental for the time being make_pkg creates the zip packages, and makes them executable :D git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@166 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- Makefile | 3 +++ make_pkg | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Makefile create mode 100755 make_pkg diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..edb25c0 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +install: + install -m 0755 callirhoe $(prefix)/bin + install -m 0755 calmagick $(prefix)/bin diff --git a/make_pkg b/make_pkg new file mode 100755 index 0000000..97174e9 --- /dev/null +++ b/make_pkg @@ -0,0 +1,41 @@ +#!/bin/bash + +mkdir _callirhoe +cp -R geom _callirhoe +cp -R holidays _callirhoe +cp -R lang _callirhoe +cp -R layouts _callirhoe +cp -R lib _callirhoe +cp -R style _callirhoe +cp callirhoe.py _callirhoe/__main__.py + +cd _callirhoe +zip -q -r callirhoe.zip * +mv callirhoe.zip ../ +cd .. +rm -rf _callirhoe +echo \#!/usr/bin/env python2 | cat - callirhoe.zip > callirhoe +chmod 755 callirhoe +rm callirhoe.zip + +mkdir _calmagick + +cp -R geom _calmagick +cp -R holidays _calmagick +cp -R lang _calmagick +cp -R layouts _calmagick +cp -R lib _calmagick +cp -R style _calmagick +cp callirhoe.py _calmagick +cp calmagick.py _calmagick/__main__.py + +cd _calmagick +zip -q -r calmagick.zip * +mv calmagick.zip ../ +cd .. +rm -rf _calmagick +echo \#!/usr/bin/env python2 | cat - calmagick.zip > calmagick +chmod 755 calmagick +rm calmagick.zip + + From fd7ced7d6643dbdfd57e27b36cf3dde19f35ae75 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 30 Oct 2014 22:03:24 +0000 Subject: [PATCH 06/71] forgot to upload new holiday.py git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@167 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- lib/holiday.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/holiday.py b/lib/holiday.py index f3d4fdd..ff58cf9 100644 --- a/lib/holiday.py +++ b/lib/holiday.py @@ -23,6 +23,7 @@ # ***************************************** from datetime import date, timedelta +import pkg_resources def _get_orthodox_easter(year): """compute date of orthodox easter @@ -318,7 +319,7 @@ class HolidayProvider(object): @param filename: file to be loaded """ - with open(filename, 'r') as f: + with open(pkg_resources.resource_stream(filename), 'r') as f: for line in f: line = line.strip() if not line: continue From bd2f1308159bc5ab38ecbf6be8cb94afe0d625a4 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 30 Oct 2014 22:15:02 +0000 Subject: [PATCH 07/71] bad idea, reverted holiday.py to previous version. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@168 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- lib/holiday.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/holiday.py b/lib/holiday.py index ff58cf9..f3d4fdd 100644 --- a/lib/holiday.py +++ b/lib/holiday.py @@ -23,7 +23,6 @@ # ***************************************** from datetime import date, timedelta -import pkg_resources def _get_orthodox_easter(year): """compute date of orthodox easter @@ -319,7 +318,7 @@ class HolidayProvider(object): @param filename: file to be loaded """ - with open(pkg_resources.resource_stream(filename), 'r') as f: + with open(filename, 'r') as f: for line in f: line = line.strip() if not line: continue From 88e86d5d4b8a16c44f4ce901991b864f7406a17a Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 30 Oct 2014 22:20:14 +0000 Subject: [PATCH 08/71] no caps plox git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@169 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/make_pkg b/make_pkg index 97174e9..10ba32a 100755 --- a/make_pkg +++ b/make_pkg @@ -1,12 +1,12 @@ #!/bin/bash mkdir _callirhoe -cp -R geom _callirhoe -cp -R holidays _callirhoe -cp -R lang _callirhoe -cp -R layouts _callirhoe -cp -R lib _callirhoe -cp -R style _callirhoe +cp -r geom _callirhoe +cp -r holidays _callirhoe +cp -r lang _callirhoe +cp -r layouts _callirhoe +cp -r lib _callirhoe +cp -r style _callirhoe cp callirhoe.py _callirhoe/__main__.py cd _callirhoe @@ -20,12 +20,12 @@ rm callirhoe.zip mkdir _calmagick -cp -R geom _calmagick -cp -R holidays _calmagick -cp -R lang _calmagick -cp -R layouts _calmagick -cp -R lib _calmagick -cp -R style _calmagick +cp -r geom _calmagick +cp -r holidays _calmagick +cp -r lang _calmagick +cp -r layouts _calmagick +cp -r lib _calmagick +cp -r style _calmagick cp callirhoe.py _calmagick cp calmagick.py _calmagick/__main__.py From 1c2c2b790a8f29f1e98ce4e0a551cb2c13513c5c Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 30 Oct 2014 22:23:13 +0000 Subject: [PATCH 09/71] nah, I caps look better... git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@170 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/make_pkg b/make_pkg index 10ba32a..97174e9 100755 --- a/make_pkg +++ b/make_pkg @@ -1,12 +1,12 @@ #!/bin/bash mkdir _callirhoe -cp -r geom _callirhoe -cp -r holidays _callirhoe -cp -r lang _callirhoe -cp -r layouts _callirhoe -cp -r lib _callirhoe -cp -r style _callirhoe +cp -R geom _callirhoe +cp -R holidays _callirhoe +cp -R lang _callirhoe +cp -R layouts _callirhoe +cp -R lib _callirhoe +cp -R style _callirhoe cp callirhoe.py _callirhoe/__main__.py cd _callirhoe @@ -20,12 +20,12 @@ rm callirhoe.zip mkdir _calmagick -cp -r geom _calmagick -cp -r holidays _calmagick -cp -r lang _calmagick -cp -r layouts _calmagick -cp -r lib _calmagick -cp -r style _calmagick +cp -R geom _calmagick +cp -R holidays _calmagick +cp -R lang _calmagick +cp -R layouts _calmagick +cp -R lib _calmagick +cp -R style _calmagick cp callirhoe.py _calmagick cp calmagick.py _calmagick/__main__.py From e63e7e352cc14722aeb28f999acf8501a4155d3c Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 08:13:11 +0000 Subject: [PATCH 10/71] Added a docstring git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@171 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- lib/plugin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/plugin.py b/lib/plugin.py index db58a13..2012559 100644 --- a/lib/plugin.py +++ b/lib/plugin.py @@ -27,6 +27,9 @@ import os.path import pkg_resources def glob(path, pattern): +""" + Internal function that scans the given path and subpaths for .py files +""" tmplist = pkg_resources.resource_listdir("__main__", "/"+path) filelist = [] for i in tmplist: From 9836d79fd1b01fd3aac0e0a7243d2fac77741811 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 12:22:31 +0000 Subject: [PATCH 11/71] New design... git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@172 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- callirhoe.py | 57 ++++++++++-------------- calmagick.py | 64 ++++++--------------------- layouts/_base.py | 1 - layouts/classic.py | 5 +-- layouts/sparse.py | 1 - lib/geom.py | 105 ++++++++------------------------------------- lib/holiday.py | 54 ++++++----------------- lib/plugin.py | 48 ++++++++++----------- lib/xcairo.py | 19 +++----- make_pkg | 4 +- 10 files changed, 98 insertions(+), 260 deletions(-) diff --git a/callirhoe.py b/callirhoe.py index 3c6ea0d..ecfc727 100755 --- a/callirhoe.py +++ b/callirhoe.py @@ -62,7 +62,7 @@ class Abort(Exception): from lib.plugin import * # TODO: SEE IF IT CAN BE MOVED INTO lib.plugin ... -def import_plugin(plugin_path, cat, longcat, longcat2, listopt, preset): +def import_plugin(plugin_paths, cat, longcat, longcat2, listopt, preset): """import a plugin making it visible I{Example:} @@ -75,14 +75,18 @@ def import_plugin(plugin_path, cat, longcat, longcat2, listopt, preset): @param longcat2: long category name in plural form @param listopt: option name @param preset: default value - @rtype: module @note: Aimed for internal use with I{lang}, I{style}, I{geom}, I{layouts}. """ try: - found = available_files(plugin_path, cat, preset) + found = [] + for path in plugin_paths: + found += available_files(plugin_paths[0], cat, preset) if len(found) == 0: raise IOError + old = sys.path[0]; + sys.path[0] = found[0][1] m = __import__("%s.%s" % (cat,preset), globals(), locals(), [ "*" ]) + sys.path[0] = old return m except IOError: sys.exit("callirhoe: %s definition '%s' not found, use %s to see available definitions" % (longcat, @@ -133,13 +137,12 @@ def add_list_option(parser, opt): parser.add_option("--list-%s" % opt, action="store_true", dest="list_%s" % opt, default=False, help="list available %s" % opt) -def atoi(s, lower_bound=None, upper_bound=None, prefix=''): - """convert string to integer, exiting on error (for cmdline parsing) +def itoa(s, lower_bound=None, upper_bound=None, prefix=''): + """convert integer to string, exiting on error (for cmdline parsing) @param lower_bound: perform additional check so that value >= I{lower_bound} @param upper_bound: perform additional check so that value <= I{upper_bound} @param prefix: output prefix for error reporting - @rtype: int """ try: k = int(s); @@ -154,40 +157,31 @@ def atoi(s, lower_bound=None, upper_bound=None, prefix=''): return k def _parse_month(mstr): - """get a month value (0-12) from I{mstr}, exiting on error (for cmdline parsing) - - @rtype: int - """ - m = atoi(mstr,lower_bound=0,upper_bound=12,prefix='month: ') + """get a month value (0-12) from I{mstr}, exiting on error (for cmdline parsing)""" + m = itoa(mstr,lower_bound=0,upper_bound=12,prefix='month: ') if m == 0: m = time.localtime()[1] return m def parse_month_range(s): - """return (Month,Span) by parsing range I{Month}, I{Month1}-I{Month2} or I{Month}:I{Span} - - @rtype: (int,int) - """ + """return (Month,Span) by parsing range I{Month}, I{Month1}-I{Month2} or I{Month}:I{Span}""" if ':' in s: t = s.split(':') if len(t) != 2: raise Abort("invalid month range '" + s + "'") Month = _parse_month(t[0]) - MonthSpan = atoi(t[1],lower_bound=0,prefix='month span: ') + MonthSpan = itoa(t[1],lower_bound=0,prefix='month span: ') elif '-' in s: t = s.split('-') if len(t) != 2: raise Abort("invalid month range '" + s + "'") Month = _parse_month(t[0]) - MonthSpan = atoi(t[1],lower_bound=Month+1,prefix='month range: ') - Month + 1 + MonthSpan = itoa(t[1],lower_bound=Month+1,prefix='month range: ') - Month + 1 else: Month = _parse_month(s) MonthSpan = 1 return (Month,MonthSpan) def parse_year(ystr): - """get a year value (>=0) from I{ystr}, exiting on error (for cmdline parsing) - - @rtype: int - """ - y = atoi(ystr,lower_bound=0,prefix='year: ') + """get a year value (>=0) from I{ystr}, exiting on error (for cmdline parsing)""" + y = itoa(ystr,lower_bound=0,prefix='year: ') if y == 0: y = time.localtime()[0] return y @@ -201,8 +195,6 @@ def extract_parser_args(arglist, parser, pos = -1): if I{pos}<0 then all positional arguments are extracted, otherwise, only I{pos} arguments are extracted. arglist[0] (usually sys.argv[0]) is also positional argument! - - @rtype: ([str,...],[str,...]) @return: tuple (argv1,argv2) with extracted argument list and remaining argument list """ argv = [[],[]] @@ -231,10 +223,7 @@ def extract_parser_args(arglist, parser, pos = -1): return tuple(argv) def get_parser(): - """get the argument parser object - - @rtype: optparse.OptionParser - """ + """get the argument parser object""" parser = optparse.OptionParser(usage="usage: %prog [options] [[MONTH[-MONTH2|:SPAN]] YEAR] FILE", description="High quality calendar rendering with vector graphics. " "By default, a calendar of the current year in pdf format is written to FILE. " @@ -308,11 +297,11 @@ def main_program(): list_and_exit = True if list_and_exit: return - plugin_path = "/" - Language = import_plugin(plugin_path, "lang", "language", "languages", "--list-languages", options.lang) - Style = import_plugin(plugin_path, "style", "style", "styles", "--list-styles", options.style) - Geometry = import_plugin(plugin_path, "geom", "geometry", "geometries", "--list-geometries", options.geom) - Layout = import_plugin(plugin_path, "layouts", "layout", "layouts", "--list-layouts", options.layout) + plugin_paths = get_plugin_paths() + Language = import_plugin(plugin_paths, "lang", "language", "languages", "--list-languages", options.lang) + Style = import_plugin(plugin_paths, "style", "style", "styles", "--list-styles", options.style) + Geometry = import_plugin(plugin_paths, "geom", "geometry", "geometries", "--list-geometries", options.geom) + Layout = import_plugin(plugin_paths, "layouts", "layout", "layouts", "--list-layouts", options.layout) for x in argv2: if '=' in x: x = x[0:x.find('=')] @@ -397,8 +386,6 @@ def main_program(): if __name__ == "__main__": try: -# import pkg_resources -# print pkg_resources.resource_listdir(__name__,"/") main_program() except Abort as e: sys.exit(e.args[0]) diff --git a/calmagick.py b/calmagick.py index 38d1485..81fc373 100755 --- a/calmagick.py +++ b/calmagick.py @@ -34,14 +34,14 @@ import optparse import Queue import threading -from callirhoe import extract_parser_args, parse_month_range, parse_year, atoi, Abort, _version, _copyright +from callirhoe import extract_parser_args, parse_month_range, parse_year, itoa, Abort, _version, _copyright from lib.geom import rect_rel_scale # MAYBE-TODO # move to python 3? # check ImageMagick availability/version # convert input to ImageMagick native format for faster re-access -# report error on parse-float (like atoi()) +# report error on parse-float (like itoa()) # abort --range only on KeyboardInterrupt? _prog_im = os.getenv('CALLIRHOE_IM', 'convert') @@ -54,16 +54,12 @@ def run_callirhoe(style, size, args, outfile): @param size: tuple (I{width},I{height}) for output calendar size (in pixels) @param args: (extra) argument list to pass to callirhoe @param outfile: output calendar file - @rtype: subprocess.Popen - @return: Popen object + @return: subprocess exit code """ return subprocess.Popen(['callirhoe', '-s', style, '--paper=-%d:-%d' % size] + args + [outfile]) def _bound(x, lower, upper): - """return the closest number to M{x} that lies in [M{lower,upper}] - - @rtype: type(x) - """ + """return the closest number to M{x} that lies in [M{lower,upper}]""" if x < lower: return lower if x > upper: return upper return x @@ -115,10 +111,7 @@ class PNMImage(object): self.xsum = [map(lambda x: self._rsum(y,x), range(w+1)) for y in range(0,h)] def _rsum(self,y,x): - """running sum with cache - - @rtype: int - """ + """running sum with cache""" if self._rsum_cache[0] == y and self._rsum_cache[1] == x: s = self._rsum_cache[2] + self.data[y][x-1] else: @@ -127,15 +120,11 @@ class PNMImage(object): return s def block_avg(self, x, y, szx, szy): - """returns the average intensity of a block of size M{(szx,szy)} at pos (top-left) M{(x,y)} - - @rtype: float - """ + """returns the average intensity of a block of size M{(szx,szy)} at pos (top-left) M{(x,y)}""" return float(sum([(self.xsum[y][x+szx] - self.xsum[y][x]) for y in range(y,y+szy)]))/(szx*szy) def lowest_block_avg(self, szx, szy, at_least = 0): """returns the M{(szx,szy)}-sized block with intensity as close to M{at_least} as possible - @rtype: (float,(float,float),(int,int),(int,int)) @return: R=tuple M({avg, (szx_ratio,szy_ratio), (x,y), (szx,szy))}: R[0] is the average intensity of the block found, R[1] is the block size ratio with respect to the whole image, R[2] is the block position (top-left) and R[3] is the block size @@ -165,8 +154,6 @@ class PNMImage(object): Calendar rectangle ratio over Photo ratio. If M{r>1} then calendar rectangle, when scaled, fits M{x} dimension first. Conversely, if M{r<1}, scaling touches the M{y} dimension first. When M{r=1}, calendar rectangle can fit perfectly within the photo at 100% size. - - @rtype: (float,(float,float),(int,int),(int,int),float) """ w,h = self.size sz_lo = _bound(int(w*size_range[0]+0.5),1,w) @@ -185,14 +172,11 @@ class PNMImage(object): # we do not use at_least because we want the best possible option, for bigger sizes cur = self.lowest_block_avg(*sz) if cur[0] <= entropy_thres: return cur + (best[0],) - return best + (best[0],) # avg, (szx_ratio,szy_ratio), (x,y), (szx,szy), best_avg + return best + (best[0],) # avg, sz_ratio, x, y, sz, best_avg def get_parser(): - """get the argument parser object - - @rtype: optparse.OptionParser - """ + """get the argument parser object""" parser = optparse.OptionParser(usage="usage: %prog IMAGE [options] [callirhoe-options] [--pre-magick ...] [--in-magick ...] [--post-magick ...]", description="""High quality photo calendar composition with automatic minimal-entropy placement. If IMAGE is a single file, then a calendar of the current month is overlayed. If IMAGE contains wildcards, @@ -319,7 +303,6 @@ def parse_magick_args(): ImageMagick-specific arguments should be defined between arguments C{--pre-magick}, C{--in-magick}, C{--post-magick} is this order - @rtype: [[str,...],[str,...],[str,...]] @return: 3-element list of lists containing the [pre,in,post]-options """ magickargs = [[],[],[]] @@ -349,19 +332,13 @@ def parse_magick_args(): return magickargs def mktemp(ext=''): - """get temporary file name with optional extension - - @rtype: str - """ + """get temporary file name with optional extension""" f = tempfile.NamedTemporaryFile(suffix=ext, delete=False) f.close() return f.name def get_outfile(infile, outdir, base_prefix, format, hint=None): - """get output file name taking into account output directory, format and prefix, avoiding overwriting the input file - - @rtype: str - """ + """get output file name taking into account output directory, format and prefix, avoiding overwriting the input file""" if hint: outfile = hint else: @@ -375,10 +352,7 @@ def get_outfile(infile, outdir, base_prefix, format, hint=None): return outfile def _IM_get_image_size(img, args): - """extract tuple(width,height) from image file using ImageMagick - - @rtype: (int,int) - """ + """extract tuple(width,height) from image file using ImageMagick""" info = subprocess.check_output([_prog_im, img] + args + ['-format', '%w %h', 'info:']).split() return tuple(map(int, info)) @@ -386,10 +360,7 @@ _IM_lum_args = "-colorspace Lab -channel R -separate +channel -set colorspace Gr """IM colorspace conversion arguments to extract image luminance""" def _IM_get_image_luminance(img, args, geometry = None): - """get average image luminance as a float in [0,255], using ImageMagick - - @rtype: float - """ + """get average image luminance as a float in [0,255], using ImageMagick""" return 255.0*float(subprocess.check_output([_prog_im, img] + args + (['-crop', '%dx%d+%d+%d' % geometry] if geometry else []) + _IM_lum_args + ['-format', '%[fx:mean]', 'info:'])) @@ -404,10 +375,7 @@ _IM_entropy_tail = "-colorspace Lab -channel R -separate +channel -set colorspac #_IM_entropy_tail = "-colorspace Lab -channel R -separate +channel -normalize -scale".split() def _IM_entropy_args(alt=False): - """IM entropy computation arguments, depending on default or alternate algorithm - - @rtype: [str,...] - """ + """IM entropy computation arguments, depending on default or alternate algorithm""" return _IM_entropy_head + _IM_entropy_alg[alt] + _IM_entropy_tail def _entropy_placement(img, size, args, options, r): @@ -418,7 +386,6 @@ def _entropy_placement(img, size, args, options, r): @param args: ImageMagick pre-processing argument list (see C{--pre-magick}) @param options: (command-line) options object @param r: rectangle ratio, 0=match input ratio - @rtype: (int,int,int,int) @return: IM geometry tuple(I{width,height,x,y}) """ w,h = size @@ -450,7 +417,6 @@ def _manual_placement(size, options, r): @param size: image size tuple(I{width,height}) @param options: (command-line) options object @param r: rectangle ratio, 0=match input ratio - @rtype: (int,int,int,int) @return: IM geometry tuple(I{width,height,x,y}) """ w,h = size @@ -483,7 +449,6 @@ _mutex = threading.Lock() def get_cache(num_photos, num_months): """returns a reference to the cache object, or None if caching is disabled - @rtype: dict @note: caching is enabled only when more than 1/6 of photos is going to be re-used """ q,r = divmod(num_months, num_photos) @@ -523,7 +488,7 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No if '/' in options.ratio: tmp = options.ratio.split('/') - calratio = float(atoi(tmp[0],1))/atoi(tmp[1],1) + calratio = float(itoa(tmp[0],1))/itoa(tmp[1],1) else: calratio = float(options.ratio) if options.placement == 'min' or options.placement == 'max': @@ -591,7 +556,6 @@ def parse_range(s,hint=None): @param s: range string in format I{Month1-Month2/Year} or I{Month:Span/Year} @param hint: span value to be used, when M{Span=0} - @rtype: [(int,int),...] @return: list of (I{Month,Year}) tuples for every month specified """ if '/' in s: diff --git a/layouts/_base.py b/layouts/_base.py index 7fe79ae..c0fe3c7 100644 --- a/layouts/_base.py +++ b/layouts/_base.py @@ -26,7 +26,6 @@ def get_parser(layout_name): """get the parser object for the layout command-line arguments @param layout_name: corresponding python module (.py file) - @rtype: optparse.OptionParser """ lname = layout_name.split(".")[1] parser = optparse.OptionParser(usage="%prog (...) --layout " + lname + " [options] (...)",add_help_option=False) diff --git a/layouts/classic.py b/layouts/classic.py index b64ec67..cc5e71a 100644 --- a/layouts/classic.py +++ b/layouts/classic.py @@ -28,10 +28,7 @@ import _base parser = _base.get_parser(__name__) def _weekrows_of_month(year, month): - """returns the number of Monday-Sunday ranges (or subsets of) that a month contains, which are 4, 5 or 6 - - @rtype: int - """ + """returns the number of Monday-Sunday ranges (or subsets of) that a month contains, which are 4, 5 or 6""" day,span = calendar.monthrange(year, month) if day == 0 and span == 28: return 4 if day == 5 and span == 31: return 6 diff --git a/layouts/sparse.py b/layouts/sparse.py index e9bedb6..0b9c75d 100644 --- a/layouts/sparse.py +++ b/layouts/sparse.py @@ -33,7 +33,6 @@ def get_parser(layout_name): """get the parser object for the layout command-line arguments @param layout_name: corresponding python module (.py file) - @rtype: optparse.OptionParser """ lname = layout_name.split(".")[1] parser = optparse.OptionParser(usage="%prog (...) --layout " + lname + " [options] (...)",add_help_option=False) diff --git a/lib/geom.py b/lib/geom.py index d7d5139..3f7918c 100644 --- a/lib/geom.py +++ b/lib/geom.py @@ -23,10 +23,7 @@ # ***************************************** def rect_ratio(r): - """returns the ratio of rect I{r} which is defined as M{width/height} - - @rtype: float - """ + """returns the ratio of rect I{r} which is defined as M{width/height}""" return r[2]*1.0/r[3] def rect_rel_scale(r, fw, fh, align_x = 0, align_y = 0): @@ -43,49 +40,33 @@ def rect_rel_scale(r, fw, fh, align_x = 0, align_y = 0): linear interpolation. @type align_y: float in [-1,1] @param align_y: Performs vertical (top-bottom) alignment similarly to L{align_x}. - @rtype: (float,float,float,float) """ x, y, w, h = r return (x + (align_x + 1.0)*w*(1 - fw)/2.0, y + (align_y + 1.0)*h*(1 - fh)/2.0, w*fw, h*fh) def rect_pad(r, pad): - """returns a padded rect by reducing border by the I{pad} tuple (top,left,bottom,right) - - @rtype: (float,float,float,float) - """ + """returns a padded rect by reducing border by the I{pad} tuple (top,left,bottom,right)""" x, y, w, h = r t_, l_, b_, r_ = pad return (x + l_, y + t_, w - r_ - l_, h - t_ - b_) def rect_to_abs(r): - """get absolute coordinates (x0,y0,x1,y1) from rect definition (x,y,w,h) - - @rtype: (float,float,float,float) - """ + """get absolute coordinates (x0,y0,x1,y1) from rect definition (x,y,w,h)""" x, y, w, h = r return (x, y, x + w, y + h) def abs_to_rect(a): - """get rect definition (x,y,w,h) from absolute coordinates (x0,y0,x1,y1) - - @rtype: (float,float,float,float) - """ + """get rect definition (x,y,w,h) from absolute coordinates (x0,y0,x1,y1)""" x1, y1, x2, y2 = a return (x1, y1, x2 - x1, y2 - y1) def rect_from_origin(r): - """returns a similar rect with top-left corner at (0,0) - - @rtype: (float,float,float,float) - """ + """returns a similar rect with top-left corner at (0,0)""" return (0, 0, r[2], r[3]) def rect_hull(r1,r2): - """returns the smallest rect containing r1 and r2 - - @rtype: (float,float,float,float) - """ + """returns the smallest rect containing r1 and r2""" x1, y1, x2, y2 = rect_to_abs(r1) x3, y3, x4, y4 = rect_to_abs(r2) return abs_to_rect((min(x1,x3), min(y1,y3), max(x2,x4), max(y2,y4))) @@ -96,7 +77,6 @@ def rect_hsplit(r, f = 0.5, fdist = 0.0): @type f: float in [0,1] @param f: split fraction @param fdist: fraction of space to discard before splitting (free space) - @rtype: ((float,float,float,float),(float,float,float,float)) @return: tuple (r1,r2) with splits and free space evenly distributed before r1, between r1 and r2 and after r2 """ @@ -107,10 +87,7 @@ def rect_hsplit(r, f = 0.5, fdist = 0.0): return (r1, r2) def rect_vsplit(r, f = 0.5, fdist = 0.0): - """split a rect vertically, similarly to L{rect_hsplit} - - @rtype: ((float,float,float,float),(float,float,float,float)) - """ + """split a rect vertically, similarly to L{rect_hsplit}""" x, y, w, h = r rh = h*(1.0 - fdist) r1 = (x, y + h*fdist/3.0, w, rh*f) @@ -122,7 +99,6 @@ def color_mix(a, b, frac): @type frac: float in [0,1] @param frac: amount of first color - @rtype: tuple """ return map(lambda (x,y): x*frac + y*(1 - frac), zip(a,b)) @@ -131,15 +107,11 @@ def color_scale(a, frac): @type frac: float @param frac: scale amount (to be multiplied) - @rtype: tuple """ return map(lambda x: min(1.0,x*frac), a) 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} - - @rtype: tuple - """ + """return I{light} or I{dark} foreground color based on an ad-hoc evaluation of I{bg}""" return light if (bg[0] + 1.5*bg[1] + bg[2]) < 1.0 else dark # ********* layout managers *********** @@ -157,10 +129,7 @@ class VLayout(object): self.pad = pad def count(self): - """return maximum number of items in the layout - - @rtype: int - """ + """return maximum number of items in the layout""" return self.nitems def resize(self, k): @@ -172,10 +141,7 @@ class VLayout(object): self.nitems += delta def item(self, i = 0): - """get rect for item I{i} - - @rtype: (float,float,float,float) - """ + """get rect for item I{i}""" x, y, w, h = self.rect h *= 1.0/self.nitems y += i*h @@ -186,16 +152,12 @@ class VLayout(object): @param n: first item @param k: number of items, -1 for all remaining items - @rtype: (float,float,float,float) """ if k < 0: k = (self.count() - n) // 2 return rect_hull(self.item(k), self.item(k + n - 1)) def items(self): - """returns a sequence of all items - - @rtype: (float,float,float,float),... - """ + """returns a sequence of all items""" return map(self.item, range(self.count())) class HLayout(VLayout): @@ -205,10 +167,6 @@ class HLayout(VLayout): nitems, (pad[1], pad[0], pad[3], pad[2])) def item(self, i = 0): - """get rect for item I{i} - - @rtype: (float,float,float,float) - """ t = super(HLayout,self).item(i) return (t[1], t[0], t[3], t[2]) @@ -231,24 +189,15 @@ class GLayout(object): self.hrep = HLayout((rect[0], rect[1], t[2], t[3]), ncols, (0.0, pad[1], 0.0, pad[3])) def row_count(self): - """get (max) number of rows in the grid - - @rtype: int - """ + """get (max) number of rows in the grid""" return self.vrep.count() def col_count(self): - """get (max) number of columns in the grid - - @rtype: int - """ + """get (max) number of columns in the grid""" return self.hrep.count() def count(self): - """get total number of cells in the grid (which is M{rows*cols}) - - @rtype: int - """ + """get total number of cells in the grid (which is M{rows*cols})""" return self.row_count()*self.col_count() def resize(self, rows, cols): @@ -258,19 +207,13 @@ class GLayout(object): self.hrep = HLayout(t[0:2], t[2:4], cols, (0.0, pad[1], 0.0, pad[3])) def item(self, row, col): - """get rect of cell at position I{row,col} - - @rtype: (float,float,float,float) - """ + """get rect of cell at position I{row,col}""" ty = self.vrep.item(row) tx = self.hrep.item(col) return (tx[0], ty[1], tx[2], tx[3]) def item_seq(self, k, column_wise = False): - """get rect of cell at position I{k} column-wise or row-wise - - @rtype: (float,float,float,float) - """ + """get rect of cell at position I{k} column-wise or row-wise""" if not column_wise: row, col = k // self.col_count(), k % self.col_count() else: @@ -278,24 +221,15 @@ class GLayout(object): return self.item(row, col) def items(self, column_wise = False): - """get sequence of rects of cells column-wise or row-wise - - @rtype: (float,float,float,float),... - """ + """get sequence of rects of cells column-wise or row-wise""" return map(self.item_seq, range(self.count())) def row_items(self, row): - """get sequence of cell rects of a row - - @rtype: (float,float,float,float),... - """ + """get sequence of cell rects of a row""" return map(lambda x: self.item(row, x), range(self.col_count())) def col_items(self, col): - """get sequence of cell rects of a column - - @rtype: (float,float,float,float),... - """ + """get sequence of cell rects of a column""" return map(lambda x: self.item(x, col), range(self.row_count())) @@ -306,7 +240,6 @@ class GLayout(object): @param nc: number of spanning columns @param row: starting row, -1 for vertically centered @param col: starting column, -1 for horizontally centered - @rtype: (float,float,float,float) """ if row < 0: row = (self.row_count() - nr) // 2 if col < 0: col = (self.col_count() - nc) // 2 diff --git a/lib/holiday.py b/lib/holiday.py index f3d4fdd..22024a6 100644 --- a/lib/holiday.py +++ b/lib/holiday.py @@ -25,9 +25,7 @@ from datetime import date, timedelta def _get_orthodox_easter(year): - """compute date of orthodox easter - @rtype: datetime.date - """ + """compute date of orthodox easter""" y1, y2, y3 = year % 4 , year % 7, year % 19 a = 19*y3 + 15 y4 = a % 30 @@ -39,10 +37,7 @@ def _get_orthodox_easter(year): # return res def _get_catholic_easter(year): - """compute date of catholic easter - - @rtype: datetime.date - """ + """compute date of catholic easter""" a, b, c = year % 19, year // 100, year % 100 d, e = divmod(b,4) f = (b + 8) // 25 @@ -55,17 +50,11 @@ def _get_catholic_easter(year): return date(year, emonth, edate+1) def _strip_empty(sl): - """strip empty strings from list I{sl} - - @rtype: [str,...] - """ + """strip empty strings from list I{sl}""" return filter(lambda z: z, sl) if sl else [] def _flatten(sl): - """join list I{sl} into a comma-separated string - - @rtype: str - """ + """join list I{sl} into a comma-separated string""" if not sl: return None return ', '.join(sl) @@ -105,31 +94,19 @@ class Holiday(object): self.flags |= hol.flags def header(self): - """return a comma-separated string for L{header_list} - - @rtype: str - """ + """return a comma-separated string for L{header_list}""" return _flatten(self.header_list) def footer(self): - """return a comma-separated string for L{footer_list} - - @rtype: str - """ + """return a comma-separated string for L{footer_list}""" return _flatten(self.footer_list) def __str__(self): - """string representation for debugging purposes - - @rtype: str - """ + """string representation for debugging purposes""" return str(self.footer()) + ':' + str(self.header()) + ':' + str(self.flags) def _parse_flags(self, fstr): - """return a bit combination of flags, from a comma-separated string list - - @rtype: int - """ + """return a bit combination of flags, from a comma-separated string list""" if not fstr: return 0 fs = fstr.split(',') val = 0 @@ -153,8 +130,6 @@ def _decode_date_str(ddef): If C{ddef} is of the form "YYYYMMDD" then tuple (YYYY,MM,DD) is returned, which stands for year YYYY - month MM - day DD. - - @rtype: (int,int,int) """ if len(ddef) == 2: return (0,0,int(ddef)) @@ -214,12 +189,11 @@ class HolidayProvider(object): def _parse_day_record(self, fields): """return tuple (etype,ddef,footer,header,flags) - @rtype: (char,type(ddef),str,str,int) @note: I{ddef} is one of the following: - - None - - int - - ((y,m,d),) - - ((y,m,d),(y,m,d)) + None + int + ((y,m,d),) + ((y,m,d),(y,m,d)) """ if len(fields) != 5: raise ValueError("Too many fields: " + str(fields)) @@ -265,7 +239,6 @@ class HolidayProvider(object): @param header: passed as C{[header]} of the generated L{Holiday} object @param footer: passed as C{[footer]} of the generated L{Holiday} object @param flags: C{flags} of the generated L{Holiday} object - @rtype: (Holiday,Holiday,Holiday,Holiday) """ if header: if self.multiday_markers: @@ -368,7 +341,6 @@ class HolidayProvider(object): def get_holiday(self, y, m, d): """return a L{Holiday} object for the specified date (y,m,d) or C{None} if no holiday is defined - @rtype: Holiday @note: If year I{y} has not been requested before, the cache is updated first with all holidays that belong in I{y}, indexed by C{date()} objects. """ @@ -416,7 +388,6 @@ class HolidayProvider(object): def get_style(self, flags, dow): """return appropriate style object, depending on I{flags} and I{dow} - @rtype: Style @param flags: bit combination of holiday flags @param dow: day of week """ @@ -429,7 +400,6 @@ class HolidayProvider(object): def __call__(self, year, month, dom, dow): """returns (header,footer,day_style) - @rtype: (str,str,Style) @param month: month (0-12) @param dom: day of month (1-31) @param dow: day of week (0-6) diff --git a/lib/plugin.py b/lib/plugin.py index 2012559..3c9d99f 100644 --- a/lib/plugin.py +++ b/lib/plugin.py @@ -24,29 +24,16 @@ import sys import os.path -import pkg_resources +import glob -def glob(path, pattern): -""" - Internal function that scans the given path and subpaths for .py files -""" - tmplist = pkg_resources.resource_listdir("__main__", "/"+path) - filelist = [] - for i in tmplist: - if i == "": - continue - if pkg_resources.resource_isdir("__main__", "/"+path+"/"+i): - filelist.extend(glob(path+"/"+i, pattern)) - else: - if i.lower()[-3:] == pattern.lower(): - name = path+"/"+i - filelist.append(name) - return filelist +try: + import resources +except: + pass def available_files(parent, dir, fmatch = None): """find parent/dir/*.py files to be used for plugins - @rtype: [str,...] @note: 1. __init__.py should exist 2. files starting with underscore are ignored @@ -54,27 +41,36 @@ def available_files(parent, dir, fmatch = None): """ good = False res = [] - for x in glob(dir,".py"): + pattern = parent + "/" + dir + "/*.py" + for x in glob.glob(pattern) if parent != "resource" else resources.resource_list[dir]: basex = os.path.basename(x) if basex == "__init__.py": good = True elif basex.startswith('_'): # ignore files aimed for internal use # safer than [a-z]-style matching... continue - else: + else: base = os.path.splitext(basex)[0] - if base and ((not fmatch) or (fmatch == base)): res.append((base,"/"+dir+parent)) + if base and ((not fmatch) or (fmatch == base)): res.append((base,parent)) return res if good else [] def plugin_list(cat): - """return a sequence of available plugins, using L{available_files()} and L{get_plugin_paths()} - - @rtype: [str,...] - """ - return available_files("../", cat) + """return a sequence of available plugins, using L{available_files()} and L{get_plugin_paths()}""" + plugin_paths = get_plugin_paths() + return available_files(plugin_paths[0], cat) + available_files(plugin_paths[1], cat) # cat = lang (category) # longcat = language # longcat2 = languages # listopt = --list-lang # preset = "EN" + +def get_plugin_paths(): + """return the plugin search paths""" + result = [ os.path.expanduser("~/.callirhoe"), sys.path[0] if sys.path[0] else "."] + try: + tmp = resources.resource_list + result.append["resource"] + except: + pass + return result diff --git a/lib/xcairo.py b/lib/xcairo.py index dcc2667..4e1c899 100644 --- a/lib/xcairo.py +++ b/lib/xcairo.py @@ -43,8 +43,6 @@ def page_spec(spec = None): Paper type can be an ISO paper type (a0..a9 or a0w..a9w) or of the form W:H; positive values correspond to W or H mm, negative values correspond to -W or -H pixels; 'w' suffix swaps width & height; None defaults to A4 paper - - @rtype: (int,int) """ if not spec: return (ISOPAGE[5], ISOPAGE[4]) @@ -64,17 +62,11 @@ def page_spec(spec = None): return (w,h) def mm_to_dots(mm): - """convert millimeters to dots - - @rtype: float - """ + """convert millimeters to dots""" return mm/25.4 * XDPI def dots_to_mm(dots): - """convert dots to millimeters - - @rtype: float - """ + """convert dots to millimeters""" return dots*25.4/XDPI class Page(object): @@ -213,10 +205,7 @@ def set_color(cr, rgba): cr.set_source_rgba(*rgba) def extract_font_name(f): - """extract the font name from a string or from a tuple (fontname, slant, weight) - - @rtype: str - """ + "extract the font name from a string or from a tuple (fontname, slant, weight)""" return f if type(f) is str else f[0] def make_sloppy_rect(cr, rect, sdx = 0.0, sdy = 0.0, srot = 0.0): @@ -244,6 +233,8 @@ def draw_shadow(cr, rect, thickness = None, shadow_color = (0,0,0,0.3)): @param thickness: if C{None} nothing is drawn @param shadow_color: shadow color """ + + if thickness is None: return fx = mm_to_dots(thickness[0]) fy = mm_to_dots(thickness[1]) diff --git a/make_pkg b/make_pkg index 97174e9..1b923c4 100755 --- a/make_pkg +++ b/make_pkg @@ -1,6 +1,7 @@ #!/bin/bash mkdir _callirhoe +./make_resources_list > resources.py cp -R geom _callirhoe cp -R holidays _callirhoe cp -R lang _callirhoe @@ -8,12 +9,13 @@ cp -R layouts _callirhoe cp -R lib _callirhoe cp -R style _callirhoe cp callirhoe.py _callirhoe/__main__.py +mv resources.py lib cd _callirhoe zip -q -r callirhoe.zip * mv callirhoe.zip ../ cd .. -rm -rf _callirhoe +#rm -rf _callirhoe echo \#!/usr/bin/env python2 | cat - callirhoe.zip > callirhoe chmod 755 callirhoe rm callirhoe.zip From d6221eff89ad9946621772bfe33e3b7a1c3068a5 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 12:22:57 +0000 Subject: [PATCH 12/71] added make_resource_list git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@173 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_resources_list | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 make_resources_list diff --git a/make_resources_list b/make_resources_list new file mode 100755 index 0000000..abca989 --- /dev/null +++ b/make_resources_list @@ -0,0 +1,10 @@ +#!/bin/bash + +echo -n resource_list = { \"lang\" : [ +find ./lang | grep '.py' | sed 's/\.\//"/' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' +echo -n \"layouts\" : [ +find ./layouts | grep '.py' | sed 's/\.\//"/' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' +echo -n \"style\" : [ +find ./style | grep '.py' | sed 's/\.\//"/' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' +echo -n \"geom\" : [ +find ./geom | grep '.py' | sed 's/\.\//"/' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/]}/' From af09f855ff287a8a9f5f77114c1ed605913d6ed4 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 13:10:12 +0000 Subject: [PATCH 13/71] making things up to date git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@174 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- callirhoe.py | 38 +++++++++++----- calmagick.py | 64 +++++++++++++++++++++------ layouts/_base.py | 1 + layouts/classic.py | 5 ++- layouts/sparse.py | 1 + lib/geom.py | 105 +++++++++++++++++++++++++++++++++++++-------- lib/holiday.py | 54 +++++++++++++++++------ lib/plugin.py | 17 +++++--- lib/xcairo.py | 19 +++++--- 9 files changed, 237 insertions(+), 67 deletions(-) diff --git a/callirhoe.py b/callirhoe.py index ecfc727..d376fb3 100755 --- a/callirhoe.py +++ b/callirhoe.py @@ -75,13 +75,14 @@ def import_plugin(plugin_paths, cat, longcat, longcat2, listopt, preset): @param longcat2: long category name in plural form @param listopt: option name @param preset: default value + @rtype: module @note: Aimed for internal use with I{lang}, I{style}, I{geom}, I{layouts}. """ try: found = [] for path in plugin_paths: - found += available_files(plugin_paths[0], cat, preset) + found += available_files(path, cat, preset) if len(found) == 0: raise IOError old = sys.path[0]; sys.path[0] = found[0][1] @@ -137,12 +138,13 @@ def add_list_option(parser, opt): parser.add_option("--list-%s" % opt, action="store_true", dest="list_%s" % opt, default=False, help="list available %s" % opt) -def itoa(s, lower_bound=None, upper_bound=None, prefix=''): - """convert integer to string, exiting on error (for cmdline parsing) +def atoi(s, lower_bound=None, upper_bound=None, prefix=''): + """convert string to integer, exiting on error (for cmdline parsing) @param lower_bound: perform additional check so that value >= I{lower_bound} @param upper_bound: perform additional check so that value <= I{upper_bound} @param prefix: output prefix for error reporting + @rtype: int """ try: k = int(s); @@ -157,31 +159,40 @@ def itoa(s, lower_bound=None, upper_bound=None, prefix=''): return k def _parse_month(mstr): - """get a month value (0-12) from I{mstr}, exiting on error (for cmdline parsing)""" - m = itoa(mstr,lower_bound=0,upper_bound=12,prefix='month: ') + """get a month value (0-12) from I{mstr}, exiting on error (for cmdline parsing) + + @rtype: int + """ + m = atoi(mstr,lower_bound=0,upper_bound=12,prefix='month: ') if m == 0: m = time.localtime()[1] return m def parse_month_range(s): - """return (Month,Span) by parsing range I{Month}, I{Month1}-I{Month2} or I{Month}:I{Span}""" + """return (Month,Span) by parsing range I{Month}, I{Month1}-I{Month2} or I{Month}:I{Span} + + @rtype: (int,int) + """ if ':' in s: t = s.split(':') if len(t) != 2: raise Abort("invalid month range '" + s + "'") Month = _parse_month(t[0]) - MonthSpan = itoa(t[1],lower_bound=0,prefix='month span: ') + MonthSpan = atoi(t[1],lower_bound=0,prefix='month span: ') elif '-' in s: t = s.split('-') if len(t) != 2: raise Abort("invalid month range '" + s + "'") Month = _parse_month(t[0]) - MonthSpan = itoa(t[1],lower_bound=Month+1,prefix='month range: ') - Month + 1 + MonthSpan = atoi(t[1],lower_bound=Month+1,prefix='month range: ') - Month + 1 else: Month = _parse_month(s) MonthSpan = 1 return (Month,MonthSpan) def parse_year(ystr): - """get a year value (>=0) from I{ystr}, exiting on error (for cmdline parsing)""" - y = itoa(ystr,lower_bound=0,prefix='year: ') + """get a year value (>=0) from I{ystr}, exiting on error (for cmdline parsing) + + @rtype: int + """ + y = atoi(ystr,lower_bound=0,prefix='year: ') if y == 0: y = time.localtime()[0] return y @@ -195,6 +206,8 @@ def extract_parser_args(arglist, parser, pos = -1): if I{pos}<0 then all positional arguments are extracted, otherwise, only I{pos} arguments are extracted. arglist[0] (usually sys.argv[0]) is also positional argument! + + @rtype: ([str,...],[str,...]) @return: tuple (argv1,argv2) with extracted argument list and remaining argument list """ argv = [[],[]] @@ -223,7 +236,10 @@ def extract_parser_args(arglist, parser, pos = -1): return tuple(argv) def get_parser(): - """get the argument parser object""" + """get the argument parser object + + @rtype: optparse.OptionParser + """ parser = optparse.OptionParser(usage="usage: %prog [options] [[MONTH[-MONTH2|:SPAN]] YEAR] FILE", description="High quality calendar rendering with vector graphics. " "By default, a calendar of the current year in pdf format is written to FILE. " diff --git a/calmagick.py b/calmagick.py index 81fc373..38d1485 100755 --- a/calmagick.py +++ b/calmagick.py @@ -34,14 +34,14 @@ import optparse import Queue import threading -from callirhoe import extract_parser_args, parse_month_range, parse_year, itoa, Abort, _version, _copyright +from callirhoe import extract_parser_args, parse_month_range, parse_year, atoi, Abort, _version, _copyright from lib.geom import rect_rel_scale # MAYBE-TODO # move to python 3? # check ImageMagick availability/version # convert input to ImageMagick native format for faster re-access -# report error on parse-float (like itoa()) +# report error on parse-float (like atoi()) # abort --range only on KeyboardInterrupt? _prog_im = os.getenv('CALLIRHOE_IM', 'convert') @@ -54,12 +54,16 @@ def run_callirhoe(style, size, args, outfile): @param size: tuple (I{width},I{height}) for output calendar size (in pixels) @param args: (extra) argument list to pass to callirhoe @param outfile: output calendar file - @return: subprocess exit code + @rtype: subprocess.Popen + @return: Popen object """ return subprocess.Popen(['callirhoe', '-s', style, '--paper=-%d:-%d' % size] + args + [outfile]) def _bound(x, lower, upper): - """return the closest number to M{x} that lies in [M{lower,upper}]""" + """return the closest number to M{x} that lies in [M{lower,upper}] + + @rtype: type(x) + """ if x < lower: return lower if x > upper: return upper return x @@ -111,7 +115,10 @@ class PNMImage(object): self.xsum = [map(lambda x: self._rsum(y,x), range(w+1)) for y in range(0,h)] def _rsum(self,y,x): - """running sum with cache""" + """running sum with cache + + @rtype: int + """ if self._rsum_cache[0] == y and self._rsum_cache[1] == x: s = self._rsum_cache[2] + self.data[y][x-1] else: @@ -120,11 +127,15 @@ class PNMImage(object): return s def block_avg(self, x, y, szx, szy): - """returns the average intensity of a block of size M{(szx,szy)} at pos (top-left) M{(x,y)}""" + """returns the average intensity of a block of size M{(szx,szy)} at pos (top-left) M{(x,y)} + + @rtype: float + """ return float(sum([(self.xsum[y][x+szx] - self.xsum[y][x]) for y in range(y,y+szy)]))/(szx*szy) def lowest_block_avg(self, szx, szy, at_least = 0): """returns the M{(szx,szy)}-sized block with intensity as close to M{at_least} as possible + @rtype: (float,(float,float),(int,int),(int,int)) @return: R=tuple M({avg, (szx_ratio,szy_ratio), (x,y), (szx,szy))}: R[0] is the average intensity of the block found, R[1] is the block size ratio with respect to the whole image, R[2] is the block position (top-left) and R[3] is the block size @@ -154,6 +165,8 @@ class PNMImage(object): Calendar rectangle ratio over Photo ratio. If M{r>1} then calendar rectangle, when scaled, fits M{x} dimension first. Conversely, if M{r<1}, scaling touches the M{y} dimension first. When M{r=1}, calendar rectangle can fit perfectly within the photo at 100% size. + + @rtype: (float,(float,float),(int,int),(int,int),float) """ w,h = self.size sz_lo = _bound(int(w*size_range[0]+0.5),1,w) @@ -172,11 +185,14 @@ class PNMImage(object): # we do not use at_least because we want the best possible option, for bigger sizes cur = self.lowest_block_avg(*sz) if cur[0] <= entropy_thres: return cur + (best[0],) - return best + (best[0],) # avg, sz_ratio, x, y, sz, best_avg + return best + (best[0],) # avg, (szx_ratio,szy_ratio), (x,y), (szx,szy), best_avg def get_parser(): - """get the argument parser object""" + """get the argument parser object + + @rtype: optparse.OptionParser + """ parser = optparse.OptionParser(usage="usage: %prog IMAGE [options] [callirhoe-options] [--pre-magick ...] [--in-magick ...] [--post-magick ...]", description="""High quality photo calendar composition with automatic minimal-entropy placement. If IMAGE is a single file, then a calendar of the current month is overlayed. If IMAGE contains wildcards, @@ -303,6 +319,7 @@ def parse_magick_args(): ImageMagick-specific arguments should be defined between arguments C{--pre-magick}, C{--in-magick}, C{--post-magick} is this order + @rtype: [[str,...],[str,...],[str,...]] @return: 3-element list of lists containing the [pre,in,post]-options """ magickargs = [[],[],[]] @@ -332,13 +349,19 @@ def parse_magick_args(): return magickargs def mktemp(ext=''): - """get temporary file name with optional extension""" + """get temporary file name with optional extension + + @rtype: str + """ f = tempfile.NamedTemporaryFile(suffix=ext, delete=False) f.close() return f.name def get_outfile(infile, outdir, base_prefix, format, hint=None): - """get output file name taking into account output directory, format and prefix, avoiding overwriting the input file""" + """get output file name taking into account output directory, format and prefix, avoiding overwriting the input file + + @rtype: str + """ if hint: outfile = hint else: @@ -352,7 +375,10 @@ def get_outfile(infile, outdir, base_prefix, format, hint=None): return outfile def _IM_get_image_size(img, args): - """extract tuple(width,height) from image file using ImageMagick""" + """extract tuple(width,height) from image file using ImageMagick + + @rtype: (int,int) + """ info = subprocess.check_output([_prog_im, img] + args + ['-format', '%w %h', 'info:']).split() return tuple(map(int, info)) @@ -360,7 +386,10 @@ _IM_lum_args = "-colorspace Lab -channel R -separate +channel -set colorspace Gr """IM colorspace conversion arguments to extract image luminance""" def _IM_get_image_luminance(img, args, geometry = None): - """get average image luminance as a float in [0,255], using ImageMagick""" + """get average image luminance as a float in [0,255], using ImageMagick + + @rtype: float + """ return 255.0*float(subprocess.check_output([_prog_im, img] + args + (['-crop', '%dx%d+%d+%d' % geometry] if geometry else []) + _IM_lum_args + ['-format', '%[fx:mean]', 'info:'])) @@ -375,7 +404,10 @@ _IM_entropy_tail = "-colorspace Lab -channel R -separate +channel -set colorspac #_IM_entropy_tail = "-colorspace Lab -channel R -separate +channel -normalize -scale".split() def _IM_entropy_args(alt=False): - """IM entropy computation arguments, depending on default or alternate algorithm""" + """IM entropy computation arguments, depending on default or alternate algorithm + + @rtype: [str,...] + """ return _IM_entropy_head + _IM_entropy_alg[alt] + _IM_entropy_tail def _entropy_placement(img, size, args, options, r): @@ -386,6 +418,7 @@ def _entropy_placement(img, size, args, options, r): @param args: ImageMagick pre-processing argument list (see C{--pre-magick}) @param options: (command-line) options object @param r: rectangle ratio, 0=match input ratio + @rtype: (int,int,int,int) @return: IM geometry tuple(I{width,height,x,y}) """ w,h = size @@ -417,6 +450,7 @@ def _manual_placement(size, options, r): @param size: image size tuple(I{width,height}) @param options: (command-line) options object @param r: rectangle ratio, 0=match input ratio + @rtype: (int,int,int,int) @return: IM geometry tuple(I{width,height,x,y}) """ w,h = size @@ -449,6 +483,7 @@ _mutex = threading.Lock() def get_cache(num_photos, num_months): """returns a reference to the cache object, or None if caching is disabled + @rtype: dict @note: caching is enabled only when more than 1/6 of photos is going to be re-used """ q,r = divmod(num_months, num_photos) @@ -488,7 +523,7 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No if '/' in options.ratio: tmp = options.ratio.split('/') - calratio = float(itoa(tmp[0],1))/itoa(tmp[1],1) + calratio = float(atoi(tmp[0],1))/atoi(tmp[1],1) else: calratio = float(options.ratio) if options.placement == 'min' or options.placement == 'max': @@ -556,6 +591,7 @@ def parse_range(s,hint=None): @param s: range string in format I{Month1-Month2/Year} or I{Month:Span/Year} @param hint: span value to be used, when M{Span=0} + @rtype: [(int,int),...] @return: list of (I{Month,Year}) tuples for every month specified """ if '/' in s: diff --git a/layouts/_base.py b/layouts/_base.py index c0fe3c7..7fe79ae 100644 --- a/layouts/_base.py +++ b/layouts/_base.py @@ -26,6 +26,7 @@ def get_parser(layout_name): """get the parser object for the layout command-line arguments @param layout_name: corresponding python module (.py file) + @rtype: optparse.OptionParser """ lname = layout_name.split(".")[1] parser = optparse.OptionParser(usage="%prog (...) --layout " + lname + " [options] (...)",add_help_option=False) diff --git a/layouts/classic.py b/layouts/classic.py index cc5e71a..b64ec67 100644 --- a/layouts/classic.py +++ b/layouts/classic.py @@ -28,7 +28,10 @@ import _base parser = _base.get_parser(__name__) def _weekrows_of_month(year, month): - """returns the number of Monday-Sunday ranges (or subsets of) that a month contains, which are 4, 5 or 6""" + """returns the number of Monday-Sunday ranges (or subsets of) that a month contains, which are 4, 5 or 6 + + @rtype: int + """ day,span = calendar.monthrange(year, month) if day == 0 and span == 28: return 4 if day == 5 and span == 31: return 6 diff --git a/layouts/sparse.py b/layouts/sparse.py index 0b9c75d..e9bedb6 100644 --- a/layouts/sparse.py +++ b/layouts/sparse.py @@ -33,6 +33,7 @@ def get_parser(layout_name): """get the parser object for the layout command-line arguments @param layout_name: corresponding python module (.py file) + @rtype: optparse.OptionParser """ lname = layout_name.split(".")[1] parser = optparse.OptionParser(usage="%prog (...) --layout " + lname + " [options] (...)",add_help_option=False) diff --git a/lib/geom.py b/lib/geom.py index 3f7918c..d7d5139 100644 --- a/lib/geom.py +++ b/lib/geom.py @@ -23,7 +23,10 @@ # ***************************************** def rect_ratio(r): - """returns the ratio of rect I{r} which is defined as M{width/height}""" + """returns the ratio of rect I{r} which is defined as M{width/height} + + @rtype: float + """ return r[2]*1.0/r[3] def rect_rel_scale(r, fw, fh, align_x = 0, align_y = 0): @@ -40,33 +43,49 @@ def rect_rel_scale(r, fw, fh, align_x = 0, align_y = 0): linear interpolation. @type align_y: float in [-1,1] @param align_y: Performs vertical (top-bottom) alignment similarly to L{align_x}. + @rtype: (float,float,float,float) """ x, y, w, h = r return (x + (align_x + 1.0)*w*(1 - fw)/2.0, y + (align_y + 1.0)*h*(1 - fh)/2.0, w*fw, h*fh) def rect_pad(r, pad): - """returns a padded rect by reducing border by the I{pad} tuple (top,left,bottom,right)""" + """returns a padded rect by reducing border by the I{pad} tuple (top,left,bottom,right) + + @rtype: (float,float,float,float) + """ x, y, w, h = r t_, l_, b_, r_ = pad return (x + l_, y + t_, w - r_ - l_, h - t_ - b_) def rect_to_abs(r): - """get absolute coordinates (x0,y0,x1,y1) from rect definition (x,y,w,h)""" + """get absolute coordinates (x0,y0,x1,y1) from rect definition (x,y,w,h) + + @rtype: (float,float,float,float) + """ x, y, w, h = r return (x, y, x + w, y + h) def abs_to_rect(a): - """get rect definition (x,y,w,h) from absolute coordinates (x0,y0,x1,y1)""" + """get rect definition (x,y,w,h) from absolute coordinates (x0,y0,x1,y1) + + @rtype: (float,float,float,float) + """ x1, y1, x2, y2 = a return (x1, y1, x2 - x1, y2 - y1) def rect_from_origin(r): - """returns a similar rect with top-left corner at (0,0)""" + """returns a similar rect with top-left corner at (0,0) + + @rtype: (float,float,float,float) + """ return (0, 0, r[2], r[3]) def rect_hull(r1,r2): - """returns the smallest rect containing r1 and r2""" + """returns the smallest rect containing r1 and r2 + + @rtype: (float,float,float,float) + """ x1, y1, x2, y2 = rect_to_abs(r1) x3, y3, x4, y4 = rect_to_abs(r2) return abs_to_rect((min(x1,x3), min(y1,y3), max(x2,x4), max(y2,y4))) @@ -77,6 +96,7 @@ def rect_hsplit(r, f = 0.5, fdist = 0.0): @type f: float in [0,1] @param f: split fraction @param fdist: fraction of space to discard before splitting (free space) + @rtype: ((float,float,float,float),(float,float,float,float)) @return: tuple (r1,r2) with splits and free space evenly distributed before r1, between r1 and r2 and after r2 """ @@ -87,7 +107,10 @@ def rect_hsplit(r, f = 0.5, fdist = 0.0): return (r1, r2) def rect_vsplit(r, f = 0.5, fdist = 0.0): - """split a rect vertically, similarly to L{rect_hsplit}""" + """split a rect vertically, similarly to L{rect_hsplit} + + @rtype: ((float,float,float,float),(float,float,float,float)) + """ x, y, w, h = r rh = h*(1.0 - fdist) r1 = (x, y + h*fdist/3.0, w, rh*f) @@ -99,6 +122,7 @@ def color_mix(a, b, frac): @type frac: float in [0,1] @param frac: amount of first color + @rtype: tuple """ return map(lambda (x,y): x*frac + y*(1 - frac), zip(a,b)) @@ -107,11 +131,15 @@ def color_scale(a, frac): @type frac: float @param frac: scale amount (to be multiplied) + @rtype: tuple """ return map(lambda x: min(1.0,x*frac), a) 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} + + @rtype: tuple + """ return light if (bg[0] + 1.5*bg[1] + bg[2]) < 1.0 else dark # ********* layout managers *********** @@ -129,7 +157,10 @@ class VLayout(object): self.pad = pad def count(self): - """return maximum number of items in the layout""" + """return maximum number of items in the layout + + @rtype: int + """ return self.nitems def resize(self, k): @@ -141,7 +172,10 @@ class VLayout(object): self.nitems += delta def item(self, i = 0): - """get rect for item I{i}""" + """get rect for item I{i} + + @rtype: (float,float,float,float) + """ x, y, w, h = self.rect h *= 1.0/self.nitems y += i*h @@ -152,12 +186,16 @@ class VLayout(object): @param n: first item @param k: number of items, -1 for all remaining items + @rtype: (float,float,float,float) """ if k < 0: k = (self.count() - n) // 2 return rect_hull(self.item(k), self.item(k + n - 1)) def items(self): - """returns a sequence of all items""" + """returns a sequence of all items + + @rtype: (float,float,float,float),... + """ return map(self.item, range(self.count())) class HLayout(VLayout): @@ -167,6 +205,10 @@ class HLayout(VLayout): nitems, (pad[1], pad[0], pad[3], pad[2])) def item(self, i = 0): + """get rect for item I{i} + + @rtype: (float,float,float,float) + """ t = super(HLayout,self).item(i) return (t[1], t[0], t[3], t[2]) @@ -189,15 +231,24 @@ class GLayout(object): self.hrep = HLayout((rect[0], rect[1], t[2], t[3]), ncols, (0.0, pad[1], 0.0, pad[3])) def row_count(self): - """get (max) number of rows in the grid""" + """get (max) number of rows in the grid + + @rtype: int + """ return self.vrep.count() def col_count(self): - """get (max) number of columns in the grid""" + """get (max) number of columns in the grid + + @rtype: int + """ return self.hrep.count() def count(self): - """get total number of cells in the grid (which is M{rows*cols})""" + """get total number of cells in the grid (which is M{rows*cols}) + + @rtype: int + """ return self.row_count()*self.col_count() def resize(self, rows, cols): @@ -207,13 +258,19 @@ class GLayout(object): self.hrep = HLayout(t[0:2], t[2:4], cols, (0.0, pad[1], 0.0, pad[3])) def item(self, row, col): - """get rect of cell at position I{row,col}""" + """get rect of cell at position I{row,col} + + @rtype: (float,float,float,float) + """ ty = self.vrep.item(row) tx = self.hrep.item(col) return (tx[0], ty[1], tx[2], tx[3]) def item_seq(self, k, column_wise = False): - """get rect of cell at position I{k} column-wise or row-wise""" + """get rect of cell at position I{k} column-wise or row-wise + + @rtype: (float,float,float,float) + """ if not column_wise: row, col = k // self.col_count(), k % self.col_count() else: @@ -221,15 +278,24 @@ class GLayout(object): return self.item(row, col) def items(self, column_wise = False): - """get sequence of rects of cells column-wise or row-wise""" + """get sequence of rects of cells column-wise or row-wise + + @rtype: (float,float,float,float),... + """ return map(self.item_seq, range(self.count())) 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),... + """ return map(lambda x: self.item(row, x), range(self.col_count())) 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),... + """ return map(lambda x: self.item(x, col), range(self.row_count())) @@ -240,6 +306,7 @@ class GLayout(object): @param nc: number of spanning columns @param row: starting row, -1 for vertically centered @param col: starting column, -1 for horizontally centered + @rtype: (float,float,float,float) """ if row < 0: row = (self.row_count() - nr) // 2 if col < 0: col = (self.col_count() - nc) // 2 diff --git a/lib/holiday.py b/lib/holiday.py index 22024a6..f3d4fdd 100644 --- a/lib/holiday.py +++ b/lib/holiday.py @@ -25,7 +25,9 @@ from datetime import date, timedelta def _get_orthodox_easter(year): - """compute date of orthodox easter""" + """compute date of orthodox easter + @rtype: datetime.date + """ y1, y2, y3 = year % 4 , year % 7, year % 19 a = 19*y3 + 15 y4 = a % 30 @@ -37,7 +39,10 @@ def _get_orthodox_easter(year): # return res def _get_catholic_easter(year): - """compute date of catholic easter""" + """compute date of catholic easter + + @rtype: datetime.date + """ a, b, c = year % 19, year // 100, year % 100 d, e = divmod(b,4) f = (b + 8) // 25 @@ -50,11 +55,17 @@ def _get_catholic_easter(year): return date(year, emonth, edate+1) def _strip_empty(sl): - """strip empty strings from list I{sl}""" + """strip empty strings from list I{sl} + + @rtype: [str,...] + """ return filter(lambda z: z, sl) if sl else [] def _flatten(sl): - """join list I{sl} into a comma-separated string""" + """join list I{sl} into a comma-separated string + + @rtype: str + """ if not sl: return None return ', '.join(sl) @@ -94,19 +105,31 @@ class Holiday(object): self.flags |= hol.flags def header(self): - """return a comma-separated string for L{header_list}""" + """return a comma-separated string for L{header_list} + + @rtype: str + """ return _flatten(self.header_list) def footer(self): - """return a comma-separated string for L{footer_list}""" + """return a comma-separated string for L{footer_list} + + @rtype: str + """ return _flatten(self.footer_list) def __str__(self): - """string representation for debugging purposes""" + """string representation for debugging purposes + + @rtype: str + """ return str(self.footer()) + ':' + str(self.header()) + ':' + str(self.flags) def _parse_flags(self, fstr): - """return a bit combination of flags, from a comma-separated string list""" + """return a bit combination of flags, from a comma-separated string list + + @rtype: int + """ if not fstr: return 0 fs = fstr.split(',') val = 0 @@ -130,6 +153,8 @@ def _decode_date_str(ddef): If C{ddef} is of the form "YYYYMMDD" then tuple (YYYY,MM,DD) is returned, which stands for year YYYY - month MM - day DD. + + @rtype: (int,int,int) """ if len(ddef) == 2: return (0,0,int(ddef)) @@ -189,11 +214,12 @@ class HolidayProvider(object): def _parse_day_record(self, fields): """return tuple (etype,ddef,footer,header,flags) + @rtype: (char,type(ddef),str,str,int) @note: I{ddef} is one of the following: - None - int - ((y,m,d),) - ((y,m,d),(y,m,d)) + - None + - int + - ((y,m,d),) + - ((y,m,d),(y,m,d)) """ if len(fields) != 5: raise ValueError("Too many fields: " + str(fields)) @@ -239,6 +265,7 @@ class HolidayProvider(object): @param header: passed as C{[header]} of the generated L{Holiday} object @param footer: passed as C{[footer]} of the generated L{Holiday} object @param flags: C{flags} of the generated L{Holiday} object + @rtype: (Holiday,Holiday,Holiday,Holiday) """ if header: if self.multiday_markers: @@ -341,6 +368,7 @@ class HolidayProvider(object): def get_holiday(self, y, m, d): """return a L{Holiday} object for the specified date (y,m,d) or C{None} if no holiday is defined + @rtype: Holiday @note: If year I{y} has not been requested before, the cache is updated first with all holidays that belong in I{y}, indexed by C{date()} objects. """ @@ -388,6 +416,7 @@ class HolidayProvider(object): def get_style(self, flags, dow): """return appropriate style object, depending on I{flags} and I{dow} + @rtype: Style @param flags: bit combination of holiday flags @param dow: day of week """ @@ -400,6 +429,7 @@ class HolidayProvider(object): def __call__(self, year, month, dom, dow): """returns (header,footer,day_style) + @rtype: (str,str,Style) @param month: month (0-12) @param dom: day of month (1-31) @param dow: day of week (0-6) diff --git a/lib/plugin.py b/lib/plugin.py index 3c9d99f..8e5dcf3 100644 --- a/lib/plugin.py +++ b/lib/plugin.py @@ -34,6 +34,7 @@ except: def available_files(parent, dir, fmatch = None): """find parent/dir/*.py files to be used for plugins + @rtype: [str,...] @note: 1. __init__.py should exist 2. files starting with underscore are ignored @@ -55,7 +56,10 @@ def available_files(parent, dir, fmatch = None): return res if good else [] def plugin_list(cat): - """return a sequence of available plugins, using L{available_files()} and L{get_plugin_paths()}""" + """return a sequence of available plugins, using L{available_files()} and L{get_plugin_paths()} + + @rtype: [str,...] + """ plugin_paths = get_plugin_paths() return available_files(plugin_paths[0], cat) + available_files(plugin_paths[1], cat) @@ -66,11 +70,14 @@ def plugin_list(cat): # preset = "EN" def get_plugin_paths(): - """return the plugin search paths""" - result = [ os.path.expanduser("~/.callirhoe"), sys.path[0] if sys.path[0] else "."] + """return the plugin search paths + + @rtype: [str,str,..] + """ + result = [ os.path.expanduser("~/.callirhoe"), sys.path[0] if sys.path[0] else "." ] try: - tmp = resources.resource_list - result.append["resource"] + temp = resources.resource_list + result.append("resource") except: pass return result diff --git a/lib/xcairo.py b/lib/xcairo.py index 4e1c899..dcc2667 100644 --- a/lib/xcairo.py +++ b/lib/xcairo.py @@ -43,6 +43,8 @@ def page_spec(spec = None): Paper type can be an ISO paper type (a0..a9 or a0w..a9w) or of the form W:H; positive values correspond to W or H mm, negative values correspond to -W or -H pixels; 'w' suffix swaps width & height; None defaults to A4 paper + + @rtype: (int,int) """ if not spec: return (ISOPAGE[5], ISOPAGE[4]) @@ -62,11 +64,17 @@ def page_spec(spec = None): return (w,h) def mm_to_dots(mm): - """convert millimeters to dots""" + """convert millimeters to dots + + @rtype: float + """ return mm/25.4 * XDPI def dots_to_mm(dots): - """convert dots to millimeters""" + """convert dots to millimeters + + @rtype: float + """ return dots*25.4/XDPI class Page(object): @@ -205,7 +213,10 @@ def set_color(cr, rgba): cr.set_source_rgba(*rgba) def extract_font_name(f): - "extract the font name from a string or from a tuple (fontname, slant, weight)""" + """extract the font name from a string or from a tuple (fontname, slant, weight) + + @rtype: str + """ return f if type(f) is str else f[0] def make_sloppy_rect(cr, rect, sdx = 0.0, sdy = 0.0, srot = 0.0): @@ -233,8 +244,6 @@ def draw_shadow(cr, rect, thickness = None, shadow_color = (0,0,0,0.3)): @param thickness: if C{None} nothing is drawn @param shadow_color: shadow color """ - - if thickness is None: return fx = mm_to_dots(thickness[0]) fy = mm_to_dots(thickness[1]) From d8e74ff812dfcc8df89ec6d815029d941a298275 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 14:15:46 +0000 Subject: [PATCH 14/71] Fixed some things, now it partialy works What doesn't work is --list-[plugin] git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@175 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- callirhoe.py | 11 +++++++---- lib/plugin.py | 4 ++-- make_pkg | 2 +- make_resources_list | 8 ++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/callirhoe.py b/callirhoe.py index d376fb3..f6fcf1c 100755 --- a/callirhoe.py +++ b/callirhoe.py @@ -84,10 +84,13 @@ def import_plugin(plugin_paths, cat, longcat, longcat2, listopt, preset): for path in plugin_paths: found += available_files(path, cat, preset) if len(found) == 0: raise IOError - old = sys.path[0]; - sys.path[0] = found[0][1] - m = __import__("%s.%s" % (cat,preset), globals(), locals(), [ "*" ]) - sys.path[0] = old + if found[0][1] == "/": + m = __import__("%s.%s" % (cat,preset), globals(), locals(), [ "*" ]) + else: + old = sys.path[0] + sys.path[0] = found[0][1] + m = __import__("%s.%s" % (cat,preset), globals(), locals(), [ "*" ]) + sys.path[0] = old return m except IOError: sys.exit("callirhoe: %s definition '%s' not found, use %s to see available definitions" % (longcat, diff --git a/lib/plugin.py b/lib/plugin.py index 8e5dcf3..0e02fc4 100644 --- a/lib/plugin.py +++ b/lib/plugin.py @@ -43,7 +43,7 @@ def available_files(parent, dir, fmatch = None): good = False res = [] pattern = parent + "/" + dir + "/*.py" - for x in glob.glob(pattern) if parent != "resource" else resources.resource_list[dir]: + for x in glob.glob(pattern) if parent != "/" else resources.resource_list[dir]: basex = os.path.basename(x) if basex == "__init__.py": good = True elif basex.startswith('_'): @@ -77,7 +77,7 @@ def get_plugin_paths(): result = [ os.path.expanduser("~/.callirhoe"), sys.path[0] if sys.path[0] else "." ] try: temp = resources.resource_list - result.append("resource") + result.append("/") except: pass return result diff --git a/make_pkg b/make_pkg index 1b923c4..e1b7a0f 100755 --- a/make_pkg +++ b/make_pkg @@ -9,7 +9,7 @@ cp -R layouts _callirhoe cp -R lib _callirhoe cp -R style _callirhoe cp callirhoe.py _callirhoe/__main__.py -mv resources.py lib +mv resources.py _callirhoe/lib cd _callirhoe zip -q -r callirhoe.zip * diff --git a/make_resources_list b/make_resources_list index abca989..bb8a267 100755 --- a/make_resources_list +++ b/make_resources_list @@ -1,10 +1,10 @@ #!/bin/bash echo -n resource_list = { \"lang\" : [ -find ./lang | grep '.py' | sed 's/\.\//"/' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' +find ./lang | grep '.py' | sed 's/\.\//"\//' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' echo -n \"layouts\" : [ -find ./layouts | grep '.py' | sed 's/\.\//"/' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' +find ./layouts | grep '.py' | sed 's/\.\//"\//' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' echo -n \"style\" : [ -find ./style | grep '.py' | sed 's/\.\//"/' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' +find ./style | grep '.py' | sed 's/\.\//"\//' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' echo -n \"geom\" : [ -find ./geom | grep '.py' | sed 's/\.\//"/' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/]}/' +find ./geom | grep '.py' | sed 's/\.\//"\//' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/]}/' From fbd576884152278ee51a1a9d3da387a34019d0f6 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 14:22:04 +0000 Subject: [PATCH 15/71] Fixed! It's working! git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@176 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- lib/plugin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/plugin.py b/lib/plugin.py index 0e02fc4..1f287c7 100644 --- a/lib/plugin.py +++ b/lib/plugin.py @@ -61,7 +61,10 @@ def plugin_list(cat): @rtype: [str,...] """ plugin_paths = get_plugin_paths() - return available_files(plugin_paths[0], cat) + available_files(plugin_paths[1], cat) + result = [] + for path in plugin_paths: + result += available_files(path, cat) + return result # cat = lang (category) # longcat = language From 6e3e42d0d1324c729587e7205ce5e325e7d04ac2 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 14:37:44 +0000 Subject: [PATCH 16/71] Cleaning here and there git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@177 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/make_pkg b/make_pkg index e1b7a0f..660443f 100755 --- a/make_pkg +++ b/make_pkg @@ -1,13 +1,9 @@ #!/bin/bash +# Create Callirhoe package mkdir _callirhoe ./make_resources_list > resources.py -cp -R geom _callirhoe -cp -R holidays _callirhoe -cp -R lang _callirhoe -cp -R layouts _callirhoe -cp -R lib _callirhoe -cp -R style _callirhoe +cp -R geom holidays lang layouts lib style _callirhoe cp callirhoe.py _callirhoe/__main__.py mv resources.py _callirhoe/lib @@ -15,19 +11,14 @@ cd _callirhoe zip -q -r callirhoe.zip * mv callirhoe.zip ../ cd .. -#rm -rf _callirhoe +rm -rf _callirhoe echo \#!/usr/bin/env python2 | cat - callirhoe.zip > callirhoe chmod 755 callirhoe rm callirhoe.zip +# Create Calmagick package mkdir _calmagick - -cp -R geom _calmagick -cp -R holidays _calmagick -cp -R lang _calmagick -cp -R layouts _calmagick -cp -R lib _calmagick -cp -R style _calmagick +cp -R geom holidays lang layouts lib style _calmagick cp callirhoe.py _calmagick cp calmagick.py _calmagick/__main__.py From 23512dc89cd2213248093c89968d757fe75f2987 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 14:49:25 +0000 Subject: [PATCH 17/71] Automating things git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@178 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- Makefile | 14 ++++++++++++-- make_pkg | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index edb25c0..08f5ffd 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,13 @@ install: - install -m 0755 callirhoe $(prefix)/bin - install -m 0755 calmagick $(prefix)/bin +install -m 0755 callirhoe $(prefix)/bin +install -m 0755 calmagick $(prefix)/bin + install -m 644 holidays/ $(prefix)/share/callirhoe + install -m 644 holidays/germany_berlin_holidays.DE.dat $(prefix)/share/callirhoe + install -m 644 holidays/greek_holidays.EL.dat $(prefix)/share/callirhoe + install -m 644 holidays/french_holidays.EN.dat $(prefix)/share/callirhoe + install -m 644 holidays/french_holidays_zone_A.FR.dat $(prefix)/share/callirhoe + install -m 644 holidays/french_holidays_zone_C.FR.dat $(prefix)/share/callirhoe + install -m 644 holidays/generic_holidays.EN.dat $(prefix)/share/callirhoe + install -m 644 holidays/french_holidays_zone_B.FR.dat $(prefix)/share/callirhoe + install -m 644 holidays/french_holidays.FR.dat $(prefix)/share/callirhoe + install -m 644 holidays/greek_namedays.EL.dat $(prefix)/share/callirhoe diff --git a/make_pkg b/make_pkg index 660443f..49a29f3 100755 --- a/make_pkg +++ b/make_pkg @@ -31,4 +31,8 @@ echo \#!/usr/bin/env python2 | cat - calmagick.zip > calmagick chmod 755 calmagick rm calmagick.zip - +# Create Makefile +echo install: > Makefile +echo install -m 0755 callirhoe "$""(prefix)"/bin >> Makefile +echo install -m 0755 calmagick "$""(prefix)"/bin >> Makefile +find holidays/ | sed 's/^/ install -m 644 /' | sed 's/$/ \$(prefix)\/share\/callirhoe/' >> Makefile \ No newline at end of file From c87b9f31464865fded290b63aa7591fe89fb742b Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 14:49:54 +0000 Subject: [PATCH 18/71] Removed Makefile, it's auto generated now. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@179 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- Makefile | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 08f5ffd..0000000 --- a/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -install: -install -m 0755 callirhoe $(prefix)/bin -install -m 0755 calmagick $(prefix)/bin - install -m 644 holidays/ $(prefix)/share/callirhoe - install -m 644 holidays/germany_berlin_holidays.DE.dat $(prefix)/share/callirhoe - install -m 644 holidays/greek_holidays.EL.dat $(prefix)/share/callirhoe - install -m 644 holidays/french_holidays.EN.dat $(prefix)/share/callirhoe - install -m 644 holidays/french_holidays_zone_A.FR.dat $(prefix)/share/callirhoe - install -m 644 holidays/french_holidays_zone_C.FR.dat $(prefix)/share/callirhoe - install -m 644 holidays/generic_holidays.EN.dat $(prefix)/share/callirhoe - install -m 644 holidays/french_holidays_zone_B.FR.dat $(prefix)/share/callirhoe - install -m 644 holidays/french_holidays.FR.dat $(prefix)/share/callirhoe - install -m 644 holidays/greek_namedays.EL.dat $(prefix)/share/callirhoe From 3a50df857223d3d7e8b81d51570bcbff8b9e0ee2 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 16:25:24 +0000 Subject: [PATCH 19/71] Remake of "make_resources_list" which is a dict actually and not a list. Hm... git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@180 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_resources_list | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/make_resources_list b/make_resources_list index bb8a267..60ba466 100755 --- a/make_resources_list +++ b/make_resources_list @@ -1,10 +1,15 @@ -#!/bin/bash +#!/usr/bin/env python2 +import glob -echo -n resource_list = { \"lang\" : [ -find ./lang | grep '.py' | sed 's/\.\//"\//' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' -echo -n \"layouts\" : [ -find ./layouts | grep '.py' | sed 's/\.\//"\//' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' -echo -n \"style\" : [ -find ./style | grep '.py' | sed 's/\.\//"\//' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/], /' -echo -n \"geom\" : [ -find ./geom | grep '.py' | sed 's/\.\//"\//' | sed 's/$/"/' | tr '\n' ',' | sed 's/.$/]}/' +lang = glob.glob('lang/*.py') +style = glob.glob('style/*.py') +layouts = glob.glob('layouts/*.py') +geom = glob.glob('geom/*.py') + +out = open('resources.py', 'w') +out.write('resource_list = { ') +out.write('"lang" : ' + str(lang) + ', ') +out.write('"style" : ' + str(style)+ ', ') +out.write('"layouts" : ' + str(layouts) + ', ') +out.write('"geom" :' + str(geom) + ' }') +out.close() From eac11c245556b44b8c88fe46872c79a444c47e56 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 16:51:54 +0000 Subject: [PATCH 20/71] Made sys.path manipulation in load_plugin a bit more pythonic. Removed 2nd "try" inside plugin.py and made first work as George suggested. Reverted to "resource:" to make it feel correct. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@181 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- callirhoe.py | 7 +++---- lib/plugin.py | 11 ++++------- make_pkg | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/callirhoe.py b/callirhoe.py index f6fcf1c..9ad58bb 100755 --- a/callirhoe.py +++ b/callirhoe.py @@ -84,13 +84,12 @@ def import_plugin(plugin_paths, cat, longcat, longcat2, listopt, preset): for path in plugin_paths: found += available_files(path, cat, preset) if len(found) == 0: raise IOError - if found[0][1] == "/": + if found[0][1] == "resource:": m = __import__("%s.%s" % (cat,preset), globals(), locals(), [ "*" ]) else: - old = sys.path[0] - sys.path[0] = found[0][1] + sys.path.insert(0, found[0][1]) m = __import__("%s.%s" % (cat,preset), globals(), locals(), [ "*" ]) - sys.path[0] = old + sys.path.pop(0) return m except IOError: sys.exit("callirhoe: %s definition '%s' not found, use %s to see available definitions" % (longcat, diff --git a/lib/plugin.py b/lib/plugin.py index 1f287c7..76768c2 100644 --- a/lib/plugin.py +++ b/lib/plugin.py @@ -29,7 +29,7 @@ import glob try: import resources except: - pass + resources = None def available_files(parent, dir, fmatch = None): """find parent/dir/*.py files to be used for plugins @@ -43,7 +43,7 @@ def available_files(parent, dir, fmatch = None): good = False res = [] pattern = parent + "/" + dir + "/*.py" - for x in glob.glob(pattern) if parent != "/" else resources.resource_list[dir]: + for x in glob.glob(pattern) if not parent.startswith('resource:') else resources.resource_list[dir]: basex = os.path.basename(x) if basex == "__init__.py": good = True elif basex.startswith('_'): @@ -78,9 +78,6 @@ def get_plugin_paths(): @rtype: [str,str,..] """ result = [ os.path.expanduser("~/.callirhoe"), sys.path[0] if sys.path[0] else "." ] - try: - temp = resources.resource_list - result.append("/") - except: - pass + if resources: + result.append("resource:") return result diff --git a/make_pkg b/make_pkg index 49a29f3..9700886 100755 --- a/make_pkg +++ b/make_pkg @@ -2,7 +2,7 @@ # Create Callirhoe package mkdir _callirhoe -./make_resources_list > resources.py +./make_resources_list cp -R geom holidays lang layouts lib style _callirhoe cp callirhoe.py _callirhoe/__main__.py mv resources.py _callirhoe/lib From b0deb9523f10030a667cbf3a512b218c71e79119 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 17:01:56 +0000 Subject: [PATCH 21/71] Changed make_resource_list as George suggested. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@182 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_resources_list | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/make_resources_list b/make_resources_list index 60ba466..2c84768 100755 --- a/make_resources_list +++ b/make_resources_list @@ -1,15 +1,13 @@ #!/usr/bin/env python2 import glob -lang = glob.glob('lang/*.py') -style = glob.glob('style/*.py') -layouts = glob.glob('layouts/*.py') -geom = glob.glob('geom/*.py') +res = dict() + +for x in ['lang', 'style', 'layouts', 'geom']: + res[x] = glob.glob('%s/*.py' % x) out = open('resources.py', 'w') -out.write('resource_list = { ') -out.write('"lang" : ' + str(lang) + ', ') -out.write('"style" : ' + str(style)+ ', ') -out.write('"layouts" : ' + str(layouts) + ', ') -out.write('"geom" :' + str(geom) + ' }') -out.close() + +for x in res.keys(): + out.write('resources_list["%s"] = %s\n' % (x, str(res[x]))) +out.close() \ No newline at end of file From 9be9c2e1854e79e264a9eabfc1e30bd2dbbb3060 Mon Sep 17 00:00:00 2001 From: "geortz@gmail.com" Date: Fri, 31 Oct 2014 17:39:36 +0000 Subject: [PATCH 22/71] moved common funcs version number git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@183 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- callirhoe.py | 123 ++++-------------------------------------------- calmagick.py | 26 +++++----- lib/__init__.py | 108 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 127 deletions(-) diff --git a/callirhoe.py b/callirhoe.py index 9ad58bb..94aabb2 100755 --- a/callirhoe.py +++ b/callirhoe.py @@ -44,21 +44,13 @@ # CANNOT UPGRADE TO argparse !!! -- how to handle [[month] year] form? -_version = "0.4.0" -_copyright = """Copyright (C) 2012-2014 George M. Tzoumas -License GPLv3+: GNU GPL version 3 or later -This is free software: you are free to change and redistribute it. -There is NO WARRANTY, to the extent permitted by law.""" - import calendar import sys import time import optparse import lib.xcairo as xcairo import lib.holiday as holiday - -class Abort(Exception): - pass +import lib from lib.plugin import * # TODO: SEE IF IT CAN BE MOVED INTO lib.plugin ... @@ -140,103 +132,6 @@ def add_list_option(parser, opt): parser.add_option("--list-%s" % opt, action="store_true", dest="list_%s" % opt, default=False, help="list available %s" % opt) -def atoi(s, lower_bound=None, upper_bound=None, prefix=''): - """convert string to integer, exiting on error (for cmdline parsing) - - @param lower_bound: perform additional check so that value >= I{lower_bound} - @param upper_bound: perform additional check so that value <= I{upper_bound} - @param prefix: output prefix for error reporting - @rtype: int - """ - try: - k = int(s); - if lower_bound is not None: - if k < lower_bound: - raise Abort(prefix + "value '" + s +"' out of range: should not be less than %d" % lower_bound) - if upper_bound is not None: - if k > upper_bound: - raise Abort(prefix + "value '" + s +"' out of range: should not be greater than %d" % upper_bound) - except ValueError as e: - raise Abort(prefix + "invalid integer value '" + s +"'") - return k - -def _parse_month(mstr): - """get a month value (0-12) from I{mstr}, exiting on error (for cmdline parsing) - - @rtype: int - """ - m = atoi(mstr,lower_bound=0,upper_bound=12,prefix='month: ') - if m == 0: m = time.localtime()[1] - return m - -def parse_month_range(s): - """return (Month,Span) by parsing range I{Month}, I{Month1}-I{Month2} or I{Month}:I{Span} - - @rtype: (int,int) - """ - if ':' in s: - t = s.split(':') - if len(t) != 2: raise Abort("invalid month range '" + s + "'") - Month = _parse_month(t[0]) - MonthSpan = atoi(t[1],lower_bound=0,prefix='month span: ') - elif '-' in s: - t = s.split('-') - if len(t) != 2: raise Abort("invalid month range '" + s + "'") - Month = _parse_month(t[0]) - MonthSpan = atoi(t[1],lower_bound=Month+1,prefix='month range: ') - Month + 1 - else: - Month = _parse_month(s) - MonthSpan = 1 - return (Month,MonthSpan) - -def parse_year(ystr): - """get a year value (>=0) from I{ystr}, exiting on error (for cmdline parsing) - - @rtype: int - """ - y = atoi(ystr,lower_bound=0,prefix='year: ') - if y == 0: y = time.localtime()[0] - return y - -def extract_parser_args(arglist, parser, pos = -1): - """extract options belonging to I{parser} along with I{pos} positional arguments - - @param arglist: argument list to extract - @param parser: parser object to be used for extracting - @param pos: number of positional options to be extracted - - if I{pos}<0 then all positional arguments are extracted, otherwise, - only I{pos} arguments are extracted. arglist[0] (usually sys.argv[0]) is also positional - argument! - - @rtype: ([str,...],[str,...]) - @return: tuple (argv1,argv2) with extracted argument list and remaining argument list - """ - argv = [[],[]] - posc = 0 - push_value = None - for x in arglist: - if push_value: - push_value.append(x) - push_value = None - continue - # get option name (long options stop at '=') - y = x[0:x.find('=')] if '=' in x else x - if x[0] == '-': - if parser.has_option(y): - argv[0].append(x) - if not x.startswith('--') and parser.get_option(y).takes_value(): - push_value = argv[0] - else: - argv[1].append(x) - else: - if pos < 0: - argv[0].append(x) - else: - argv[posc >= pos].append(x) - posc += 1 - return tuple(argv) - def get_parser(): """get the argument parser object @@ -247,7 +142,7 @@ def get_parser(): "By default, a calendar of the current year in pdf format is written to FILE. " "Alternatively, you can select a specific YEAR (0=current), " "and a month range from MONTH (0-12, 0=current) to MONTH2 or for SPAN months.", - version="callirhoe " + _version + '\n' + _copyright) + version="callirhoe " + lib._version + '\n' + lib._copyright) parser.add_option("-l", "--lang", dest="lang", default="EN", help="choose language [%default]") parser.add_option("-t", "--layout", dest="layout", default="classic", @@ -293,7 +188,7 @@ def get_parser(): def main_program(): parser = get_parser() - sys.argv,argv2 = extract_parser_args(sys.argv,parser) + sys.argv,argv2 = lib.extract_parser_args(sys.argv,parser) (options,args) = parser.parse_args() list_and_exit = False @@ -364,16 +259,16 @@ def main_program(): Month, MonthSpan = 1, 12 Outfile = args[0] elif len(args) == 2: - Year = parse_year(args[0]) + Year = lib.parse_year(args[0]) Month, MonthSpan = 1, 12 Outfile = args[1] elif len(args) == 3: - Month, MonthSpan = parse_month_range(args[0]) - Year = parse_year(args[1]) + Month, MonthSpan = lib.parse_month_range(args[0]) + Year = lib.parse_year(args[1]) Outfile = args[2] if MonthSpan == 0: - raise Abort("callirhoe: empty calendar requested, aborting") + raise lib.Abort("callirhoe: empty calendar requested, aborting") Geometry.landscape = options.landscape xcairo.XDPI = options.dpi @@ -399,11 +294,11 @@ def main_program(): Language.month_name = Language.long_month_name renderer = Layout.CalendarRenderer(Outfile, Year, Month, MonthSpan, - (Style,Geometry,Language), hprovider, _version, loptions) + (Style,Geometry,Language), hprovider, lib._version, loptions) renderer.render() if __name__ == "__main__": try: main_program() - except Abort as e: + except lib.Abort as e: sys.exit(e.args[0]) diff --git a/calmagick.py b/calmagick.py index 38d1485..ae791e5 100755 --- a/calmagick.py +++ b/calmagick.py @@ -34,7 +34,7 @@ import optparse import Queue import threading -from callirhoe import extract_parser_args, parse_month_range, parse_year, atoi, Abort, _version, _copyright +import lib from lib.geom import rect_rel_scale # MAYBE-TODO @@ -198,7 +198,7 @@ def get_parser(): If IMAGE is a single file, then a calendar of the current month is overlayed. If IMAGE contains wildcards, then every month is generated according to the --range option, advancing one month for every photo file. Photos will be reused in a round-robin fashion if more calendar -months are requested.""", version="callirhoe.CalMagick " + _version + '\n' + _copyright) +months are requested.""", version="callirhoe.CalMagick " + lib._version + '\n' + lib._copyright) parser.add_option("--outdir", default=".", help="set directory for the output image(s); directory will be created if it does not already exist [%default]") parser.add_option("--outfile", default=None, @@ -300,11 +300,11 @@ def check_parsed_options(options): if options.min_size is None: options.min_size = 0.333 if options.placement in ['min','max','random'] else 0.05 if options.sample is not None and not options.range: - raise Abort("calmagick: --sample requested without --range") + raise lib.Abort("calmagick: --sample requested without --range") if options.outfile is not None and options.range: - raise Abort("calmagick: you cannot specify both --outfile and --range options") + raise lib.Abort("calmagick: you cannot specify both --outfile and --range options") if options.sample is not None and options.shuffle: - raise Abort("calmagick: you cannot specify both --shuffle and --sample options") + raise lib.Abort("calmagick: you cannot specify both --shuffle and --sample options") if options.shuffle: options.sample = 0 if options.sample is None: @@ -370,7 +370,7 @@ def get_outfile(infile, outdir, base_prefix, format, hint=None): if format: ext = '.' + format outfile = os.path.join(outdir,base_prefix+base+ext) if os.path.exists(outfile) and os.path.samefile(infile, outfile): - if hint: raise Abort("calmagick: --outfile same as input, aborting") + if hint: raise lib.Abort("calmagick: --outfile same as input, aborting") outfile = os.path.join(outdir,base_prefix+base+'_calmagick'+ext) return outfile @@ -523,7 +523,7 @@ def compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=No if '/' in options.ratio: tmp = options.ratio.split('/') - calratio = float(atoi(tmp[0],1))/atoi(tmp[1],1) + calratio = float(lib.atoi(tmp[0],1))/lib.atoi(tmp[1],1) else: calratio = float(options.ratio) if options.placement == 'min' or options.placement == 'max': @@ -596,9 +596,9 @@ def parse_range(s,hint=None): """ if '/' in s: t = s.split('/') - month,span = parse_month_range(t[0]) + month,span = lib.parse_month_range(t[0]) if hint and span == 0: span = hint - year = parse_year(t[1]) + year = lib.parse_year(t[1]) margs = [] for m in xrange(span): margs += [(month,year)] @@ -606,7 +606,7 @@ def parse_range(s,hint=None): if month > 12: month = 1; year += 1 return margs else: - raise Abort("calmagick: invalid range format '%s'" % options.range) + raise lib.Abort("calmagick: invalid range format '%s'" % options.range) def range_worker(q,ev,i): """worker thread for a (I{Month,Year}) tuple @@ -638,7 +638,7 @@ def main_program(): parser = get_parser() magick_args = parse_magick_args() - sys.argv,argv2 = extract_parser_args(sys.argv,parser,2) + sys.argv,argv2 = lib.extract_parser_args(sys.argv,parser,2) (options,args) = parser.parse_args() check_parsed_options(options) @@ -682,12 +682,12 @@ def main_program(): else: img = args[0] if not os.path.isfile(img): - raise Abort("calmagick: input image '%s' does not exist" % img) + raise lib.Abort("calmagick: input image '%s' does not exist" % img) outimg = get_outfile(img,options.outdir,'',options.format,options.outfile) compose_calendar(img, outimg, options, argv2, magick_args) if __name__ == '__main__': try: main_program() - except Abort as e: + except lib.Abort as e: sys.exit(e.args[0]) diff --git a/lib/__init__.py b/lib/__init__.py index e69de29..1f32408 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -0,0 +1,108 @@ +import time + +_version = "0.4.1" +_copyright = """Copyright (C) 2012-2014 George M. Tzoumas +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law.""" + +class Abort(Exception): + pass + +def extract_parser_args(arglist, parser, pos = -1): + """extract options belonging to I{parser} along with I{pos} positional arguments + + @param arglist: argument list to extract + @param parser: parser object to be used for extracting + @param pos: number of positional options to be extracted + + if I{pos}<0 then all positional arguments are extracted, otherwise, + only I{pos} arguments are extracted. arglist[0] (usually sys.argv[0]) is also positional + argument! + + @rtype: ([str,...],[str,...]) + @return: tuple (argv1,argv2) with extracted argument list and remaining argument list + """ + argv = [[],[]] + posc = 0 + push_value = None + for x in arglist: + if push_value: + push_value.append(x) + push_value = None + continue + # get option name (long options stop at '=') + y = x[0:x.find('=')] if '=' in x else x + if x[0] == '-': + if parser.has_option(y): + argv[0].append(x) + if not x.startswith('--') and parser.get_option(y).takes_value(): + push_value = argv[0] + else: + argv[1].append(x) + else: + if pos < 0: + argv[0].append(x) + else: + argv[posc >= pos].append(x) + posc += 1 + return tuple(argv) + +def atoi(s, lower_bound=None, upper_bound=None, prefix=''): + """convert string to integer, exiting on error (for cmdline parsing) + + @param lower_bound: perform additional check so that value >= I{lower_bound} + @param upper_bound: perform additional check so that value <= I{upper_bound} + @param prefix: output prefix for error reporting + @rtype: int + """ + try: + k = int(s); + if lower_bound is not None: + if k < lower_bound: + raise Abort(prefix + "value '" + s +"' out of range: should not be less than %d" % lower_bound) + if upper_bound is not None: + if k > upper_bound: + raise Abort(prefix + "value '" + s +"' out of range: should not be greater than %d" % upper_bound) + except ValueError as e: + raise Abort(prefix + "invalid integer value '" + s +"'") + return k + +def _parse_month(mstr): + """get a month value (0-12) from I{mstr}, exiting on error (for cmdline parsing) + + @rtype: int + """ + m = atoi(mstr,lower_bound=0,upper_bound=12,prefix='month: ') + if m == 0: m = time.localtime()[1] + return m + +def parse_month_range(s): + """return (Month,Span) by parsing range I{Month}, I{Month1}-I{Month2} or I{Month}:I{Span} + + @rtype: (int,int) + """ + if ':' in s: + t = s.split(':') + if len(t) != 2: raise Abort("invalid month range '" + s + "'") + Month = _parse_month(t[0]) + MonthSpan = atoi(t[1],lower_bound=0,prefix='month span: ') + elif '-' in s: + t = s.split('-') + if len(t) != 2: raise Abort("invalid month range '" + s + "'") + Month = _parse_month(t[0]) + MonthSpan = atoi(t[1],lower_bound=Month+1,prefix='month range: ') - Month + 1 + else: + Month = _parse_month(s) + MonthSpan = 1 + return (Month,MonthSpan) + +def parse_year(ystr): + """get a year value (>=0) from I{ystr}, exiting on error (for cmdline parsing) + + @rtype: int + """ + y = atoi(ystr,lower_bound=0,prefix='year: ') + if y == 0: y = time.localtime()[0] + return y + From 05fc2b89d843566e42d6a5a92840c7117ba10bea Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 21:12:41 +0000 Subject: [PATCH 23/71] Work on make_pkg script git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@184 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/make_pkg b/make_pkg index 9700886..ff4dba4 100755 --- a/make_pkg +++ b/make_pkg @@ -33,6 +33,6 @@ rm calmagick.zip # Create Makefile echo install: > Makefile -echo install -m 0755 callirhoe "$""(prefix)"/bin >> Makefile -echo install -m 0755 calmagick "$""(prefix)"/bin >> Makefile -find holidays/ | sed 's/^/ install -m 644 /' | sed 's/$/ \$(prefix)\/share\/callirhoe/' >> Makefile \ No newline at end of file +echo " install -m 0755 callirhoe" "$""(prefix)/bin" >> Makefile +echo " install -m 0755 calmagick" "$""(prefix)/bin" >> Makefile +find holidays/* -printf " install -m 644 %p \$(prefix)/share/callirhoe\n" >> Makefile \ No newline at end of file From a3c19685abd3d21a0c585b13681100d1a676771d Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 21:14:24 +0000 Subject: [PATCH 24/71] Work on make_pkg git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@185 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/make_pkg b/make_pkg index ff4dba4..babf6d0 100755 --- a/make_pkg +++ b/make_pkg @@ -3,7 +3,7 @@ # Create Callirhoe package mkdir _callirhoe ./make_resources_list -cp -R geom holidays lang layouts lib style _callirhoe +cp -R geom lang layouts lib style _callirhoe cp callirhoe.py _callirhoe/__main__.py mv resources.py _callirhoe/lib @@ -18,7 +18,7 @@ rm callirhoe.zip # Create Calmagick package mkdir _calmagick -cp -R geom holidays lang layouts lib style _calmagick +cp -R geom lib _calmagick cp callirhoe.py _calmagick cp calmagick.py _calmagick/__main__.py From 3a6e54e8e832c572dc1479f02f868590bd83db3a Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 21:33:08 +0000 Subject: [PATCH 25/71] Fixin stuff in make_pkg git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@186 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 12 ++---------- make_resources_list | 1 + 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/make_pkg b/make_pkg index babf6d0..211dbad 100755 --- a/make_pkg +++ b/make_pkg @@ -7,11 +7,7 @@ cp -R geom lang layouts lib style _callirhoe cp callirhoe.py _callirhoe/__main__.py mv resources.py _callirhoe/lib -cd _callirhoe -zip -q -r callirhoe.zip * -mv callirhoe.zip ../ -cd .. -rm -rf _callirhoe +cd _callirhoe && zip -q -r callirhoe.zip * && mv callirhoe.zip ../ && cd .. && rm -rf _callirhoe echo \#!/usr/bin/env python2 | cat - callirhoe.zip > callirhoe chmod 755 callirhoe rm callirhoe.zip @@ -22,11 +18,7 @@ cp -R geom lib _calmagick cp callirhoe.py _calmagick cp calmagick.py _calmagick/__main__.py -cd _calmagick -zip -q -r calmagick.zip * -mv calmagick.zip ../ -cd .. -rm -rf _calmagick +cd _calmagick && zip -q -r calmagick.zip * && mv calmagick.zip ../ && cd .. && rm -rf _calmagick echo \#!/usr/bin/env python2 | cat - calmagick.zip > calmagick chmod 755 calmagick rm calmagick.zip diff --git a/make_resources_list b/make_resources_list index 2c84768..d35b8d5 100755 --- a/make_resources_list +++ b/make_resources_list @@ -10,4 +10,5 @@ out = open('resources.py', 'w') for x in res.keys(): out.write('resources_list["%s"] = %s\n' % (x, str(res[x]))) + out.close() \ No newline at end of file From 04ac928a31797fb3c99eb0c6c1c3d7aeac467dd1 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 22:17:49 +0000 Subject: [PATCH 26/71] Working on make_pkg, added here docs, cause ppl like them :D git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@187 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/make_pkg b/make_pkg index 211dbad..1d7f159 100755 --- a/make_pkg +++ b/make_pkg @@ -24,7 +24,12 @@ chmod 755 calmagick rm calmagick.zip # Create Makefile -echo install: > Makefile -echo " install -m 0755 callirhoe" "$""(prefix)/bin" >> Makefile -echo " install -m 0755 calmagick" "$""(prefix)/bin" >> Makefile +cat << END > Makefile +prefix=/usr + +install: callrhoe + install -m 0755 callirhoe \$(prefix)/bin + install -m 0755 calmagick \$(prefix)/bin +END + find holidays/* -printf " install -m 644 %p \$(prefix)/share/callirhoe\n" >> Makefile \ No newline at end of file From ffdc2ac289202a6082c65fc5e7bbaa318133dbc2 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 22:26:54 +0000 Subject: [PATCH 27/71] Dealing with tabs in makefile git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@188 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/make_pkg b/make_pkg index 1d7f159..a98974f 100755 --- a/make_pkg +++ b/make_pkg @@ -28,8 +28,8 @@ cat << END > Makefile prefix=/usr install: callrhoe - install -m 0755 callirhoe \$(prefix)/bin - install -m 0755 calmagick \$(prefix)/bin + install -m 0755 callirhoe \$(prefix)/bin + install -m 0755 calmagick \$(prefix)/bin END -find holidays/* -printf " install -m 644 %p \$(prefix)/share/callirhoe\n" >> Makefile \ No newline at end of file +find holidays/* -printf "\tinstall -m 644 %p \$(prefix)/share/callirhoe\n" >> Makefile \ No newline at end of file From 459795fff7eed6ff958341b0f66070c58081959d Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 22:28:48 +0000 Subject: [PATCH 28/71] Makefile is stubborn with tabs... git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@189 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/make_pkg b/make_pkg index a98974f..ed209a8 100755 --- a/make_pkg +++ b/make_pkg @@ -28,8 +28,8 @@ cat << END > Makefile prefix=/usr install: callrhoe - install -m 0755 callirhoe \$(prefix)/bin - install -m 0755 calmagick \$(prefix)/bin + install -m 0755 callirhoe \$(prefix)/bin + install -m 0755 calmagick \$(prefix)/bin END find holidays/* -printf "\tinstall -m 644 %p \$(prefix)/share/callirhoe\n" >> Makefile \ No newline at end of file From 7b2a2126f3bb5040487698abb59bcc4fb4bf44ac Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 22:29:36 +0000 Subject: [PATCH 29/71] fighting with makefile git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@190 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make_pkg b/make_pkg index ed209a8..ec89547 100755 --- a/make_pkg +++ b/make_pkg @@ -27,7 +27,7 @@ rm calmagick.zip cat << END > Makefile prefix=/usr -install: callrhoe +install: install -m 0755 callirhoe \$(prefix)/bin install -m 0755 calmagick \$(prefix)/bin END From 04a9d7b462972475d299751ebefdc588448c5585 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 22:34:58 +0000 Subject: [PATCH 30/71] Tabs fixed. Working on destdir jail. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@191 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/make_pkg b/make_pkg index ec89547..8034510 100755 --- a/make_pkg +++ b/make_pkg @@ -28,8 +28,8 @@ cat << END > Makefile prefix=/usr install: - install -m 0755 callirhoe \$(prefix)/bin - install -m 0755 calmagick \$(prefix)/bin + install -m 0755 callirhoe \$(DESTDIR)/bin + install -m 0755 calmagick \$(DESTDIR)/bin END find holidays/* -printf "\tinstall -m 644 %p \$(prefix)/share/callirhoe\n" >> Makefile \ No newline at end of file From fbb60177b1dd8a4d6aad7ef261f2a2fbeeda7aae Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 22:41:29 +0000 Subject: [PATCH 31/71] Changed from prefix to destdir, seems to be the correct way to do it. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@192 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make_pkg b/make_pkg index 8034510..086c9e7 100755 --- a/make_pkg +++ b/make_pkg @@ -32,4 +32,4 @@ install: install -m 0755 calmagick \$(DESTDIR)/bin END -find holidays/* -printf "\tinstall -m 644 %p \$(prefix)/share/callirhoe\n" >> Makefile \ No newline at end of file +find holidays/* -printf "\tinstall -m 644 %p \$(DESTDIR)/share/callirhoe\n" >> Makefile \ No newline at end of file From 25c1096f8220693219a8bda94426f0d73a960b67 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 22:44:42 +0000 Subject: [PATCH 32/71] The pain of "/"s ... git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@193 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/make_pkg b/make_pkg index 086c9e7..95e1722 100755 --- a/make_pkg +++ b/make_pkg @@ -28,8 +28,8 @@ cat << END > Makefile prefix=/usr install: - install -m 0755 callirhoe \$(DESTDIR)/bin - install -m 0755 calmagick \$(DESTDIR)/bin + install -m 0755 callirhoe \$(DESTDIR)/bin/ + install -m 0755 calmagick \$(DESTDIR)/bin/ END -find holidays/* -printf "\tinstall -m 644 %p \$(DESTDIR)/share/callirhoe\n" >> Makefile \ No newline at end of file +find holidays/* -printf "\tinstall -m 644 %p \$(DESTDIR)/share/callirhoe/\n" >> Makefile \ No newline at end of file From 94e52e09b945b1b8e4abf4347a6f98ca7bc2dc1e Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 22:47:48 +0000 Subject: [PATCH 33/71] install works a bit differently than I expected git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@194 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/make_pkg b/make_pkg index 95e1722..fda8546 100755 --- a/make_pkg +++ b/make_pkg @@ -28,8 +28,8 @@ cat << END > Makefile prefix=/usr install: - install -m 0755 callirhoe \$(DESTDIR)/bin/ - install -m 0755 calmagick \$(DESTDIR)/bin/ + install -m 0755 callirhoe \$(DESTDIR)/bin/callirhoe + install -m 0755 calmagick \$(DESTDIR)/bin/calmagick END -find holidays/* -printf "\tinstall -m 644 %p \$(DESTDIR)/share/callirhoe/\n" >> Makefile \ No newline at end of file +find holidays/* -printf "\tinstall -m 644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile \ No newline at end of file From fc69eafe7e67d559a07475463b77d0d71cc7f67d Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 22:51:31 +0000 Subject: [PATCH 34/71] RTFM (about install) git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@195 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/make_pkg b/make_pkg index fda8546..ded9d61 100755 --- a/make_pkg +++ b/make_pkg @@ -28,8 +28,8 @@ cat << END > Makefile prefix=/usr install: - install -m 0755 callirhoe \$(DESTDIR)/bin/callirhoe - install -m 0755 calmagick \$(DESTDIR)/bin/calmagick + install -Dm755 callirhoe \$(DESTDIR)/bin/callirhoe + install -Dm755 calmagick \$(DESTDIR)/bin/calmagick END -find holidays/* -printf "\tinstall -m 644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile \ No newline at end of file +find holidays/* -printf "\tinstall -Dm644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile \ No newline at end of file From e158dfa2db8a3ecaaa510b2befd69ebb5c3e9d36 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 22:57:59 +0000 Subject: [PATCH 35/71] Added me to AUTHORS, added PKGBUILD. This is a working PKGBUILD for Arch Linux. I haven't uploaded it yet to AUR. I will upload it in some hours, want to test it first. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@196 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- AUTHORS | 2 +- PKGBUILD | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 PKGBUILD diff --git a/AUTHORS b/AUTHORS index fcc5e4e..877355e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,7 +12,7 @@ George M. Tzoumas CONTRIBUTORS ------------ Neels Hofmeyr - +Nick Kavalieris LANGUAGE DEFINITIONS -------------------- diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..f419735 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,30 @@ +# Author : George Tzoumas +# Maintainer: Nick Kavalieris +# For contributors check the AUTHORS file +pkgname=callirhoe +pkgver=195 +pkgrel=1 +pkgdesc="PDF Calendar creator with high quality vector graphics" +url="https://code.google.com/p/callirhoe/" +arch=('any') +license=('GPLv3') +depends=('python2' 'imagemagick' 'python2-cairo' 'subversion') +source=("$pkgname::svn+https://callirhoe.googlecode.com/svn/branches/phantome") +md5sums=('SKIP') + + +pkgver() { + cd "$pkgname" + svnversion | tr -d [A-z] | sed 's/ *//g' +} + +build() { + cd "${srcdir}/${pkgname}" + ./make_pkg +} + +package() { + cd "${srcdir}/${pkgname}" + install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING" + make DESTDIR="$pkgdir/usr" install +} \ No newline at end of file From e1aad0b2217de6d02db7192fdc0d9bbafe8aff92 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 23:19:41 +0000 Subject: [PATCH 36/71] Just fixed the reason that broke the program. It was the script that creates the resource_list. There was a typo "resoures_list" ... git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@197 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_resources_list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make_resources_list b/make_resources_list index d35b8d5..f24f340 100755 --- a/make_resources_list +++ b/make_resources_list @@ -9,6 +9,6 @@ for x in ['lang', 'style', 'layouts', 'geom']: out = open('resources.py', 'w') for x in res.keys(): - out.write('resources_list["%s"] = %s\n' % (x, str(res[x]))) + out.write('resource_list["%s"] = %s\n' % (x, str(res[x]))) out.close() \ No newline at end of file From e1ed041a19463d9f4b5f0f4f601043c906b27a8f Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 23:24:39 +0000 Subject: [PATCH 37/71] There were more than one mistakes. The second were that I tried to insert data to a dict that were never created. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@198 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_resources_list | 1 + 1 file changed, 1 insertion(+) diff --git a/make_resources_list b/make_resources_list index f24f340..94b5275 100755 --- a/make_resources_list +++ b/make_resources_list @@ -8,6 +8,7 @@ for x in ['lang', 'style', 'layouts', 'geom']: out = open('resources.py', 'w') +out.write('resource_list = {}') for x in res.keys(): out.write('resource_list["%s"] = %s\n' % (x, str(res[x]))) From 5370e100f79ca854da637f187af47f30af5e3e8d Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Fri, 31 Oct 2014 23:26:37 +0000 Subject: [PATCH 38/71] Fixed a missing "\n". git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@199 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_resources_list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make_resources_list b/make_resources_list index 94b5275..e9a8c0a 100755 --- a/make_resources_list +++ b/make_resources_list @@ -8,7 +8,7 @@ for x in ['lang', 'style', 'layouts', 'geom']: out = open('resources.py', 'w') -out.write('resource_list = {}') +out.write('resource_list = {}\n') for x in res.keys(): out.write('resource_list["%s"] = %s\n' % (x, str(res[x]))) From d7446bde8aa18ec85a6c65c5b971884b6913a920 Mon Sep 17 00:00:00 2001 From: "geortz@gmail.com" Date: Sat, 1 Nov 2014 18:09:18 +0000 Subject: [PATCH 39/71] proposed new version of scripts: using mktemp for temp dir fixed deps for calmagick writing to stdout in make_resources_list git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@200 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg.new | 44 +++++++++++++++++++++++++++++++++++++++++ make_resources_list.new | 11 +++++++++++ 2 files changed, 55 insertions(+) create mode 100755 make_pkg.new create mode 100755 make_resources_list.new diff --git a/make_pkg.new b/make_pkg.new new file mode 100755 index 0000000..05b452c --- /dev/null +++ b/make_pkg.new @@ -0,0 +1,44 @@ +#!/bin/bash +set -e + +make_archive() { + base="$1" + tempdir="$2" + curdir=`pwd` + cd $tempdir + zip -q -r $curdir/$base.zip * + cd $curdir + rm -rf $tempdir + echo '#!/usr/bin/env python2.7' | cat - $base.zip > $base + chmod 755 $base + rm -f $base.zip +} + + +# Create Callirhoe package +DIR=`mktemp -d -t callirhoe` +# TODO: do we need .pyc files? (my guess is yes, how do we force creation?) +cp -R geom lang layouts lib style "$DIR" +cp callirhoe.py "$DIR/__main__.py" +./make_resources_list > "$DIR/lib/resources.py" + +make_archive callirhoe "$DIR" + +# Create Calmagick package +DIR=`mktemp -d -t callirhoe` +mkdir "$DIR/lib" +cp lib/__init__.py lib/geom.py "$DIR/lib" +cp calmagick.py "$DIR/__main__.py" + +make_archive calmagick "$DIR" + +# Create Makefile +cat << END > Makefile +prefix=/usr + +install: + install -Dm755 callirhoe \$(DESTDIR)/bin/callirhoe + install -Dm755 calmagick \$(DESTDIR)/bin/calmagick +END + +find holidays/* -printf "\tinstall -Dm644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile diff --git a/make_resources_list.new b/make_resources_list.new new file mode 100755 index 0000000..1b17b1d --- /dev/null +++ b/make_resources_list.new @@ -0,0 +1,11 @@ +#!/usr/bin/env python2.7 +import glob + +res = dict() + +for x in ['lang', 'style', 'layouts', 'geom']: + res[x] = glob.glob('%s/*.py' % x) + +print 'resource_list = {}' +for x in res.keys(): + print 'resource_list["%s"] = %s' % (x, str(res[x])) From f8af3a09a9694bfa624c836a09bf9c22937c93d8 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Sat, 1 Nov 2014 22:16:44 +0000 Subject: [PATCH 40/71] Fixed the default interpreter issue. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@201 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 45 ++++++++++++++++++++++++----------------- make_pkg.new | 44 ---------------------------------------- make_resources_list | 10 +++------ make_resources_list.new | 11 ---------- 4 files changed, 30 insertions(+), 80 deletions(-) delete mode 100755 make_pkg.new delete mode 100755 make_resources_list.new diff --git a/make_pkg b/make_pkg index ded9d61..05b452c 100755 --- a/make_pkg +++ b/make_pkg @@ -1,27 +1,36 @@ #!/bin/bash +set -e + +make_archive() { + base="$1" + tempdir="$2" + curdir=`pwd` + cd $tempdir + zip -q -r $curdir/$base.zip * + cd $curdir + rm -rf $tempdir + echo '#!/usr/bin/env python2.7' | cat - $base.zip > $base + chmod 755 $base + rm -f $base.zip +} + # Create Callirhoe package -mkdir _callirhoe -./make_resources_list -cp -R geom lang layouts lib style _callirhoe -cp callirhoe.py _callirhoe/__main__.py -mv resources.py _callirhoe/lib +DIR=`mktemp -d -t callirhoe` +# TODO: do we need .pyc files? (my guess is yes, how do we force creation?) +cp -R geom lang layouts lib style "$DIR" +cp callirhoe.py "$DIR/__main__.py" +./make_resources_list > "$DIR/lib/resources.py" -cd _callirhoe && zip -q -r callirhoe.zip * && mv callirhoe.zip ../ && cd .. && rm -rf _callirhoe -echo \#!/usr/bin/env python2 | cat - callirhoe.zip > callirhoe -chmod 755 callirhoe -rm callirhoe.zip +make_archive callirhoe "$DIR" # Create Calmagick package -mkdir _calmagick -cp -R geom lib _calmagick -cp callirhoe.py _calmagick -cp calmagick.py _calmagick/__main__.py +DIR=`mktemp -d -t callirhoe` +mkdir "$DIR/lib" +cp lib/__init__.py lib/geom.py "$DIR/lib" +cp calmagick.py "$DIR/__main__.py" -cd _calmagick && zip -q -r calmagick.zip * && mv calmagick.zip ../ && cd .. && rm -rf _calmagick -echo \#!/usr/bin/env python2 | cat - calmagick.zip > calmagick -chmod 755 calmagick -rm calmagick.zip +make_archive calmagick "$DIR" # Create Makefile cat << END > Makefile @@ -32,4 +41,4 @@ install: install -Dm755 calmagick \$(DESTDIR)/bin/calmagick END -find holidays/* -printf "\tinstall -Dm644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile \ No newline at end of file +find holidays/* -printf "\tinstall -Dm644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile diff --git a/make_pkg.new b/make_pkg.new deleted file mode 100755 index 05b452c..0000000 --- a/make_pkg.new +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -set -e - -make_archive() { - base="$1" - tempdir="$2" - curdir=`pwd` - cd $tempdir - zip -q -r $curdir/$base.zip * - cd $curdir - rm -rf $tempdir - echo '#!/usr/bin/env python2.7' | cat - $base.zip > $base - chmod 755 $base - rm -f $base.zip -} - - -# Create Callirhoe package -DIR=`mktemp -d -t callirhoe` -# TODO: do we need .pyc files? (my guess is yes, how do we force creation?) -cp -R geom lang layouts lib style "$DIR" -cp callirhoe.py "$DIR/__main__.py" -./make_resources_list > "$DIR/lib/resources.py" - -make_archive callirhoe "$DIR" - -# Create Calmagick package -DIR=`mktemp -d -t callirhoe` -mkdir "$DIR/lib" -cp lib/__init__.py lib/geom.py "$DIR/lib" -cp calmagick.py "$DIR/__main__.py" - -make_archive calmagick "$DIR" - -# Create Makefile -cat << END > Makefile -prefix=/usr - -install: - install -Dm755 callirhoe \$(DESTDIR)/bin/callirhoe - install -Dm755 calmagick \$(DESTDIR)/bin/calmagick -END - -find holidays/* -printf "\tinstall -Dm644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile diff --git a/make_resources_list b/make_resources_list index e9a8c0a..1b17b1d 100755 --- a/make_resources_list +++ b/make_resources_list @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python2.7 import glob res = dict() @@ -6,10 +6,6 @@ res = dict() for x in ['lang', 'style', 'layouts', 'geom']: res[x] = glob.glob('%s/*.py' % x) -out = open('resources.py', 'w') - -out.write('resource_list = {}\n') +print 'resource_list = {}' for x in res.keys(): - out.write('resource_list["%s"] = %s\n' % (x, str(res[x]))) - -out.close() \ No newline at end of file + print 'resource_list["%s"] = %s' % (x, str(res[x])) diff --git a/make_resources_list.new b/make_resources_list.new deleted file mode 100755 index 1b17b1d..0000000 --- a/make_resources_list.new +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python2.7 -import glob - -res = dict() - -for x in ['lang', 'style', 'layouts', 'geom']: - res[x] = glob.glob('%s/*.py' % x) - -print 'resource_list = {}' -for x in res.keys(): - print 'resource_list["%s"] = %s' % (x, str(res[x])) From c3dc09db4e3197f5461f9a5abd01bb91e28aa99f Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Sat, 1 Nov 2014 22:26:56 +0000 Subject: [PATCH 41/71] Fixed mktemp templates git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@202 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/make_pkg b/make_pkg index 05b452c..3c20dd4 100755 --- a/make_pkg +++ b/make_pkg @@ -16,7 +16,9 @@ make_archive() { # Create Callirhoe package -DIR=`mktemp -d -t callirhoe` +echo "here" +DIR=`mktemp -d -t callirhoe.XXX` +echo "there" # TODO: do we need .pyc files? (my guess is yes, how do we force creation?) cp -R geom lang layouts lib style "$DIR" cp callirhoe.py "$DIR/__main__.py" @@ -25,7 +27,7 @@ cp callirhoe.py "$DIR/__main__.py" make_archive callirhoe "$DIR" # Create Calmagick package -DIR=`mktemp -d -t callirhoe` +DIR=`mktemp -d -t callirhoe.XXX` mkdir "$DIR/lib" cp lib/__init__.py lib/geom.py "$DIR/lib" cp calmagick.py "$DIR/__main__.py" From 1a53b5e4d88d17629e5ca15782d0f63bc4ecdac8 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Sat, 1 Nov 2014 22:47:56 +0000 Subject: [PATCH 42/71] zip packages now include .pyc files git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@203 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/make_pkg b/make_pkg index 3c20dd4..33d812c 100755 --- a/make_pkg +++ b/make_pkg @@ -16,14 +16,17 @@ make_archive() { # Create Callirhoe package -echo "here" DIR=`mktemp -d -t callirhoe.XXX` -echo "there" # TODO: do we need .pyc files? (my guess is yes, how do we force creation?) cp -R geom lang layouts lib style "$DIR" cp callirhoe.py "$DIR/__main__.py" ./make_resources_list > "$DIR/lib/resources.py" +for i in `find $DIR -type f -name "*.py" | grep -v "__"` +do + python2.7 -m py_compile $i +done + make_archive callirhoe "$DIR" # Create Calmagick package @@ -32,6 +35,11 @@ mkdir "$DIR/lib" cp lib/__init__.py lib/geom.py "$DIR/lib" cp calmagick.py "$DIR/__main__.py" +for i in `find $DIR -type f -name "*.py" | grep -v "__"` +do + python2.7 -m py_compile $i +done + make_archive calmagick "$DIR" # Create Makefile From 1fb45c2d819db0e75ea7654024f36c0867a5280f Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Sat, 1 Nov 2014 22:53:05 +0000 Subject: [PATCH 43/71] .pyc generation went inside make_archive git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@204 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/make_pkg b/make_pkg index 33d812c..7098930 100755 --- a/make_pkg +++ b/make_pkg @@ -5,6 +5,10 @@ make_archive() { base="$1" tempdir="$2" curdir=`pwd` + for i in `find $tempdir -type f -name "*.py" | grep -v "__"` + do + python2.7 -m py_compile $i + done cd $tempdir zip -q -r $curdir/$base.zip * cd $curdir @@ -17,16 +21,10 @@ make_archive() { # Create Callirhoe package DIR=`mktemp -d -t callirhoe.XXX` -# TODO: do we need .pyc files? (my guess is yes, how do we force creation?) cp -R geom lang layouts lib style "$DIR" cp callirhoe.py "$DIR/__main__.py" ./make_resources_list > "$DIR/lib/resources.py" -for i in `find $DIR -type f -name "*.py" | grep -v "__"` -do - python2.7 -m py_compile $i -done - make_archive callirhoe "$DIR" # Create Calmagick package @@ -35,11 +33,6 @@ mkdir "$DIR/lib" cp lib/__init__.py lib/geom.py "$DIR/lib" cp calmagick.py "$DIR/__main__.py" -for i in `find $DIR -type f -name "*.py" | grep -v "__"` -do - python2.7 -m py_compile $i -done - make_archive calmagick "$DIR" # Create Makefile From 926cf961775168ef115b7b5a36fe0593594f20dd Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Sun, 2 Nov 2014 07:22:00 +0000 Subject: [PATCH 44/71] Now make_pkg includes main script's .pyc too. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@205 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make_pkg b/make_pkg index 7098930..8de4747 100755 --- a/make_pkg +++ b/make_pkg @@ -5,7 +5,7 @@ make_archive() { base="$1" tempdir="$2" curdir=`pwd` - for i in `find $tempdir -type f -name "*.py" | grep -v "__"` + for i in `find $tempdir -type f -name "*.py" | grep -v "__init__"` do python2.7 -m py_compile $i done From 8a1b4f9d74886d0fd02933d7519d979ed74c936b Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Sun, 2 Nov 2014 11:38:01 +0000 Subject: [PATCH 45/71] Only .pyc files are included in the zip package. Since it's "freezed" it doesn't make any sense to include .py files. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@206 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 1 + 1 file changed, 1 insertion(+) diff --git a/make_pkg b/make_pkg index 8de4747..9b191d7 100755 --- a/make_pkg +++ b/make_pkg @@ -8,6 +8,7 @@ make_archive() { for i in `find $tempdir -type f -name "*.py" | grep -v "__init__"` do python2.7 -m py_compile $i + rm $i done cd $tempdir zip -q -r $curdir/$base.zip * From 82becf586c10deeaba34e687f1a37ca9bf8f68da Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Sun, 2 Nov 2014 11:43:02 +0000 Subject: [PATCH 46/71] .svn directories are now removed from the zip archive git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@207 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/make_pkg b/make_pkg index 9b191d7..074c070 100755 --- a/make_pkg +++ b/make_pkg @@ -10,6 +10,10 @@ make_archive() { python2.7 -m py_compile $i rm $i done + for i in `find $tempdir -type d -name ".svn"` + do + rm -rf $i + done cd $tempdir zip -q -r $curdir/$base.zip * cd $curdir From bec999506deed6ef1439707f2f8e3fde9fd46888 Mon Sep 17 00:00:00 2001 From: "geortz@gmail.com" Date: Sun, 2 Nov 2014 15:27:18 +0000 Subject: [PATCH 47/71] proposed changes regarding archiving commands (in comments) git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@208 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/make_pkg b/make_pkg index 074c070..798f70f 100755 --- a/make_pkg +++ b/make_pkg @@ -5,14 +5,16 @@ make_archive() { base="$1" tempdir="$2" curdir=`pwd` - for i in `find $tempdir -type f -name "*.py" | grep -v "__init__"` - do - python2.7 -m py_compile $i - rm $i + for i in `find $tempdir -type f -name "*.py" | grep -v "__init__"`; do + python2.7 -m py_compile $i + rm $i done - for i in `find $tempdir -type d -name ".svn"` - do - rm -rf $i + # if copied with tar, this is not needed anyway: + # find $tempdir -type d -name ".svn" -exec rm -rf '{}' ';' + # or + # rm -rf `find $tempdir -type d -name ".svn"` + for i in `find $tempdir -type d -name ".svn"`; do + rm -rf $i done cd $tempdir zip -q -r $curdir/$base.zip * @@ -26,7 +28,11 @@ make_archive() { # Create Callirhoe package DIR=`mktemp -d -t callirhoe.XXX` +# consider this command to actually copy only *.py, without any .svn/ or other crap +# tar also preserves timestamps by default, dunno if we really need them +#tar c {geom,lang,layouts,lib,style}/*.py | tar x -C "$DIR" cp -R geom lang layouts lib style "$DIR" + cp callirhoe.py "$DIR/__main__.py" ./make_resources_list > "$DIR/lib/resources.py" @@ -34,8 +40,11 @@ make_archive callirhoe "$DIR" # Create Calmagick package DIR=`mktemp -d -t callirhoe.XXX` +#tar c lib/{__init__,geom}.py | tar x -C "$DIR" +# we also avoid using mkdir this way! ;) mkdir "$DIR/lib" cp lib/__init__.py lib/geom.py "$DIR/lib" + cp calmagick.py "$DIR/__main__.py" make_archive calmagick "$DIR" From aed2faa8b6ab4f50a57d108f4e19b0f9df78f6d6 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Mon, 3 Nov 2014 08:36:17 +0000 Subject: [PATCH 48/71] Applied the proposed changes by George to make_pkg git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@209 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/make_pkg b/make_pkg index 798f70f..f8da2e9 100755 --- a/make_pkg +++ b/make_pkg @@ -9,13 +9,6 @@ make_archive() { python2.7 -m py_compile $i rm $i done - # if copied with tar, this is not needed anyway: - # find $tempdir -type d -name ".svn" -exec rm -rf '{}' ';' - # or - # rm -rf `find $tempdir -type d -name ".svn"` - for i in `find $tempdir -type d -name ".svn"`; do - rm -rf $i - done cd $tempdir zip -q -r $curdir/$base.zip * cd $curdir @@ -28,10 +21,7 @@ make_archive() { # Create Callirhoe package DIR=`mktemp -d -t callirhoe.XXX` -# consider this command to actually copy only *.py, without any .svn/ or other crap -# tar also preserves timestamps by default, dunno if we really need them -#tar c {geom,lang,layouts,lib,style}/*.py | tar x -C "$DIR" -cp -R geom lang layouts lib style "$DIR" +tar c {geom,lang,layouts,lib,style}/*.py | tar x -C "$DIR" cp callirhoe.py "$DIR/__main__.py" ./make_resources_list > "$DIR/lib/resources.py" @@ -40,11 +30,7 @@ make_archive callirhoe "$DIR" # Create Calmagick package DIR=`mktemp -d -t callirhoe.XXX` -#tar c lib/{__init__,geom}.py | tar x -C "$DIR" -# we also avoid using mkdir this way! ;) -mkdir "$DIR/lib" -cp lib/__init__.py lib/geom.py "$DIR/lib" - +tar c lib/{__init__,geom}.py | tar x -C "$DIR" cp calmagick.py "$DIR/__main__.py" make_archive calmagick "$DIR" From 64dfad3a28796b277ac82abd726cb67202914cbd Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Mon, 3 Nov 2014 08:38:55 +0000 Subject: [PATCH 49/71] removed prefix=/usr from Makefile since it is not used. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@210 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 2 -- 1 file changed, 2 deletions(-) diff --git a/make_pkg b/make_pkg index f8da2e9..8956c0d 100755 --- a/make_pkg +++ b/make_pkg @@ -37,8 +37,6 @@ make_archive calmagick "$DIR" # Create Makefile cat << END > Makefile -prefix=/usr - install: install -Dm755 callirhoe \$(DESTDIR)/bin/callirhoe install -Dm755 calmagick \$(DESTDIR)/bin/calmagick From 475e91f5fec8ffb19313ebf8e89408a03322a129 Mon Sep 17 00:00:00 2001 From: "geortz@gmail.com" Date: Mon, 3 Nov 2014 10:31:27 +0000 Subject: [PATCH 50/71] fixed min_size bug being greater than max_size git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@211 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- calmagick.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/calmagick.py b/calmagick.py index ae791e5..db478b4 100755 --- a/calmagick.py +++ b/calmagick.py @@ -298,7 +298,9 @@ photos.""") def check_parsed_options(options): """set (remaining) default values and check validity of various option combinations""" if options.min_size is None: - options.min_size = 0.333 if options.placement in ['min','max','random'] else 0.05 + options.min_size = min(0.333,options.max_size) if options.placement in ['min','max','random'] else min(0.05,options.max_size) + if options.min_size > options.max_size: + raise lib.Abort("calmagick: --min-size should not be greater than --max-size") if options.sample is not None and not options.range: raise lib.Abort("calmagick: --sample requested without --range") if options.outfile is not None and options.range: From f47b3151867f59144de34ea3e5167b47751ae867 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Wed, 5 Nov 2014 10:36:06 +0000 Subject: [PATCH 51/71] Changes in dir structure git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@212 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- scripts/PKGBUILD | 30 ++++++++++++++++++++++++ scripts/make_pkg | 46 +++++++++++++++++++++++++++++++++++++ scripts/make_resources_list | 11 +++++++++ 3 files changed, 87 insertions(+) create mode 100644 scripts/PKGBUILD create mode 100755 scripts/make_pkg create mode 100755 scripts/make_resources_list diff --git a/scripts/PKGBUILD b/scripts/PKGBUILD new file mode 100644 index 0000000..f419735 --- /dev/null +++ b/scripts/PKGBUILD @@ -0,0 +1,30 @@ +# Author : George Tzoumas +# Maintainer: Nick Kavalieris +# For contributors check the AUTHORS file +pkgname=callirhoe +pkgver=195 +pkgrel=1 +pkgdesc="PDF Calendar creator with high quality vector graphics" +url="https://code.google.com/p/callirhoe/" +arch=('any') +license=('GPLv3') +depends=('python2' 'imagemagick' 'python2-cairo' 'subversion') +source=("$pkgname::svn+https://callirhoe.googlecode.com/svn/branches/phantome") +md5sums=('SKIP') + + +pkgver() { + cd "$pkgname" + svnversion | tr -d [A-z] | sed 's/ *//g' +} + +build() { + cd "${srcdir}/${pkgname}" + ./make_pkg +} + +package() { + cd "${srcdir}/${pkgname}" + install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING" + make DESTDIR="$pkgdir/usr" install +} \ No newline at end of file diff --git a/scripts/make_pkg b/scripts/make_pkg new file mode 100755 index 0000000..4830058 --- /dev/null +++ b/scripts/make_pkg @@ -0,0 +1,46 @@ +#!/bin/bash +set -e +cd.. + +make_archive() { + base="$1" + tempdir="$2" + curdir=`pwd` + for i in `find $tempdir -type f -name "*.py" | grep -v "__init__"`; do + python2.7 -m py_compile $i + rm $i + done + cd $tempdir + zip -q -r $curdir/$base.zip * + cd $curdir + rm -rf $tempdir + echo '#!/usr/bin/env python2.7' | cat - $base.zip > $base + chmod 755 $base + rm -f $base.zip +} + + +# Create Callirhoe package +DIR=`mktemp -d -t callirhoe.XXX` +tar c {geom,lang,layouts,lib,style}/*.py | tar x -C "$DIR" + +cp callirhoe.py "$DIR/__main__.py" +scripts/make_resources_list > "$DIR/lib/resources.py" + +make_archive callirhoe "$DIR" + +# Create Calmagick package +DIR=`mktemp -d -t callirhoe.XXX` +tar c lib/{__init__,geom}.py | tar x -C "$DIR" +cp calmagick.py "$DIR/__main__.py" + +make_archive calmagick "$DIR" + +# Create Makefile +cat << END > Makefile +install: + install -Dm755 callirhoe \$(DESTDIR)/bin/callirhoe + install -Dm755 calmagick \$(DESTDIR)/bin/calmagick +END + +find holidays/* -printf "\tinstall -Dm644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile diff --git a/scripts/make_resources_list b/scripts/make_resources_list new file mode 100755 index 0000000..1b17b1d --- /dev/null +++ b/scripts/make_resources_list @@ -0,0 +1,11 @@ +#!/usr/bin/env python2.7 +import glob + +res = dict() + +for x in ['lang', 'style', 'layouts', 'geom']: + res[x] = glob.glob('%s/*.py' % x) + +print 'resource_list = {}' +for x in res.keys(): + print 'resource_list["%s"] = %s' % (x, str(res[x])) From da9225c9734939056a271b335cab208bf716d87d Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Wed, 5 Nov 2014 10:37:10 +0000 Subject: [PATCH 52/71] removed make_pkg and resrouces_list from root dir forgot to remove pkgbuild too, but it will be removed in next commit git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@213 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- make_pkg | 45 --------------------------------------------- make_resources_list | 11 ----------- 2 files changed, 56 deletions(-) delete mode 100755 make_pkg delete mode 100755 make_resources_list diff --git a/make_pkg b/make_pkg deleted file mode 100755 index 8956c0d..0000000 --- a/make_pkg +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -set -e - -make_archive() { - base="$1" - tempdir="$2" - curdir=`pwd` - for i in `find $tempdir -type f -name "*.py" | grep -v "__init__"`; do - python2.7 -m py_compile $i - rm $i - done - cd $tempdir - zip -q -r $curdir/$base.zip * - cd $curdir - rm -rf $tempdir - echo '#!/usr/bin/env python2.7' | cat - $base.zip > $base - chmod 755 $base - rm -f $base.zip -} - - -# Create Callirhoe package -DIR=`mktemp -d -t callirhoe.XXX` -tar c {geom,lang,layouts,lib,style}/*.py | tar x -C "$DIR" - -cp callirhoe.py "$DIR/__main__.py" -./make_resources_list > "$DIR/lib/resources.py" - -make_archive callirhoe "$DIR" - -# Create Calmagick package -DIR=`mktemp -d -t callirhoe.XXX` -tar c lib/{__init__,geom}.py | tar x -C "$DIR" -cp calmagick.py "$DIR/__main__.py" - -make_archive calmagick "$DIR" - -# Create Makefile -cat << END > Makefile -install: - install -Dm755 callirhoe \$(DESTDIR)/bin/callirhoe - install -Dm755 calmagick \$(DESTDIR)/bin/calmagick -END - -find holidays/* -printf "\tinstall -Dm644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile diff --git a/make_resources_list b/make_resources_list deleted file mode 100755 index 1b17b1d..0000000 --- a/make_resources_list +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python2.7 -import glob - -res = dict() - -for x in ['lang', 'style', 'layouts', 'geom']: - res[x] = glob.glob('%s/*.py' % x) - -print 'resource_list = {}' -for x in res.keys(): - print 'resource_list["%s"] = %s' % (x, str(res[x])) From 21080ec6cf5360a9922f58fb647569add3fe09aa Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Wed, 5 Nov 2014 10:38:44 +0000 Subject: [PATCH 53/71] removed PKGBUILD from root dir too. Although I don't like PKGBUILD to be placed in scripts directory since it is Arch Linux specific, I don't see any better directory to put it on, so it sticks there. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@214 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- PKGBUILD | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 PKGBUILD diff --git a/PKGBUILD b/PKGBUILD deleted file mode 100644 index f419735..0000000 --- a/PKGBUILD +++ /dev/null @@ -1,30 +0,0 @@ -# Author : George Tzoumas -# Maintainer: Nick Kavalieris -# For contributors check the AUTHORS file -pkgname=callirhoe -pkgver=195 -pkgrel=1 -pkgdesc="PDF Calendar creator with high quality vector graphics" -url="https://code.google.com/p/callirhoe/" -arch=('any') -license=('GPLv3') -depends=('python2' 'imagemagick' 'python2-cairo' 'subversion') -source=("$pkgname::svn+https://callirhoe.googlecode.com/svn/branches/phantome") -md5sums=('SKIP') - - -pkgver() { - cd "$pkgname" - svnversion | tr -d [A-z] | sed 's/ *//g' -} - -build() { - cd "${srcdir}/${pkgname}" - ./make_pkg -} - -package() { - cd "${srcdir}/${pkgname}" - install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING" - make DESTDIR="$pkgdir/usr" install -} \ No newline at end of file From b105523f48f20da7a8ec8685bc75c636b7f1e2e0 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Wed, 5 Nov 2014 10:39:53 +0000 Subject: [PATCH 54/71] fixed a typo in make_pkg git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@215 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- scripts/make_pkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/make_pkg b/scripts/make_pkg index 4830058..7189b17 100755 --- a/scripts/make_pkg +++ b/scripts/make_pkg @@ -1,6 +1,6 @@ #!/bin/bash set -e -cd.. +cd .. make_archive() { base="$1" From f4dab107c3443d90d60df54746764bf5f4902e99 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Wed, 5 Nov 2014 10:41:13 +0000 Subject: [PATCH 55/71] Changed the directory of make_pkg in PKGBUILD so it reflects to new changes git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@216 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- scripts/PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/PKGBUILD b/scripts/PKGBUILD index f419735..d9759b6 100644 --- a/scripts/PKGBUILD +++ b/scripts/PKGBUILD @@ -19,7 +19,7 @@ pkgver() { } build() { - cd "${srcdir}/${pkgname}" + cd "${srcdir}/${pkgname}/scripts" ./make_pkg } From 5efa098a0e9cd079988a899a5b8b773640b47dcf Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Wed, 5 Nov 2014 10:59:40 +0000 Subject: [PATCH 56/71] Updated the INSTALL file, after the merge to trunk we will need to update the (because I will upload the package into AUR after the merge so PKGBUILD will point to the right svn address) git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@217 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- INSTALL | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/INSTALL b/INSTALL index 581ece7..c468574 100644 --- a/INSTALL +++ b/INSTALL @@ -6,6 +6,11 @@ QUICK INSTALLATION GUIDE +CONTENTS + 1) FROM COMPRESSED ARCHIVE + 2) FROM SVN + 3) INSTALLATION FOR ARCH LINUX + (rough installation guide for novice users...) 1) FROM COMPRESSED ARCHIVE @@ -13,7 +18,7 @@ QUICK INSTALLATION GUIDE Download the latest version from the project's page, or directly from: https://callirhoe.googlecode.com/svn/wiki/releases/ - + You end up with a file named callirhoe-X.Y.Z.7z where X.Y.Z the version number (for example 0.4.0). Extract the contents of the archive @@ -51,3 +56,22 @@ $ svn up You can launch the program as usual: $ ./callirhoe.py foo.pdf + +3) INSTALLATION FOR ARCH LINUX + +There is a PKGBUILD file you can use to install. +You can get the PKGBUILD either from SVN or compressed archive or from AUR. +For the first two options the method to get the source tree is described above, +while for the third option you can get it from here: + + +Place the PKGBUILD into a directory and run: +$ makepkg -i + +Arch will do the rest for you. + +In the unlikely event that you don't have "makepkg" already installed +you can find information about it's installation here: + +https://wiki.archlinux.org/index.php/Arch_User_Repository + From 50b683c55edd4d4d50de20ce8f67c68237f2bafb Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Wed, 5 Nov 2014 11:09:00 +0000 Subject: [PATCH 57/71] Added some info in INSTALL and change the makepkg command to install missing depedencies. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@218 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- INSTALL | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/INSTALL b/INSTALL index c468574..645082c 100644 --- a/INSTALL +++ b/INSTALL @@ -66,7 +66,10 @@ while for the third option you can get it from here: Place the PKGBUILD into a directory and run: -$ makepkg -i + +$ makepkg -s -i + +( -s will automatically install missing depedencies ) Arch will do the rest for you. From 1d6775d689afb91221eaff4ce9dcffb388e92d65 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Wed, 5 Nov 2014 11:13:18 +0000 Subject: [PATCH 58/71] Changed makepkg -s -i to makepkg -si It's the same thing, but looks better :D git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@219 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- INSTALL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL b/INSTALL index 645082c..48e6eb9 100644 --- a/INSTALL +++ b/INSTALL @@ -67,7 +67,7 @@ while for the third option you can get it from here: Place the PKGBUILD into a directory and run: -$ makepkg -s -i +$ makepkg -si ( -s will automatically install missing depedencies ) From 139f410c6cb7c84aac02031d6dd2c1041cb75185 Mon Sep 17 00:00:00 2001 From: "geortz@gmail.com" Date: Wed, 5 Nov 2014 13:56:11 +0000 Subject: [PATCH 59/71] documentation make_pkg -- minor refactoring git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@220 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- ChangeLog | 7 +++ INSTALL | 44 +++++++++++++---- scripts/make_pkg | 48 +++++++++++-------- ..._resources_list => make_resources_list.py} | 0 4 files changed, 69 insertions(+), 30 deletions(-) rename scripts/{make_resources_list => make_resources_list.py} (100%) diff --git a/ChangeLog b/ChangeLog index b9b0846..5a56141 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +******************************* +* Version 0.4.1 (Nov 2014) * +******************************* ++ packaging support for Python/Arch Linux {Nick} +! calmagick: fixed bug regarding --min-size being greater than --max-size +* refactored some common code between callirhoe and calmagick + ******************************* * Version 0.4.0 (Oct 2014) * ******************************* diff --git a/INSTALL b/INSTALL index 48e6eb9..f803dd8 100644 --- a/INSTALL +++ b/INSTALL @@ -9,7 +9,8 @@ QUICK INSTALLATION GUIDE CONTENTS 1) FROM COMPRESSED ARCHIVE 2) FROM SVN - 3) INSTALLATION FOR ARCH LINUX + 3) INVOKING callirhoe FROM PATH + 4) INSTALLATION FOR ARCH LINUX (rough installation guide for novice users...) @@ -31,13 +32,7 @@ Now you can launch the program, e.g. $ ./callirhoe.py foo.pdf -You may want to add a link to your path, $HOME/bin or /usr/local/bin: - -$ ln -s `pwd`/callirhoe.py $HOME/bin/callirhoe - -You can do the same with calmagick.py. You may also install it system-wide, -for example in /opt. In this case, keep in mind, that ~/.callirhoe/ is also -searched for additional definitions, styles etc. +See section 3 for how to install callirhoe so that it lies in your executable path. 2) FROM SVN @@ -57,11 +52,40 @@ You can launch the program as usual: $ ./callirhoe.py foo.pdf -3) INSTALLATION FOR ARCH LINUX +3) INVOKING callirhoe FROM PATH + +You can add a link to your path, $HOME/bin or /usr/local/bin: + +$ ln -s `pwd`/callirhoe.py $HOME/bin/callirhoe + +You can do the same with calmagick.py. You may also install it system-wide, +for example in /opt. In this case, keep in mind, that ~/.callirhoe/ is also +searched for additional definitions, styles etc. + +If you do not plan to mess with the source, you make create a binary python package. +This is not exactly a binary, it is a zip archive containing compiled python bytecode, +which is quite compact. To do so, go to the scripts directory: + +$ cd scripts + +and run + +$ ./make_pkg + +This will create in the parent directory two executables, 'callirhoe' and 'calmagick'. +Now copy them to your binary path. And you can remove the source dir, as it is no longer +needed. You might want to copy the holiday data files first, if you want to use them +(callirhoe takes a full path to them, so you can store them wherever you want). + +On a linux system, you will additionally see a Makefile created, which you can alternatively +run with 'make install' to install the files in the standard places, +instead of manually copying them. + +4) INSTALLATION FOR ARCH LINUX There is a PKGBUILD file you can use to install. You can get the PKGBUILD either from SVN or compressed archive or from AUR. -For the first two options the method to get the source tree is described above, +For the first two options, the method to get the source tree is described in sections 1 and 2, while for the third option you can get it from here: diff --git a/scripts/make_pkg b/scripts/make_pkg index 7189b17..3b8e549 100755 --- a/scripts/make_pkg +++ b/scripts/make_pkg @@ -1,8 +1,6 @@ #!/bin/bash -set -e -cd .. -make_archive() { +make_python_zip() { base="$1" tempdir="$2" curdir=`pwd` @@ -19,28 +17,38 @@ make_archive() { rm -f $base.zip } +create_callirhoe_package() { + DIR=`mktemp -d -t callirhoe.XXX` + tar c {geom,lang,layouts,lib,style}/*.py | tar x -C "$DIR" + cp callirhoe.py "$DIR/__main__.py" + python2.7 scripts/make_resources_list.py > "$DIR/lib/resources.py" -# Create Callirhoe package -DIR=`mktemp -d -t callirhoe.XXX` -tar c {geom,lang,layouts,lib,style}/*.py | tar x -C "$DIR" + make_python_zip callirhoe "$DIR" +} -cp callirhoe.py "$DIR/__main__.py" -scripts/make_resources_list > "$DIR/lib/resources.py" +create_calmagick_package() { + # Create Calmagick package + DIR=`mktemp -d -t callirhoe.XXX` + tar c lib/{__init__,geom}.py | tar x -C "$DIR" + cp calmagick.py "$DIR/__main__.py" + + make_python_zip calmagick "$DIR" +} -make_archive callirhoe "$DIR" - -# Create Calmagick package -DIR=`mktemp -d -t callirhoe.XXX` -tar c lib/{__init__,geom}.py | tar x -C "$DIR" -cp calmagick.py "$DIR/__main__.py" - -make_archive calmagick "$DIR" - -# Create Makefile -cat << END > Makefile +create_makefile() { + cat << END > Makefile install: install -Dm755 callirhoe \$(DESTDIR)/bin/callirhoe install -Dm755 calmagick \$(DESTDIR)/bin/calmagick END -find holidays/* -printf "\tinstall -Dm644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile + find holidays/* -printf "\tinstall -Dm644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile +} + +set -e +cd .. + +create_callirhoe_package +create_calmagick_package + +[[ "`uname`" != "Darwin" ]] && create_makefile diff --git a/scripts/make_resources_list b/scripts/make_resources_list.py similarity index 100% rename from scripts/make_resources_list rename to scripts/make_resources_list.py From 640164b029ee8e96824cb371dc3693ad075cb86e Mon Sep 17 00:00:00 2001 From: "geortz@gmail.com" Date: Wed, 5 Nov 2014 13:58:19 +0000 Subject: [PATCH 60/71] propdel executable git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@221 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- scripts/make_resources_list.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 scripts/make_resources_list.py diff --git a/scripts/make_resources_list.py b/scripts/make_resources_list.py old mode 100755 new mode 100644 From 6d6977b9df6c763fbe9adc38baf746c61814ea12 Mon Sep 17 00:00:00 2001 From: "geortz@gmail.com" Date: Wed, 5 Nov 2014 22:53:32 +0000 Subject: [PATCH 61/71] typo git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@222 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- INSTALL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL b/INSTALL index f803dd8..d7cb195 100644 --- a/INSTALL +++ b/INSTALL @@ -62,7 +62,7 @@ You can do the same with calmagick.py. You may also install it system-wide, for example in /opt. In this case, keep in mind, that ~/.callirhoe/ is also searched for additional definitions, styles etc. -If you do not plan to mess with the source, you make create a binary python package. +If you do not plan to mess with the source, you may create a binary python package. This is not exactly a binary, it is a zip archive containing compiled python bytecode, which is quite compact. To do so, go to the scripts directory: From b50ae0a592a147999c8dea93999919dc42c181cf Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 6 Nov 2014 11:45:50 +0000 Subject: [PATCH 62/71] Changes in scripts (added Makefile), changed make_pkg git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@223 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- scripts/Makefile | 10 ++++++++++ scripts/make_pkg | 16 +++------------- 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 scripts/Makefile diff --git a/scripts/Makefile b/scripts/Makefile new file mode 100644 index 0000000..d5656fa --- /dev/null +++ b/scripts/Makefile @@ -0,0 +1,10 @@ +DESTDIR=/usr + +install: install-package + +install-package: + mkdir -p $(DESTDIR)/bin + mkdir -p $(DESTDIR)/share/callirhoe/holidays + install -m755 callirhoe $(DESTDIR)/bin/callirhoe + install -m755 calmagick $(DESTDIR)/bin/calmagick + install -m644 holidays/* $(DESTDIR)/share/callirhoe/holidays/ diff --git a/scripts/make_pkg b/scripts/make_pkg index 3b8e549..77a3368 100755 --- a/scripts/make_pkg +++ b/scripts/make_pkg @@ -31,24 +31,14 @@ create_calmagick_package() { DIR=`mktemp -d -t callirhoe.XXX` tar c lib/{__init__,geom}.py | tar x -C "$DIR" cp calmagick.py "$DIR/__main__.py" - + make_python_zip calmagick "$DIR" } -create_makefile() { - cat << END > Makefile -install: - install -Dm755 callirhoe \$(DESTDIR)/bin/callirhoe - install -Dm755 calmagick \$(DESTDIR)/bin/calmagick -END - - find holidays/* -printf "\tinstall -Dm644 %p \$(DESTDIR)/share/callirhoe/%p\n" >> Makefile -} - set -e + +cp Makefile ../ cd .. create_callirhoe_package create_calmagick_package - -[[ "`uname`" != "Darwin" ]] && create_makefile From d9cb3f5f2f0af4c7ab115afc8d58a70d52c7222e Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 6 Nov 2014 11:50:29 +0000 Subject: [PATCH 63/71] moved Makefile to root dir and updated it git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@224 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- Makefile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..57e5b62 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +DESTDIR=/usr + +all: callirhoe calmagick + cd scripts && ./make_pkg + +install: install-package + +install-package: + mkdir -p $(DESTDIR)/bin + mkdir -p $(DESTDIR)/share/callirhoe/holidays + install -m755 callirhoe $(DESTDIR)/bin/callirhoe + install -m755 calmagick $(DESTDIR)/bin/calmagick + install -m644 holidays/* $(DESTDIR)/share/callirhoe/holidays/ From 74fdf623e94d81258e72351bb49c21f39f9ffdfc Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 6 Nov 2014 11:53:39 +0000 Subject: [PATCH 64/71] Fixed typo in Makefile git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@225 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- Makefile | 2 +- scripts/Makefile | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 scripts/Makefile diff --git a/Makefile b/Makefile index 57e5b62..b31b036 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ DESTDIR=/usr all: callirhoe calmagick - cd scripts && ./make_pkg + cd scripts && ./make_pkg install: install-package diff --git a/scripts/Makefile b/scripts/Makefile deleted file mode 100644 index d5656fa..0000000 --- a/scripts/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -DESTDIR=/usr - -install: install-package - -install-package: - mkdir -p $(DESTDIR)/bin - mkdir -p $(DESTDIR)/share/callirhoe/holidays - install -m755 callirhoe $(DESTDIR)/bin/callirhoe - install -m755 calmagick $(DESTDIR)/bin/calmagick - install -m644 holidays/* $(DESTDIR)/share/callirhoe/holidays/ From e171bed77777961bd06eb8e4743300f4d5fc72de Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 6 Nov 2014 11:55:22 +0000 Subject: [PATCH 65/71] Fixed error in Makefile git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@226 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b31b036..00d4eea 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ DESTDIR=/usr -all: callirhoe calmagick +all: cd scripts && ./make_pkg install: install-package From 16b7f03763b50293c0a1189ae991dbbb1549c6aa Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 6 Nov 2014 11:56:32 +0000 Subject: [PATCH 66/71] Removed "cp Makefile" from make_pkg, it is not relevant anymore. git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@227 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- scripts/make_pkg | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/make_pkg b/scripts/make_pkg index 77a3368..a94b473 100755 --- a/scripts/make_pkg +++ b/scripts/make_pkg @@ -37,8 +37,6 @@ create_calmagick_package() { set -e -cp Makefile ../ -cd .. - +cd.. create_callirhoe_package create_calmagick_package From 7bfd4419a50c78b481b29168dc3f5fe8048345c7 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 6 Nov 2014 11:57:14 +0000 Subject: [PATCH 67/71] omg! second time the same type "cd.." ...... git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@228 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- scripts/make_pkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/make_pkg b/scripts/make_pkg index a94b473..c62a89a 100755 --- a/scripts/make_pkg +++ b/scripts/make_pkg @@ -37,6 +37,6 @@ create_calmagick_package() { set -e -cd.. +cd .. create_callirhoe_package create_calmagick_package From 934598b37797c89a3312ead29cb50bb9a5abeb40 Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 6 Nov 2014 11:58:56 +0000 Subject: [PATCH 68/71] Updated PKGBUILD git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@229 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- scripts/PKGBUILD | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/PKGBUILD b/scripts/PKGBUILD index d9759b6..08afcb2 100644 --- a/scripts/PKGBUILD +++ b/scripts/PKGBUILD @@ -2,7 +2,7 @@ # Maintainer: Nick Kavalieris # For contributors check the AUTHORS file pkgname=callirhoe -pkgver=195 +pkgver=228 pkgrel=1 pkgdesc="PDF Calendar creator with high quality vector graphics" url="https://code.google.com/p/callirhoe/" @@ -19,8 +19,8 @@ pkgver() { } build() { - cd "${srcdir}/${pkgname}/scripts" - ./make_pkg + cd "${srcdir}/${pkgname}" + make } package() { From 5ad584249edf8faf76c74ab012a8d26728b086ad Mon Sep 17 00:00:00 2001 From: "ph4ntome@gmail.com" Date: Thu, 6 Nov 2014 12:01:21 +0000 Subject: [PATCH 69/71] Changed some comments inside PKGBUILD git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@230 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- scripts/PKGBUILD | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/PKGBUILD b/scripts/PKGBUILD index 08afcb2..e91388d 100644 --- a/scripts/PKGBUILD +++ b/scripts/PKGBUILD @@ -1,6 +1,10 @@ -# Author : George Tzoumas # Maintainer: Nick Kavalieris +# Upstream Author : George Tzoumas # For contributors check the AUTHORS file + +# This file is also included in the source tree for purposes of completeness +# The normal way of aqusition is from AUR: + pkgname=callirhoe pkgver=228 pkgrel=1 From 7cd1161aeff36065fa3607b5c5ede6f2d5923249 Mon Sep 17 00:00:00 2001 From: "geortz@gmail.com" Date: Thu, 6 Nov 2014 12:57:39 +0000 Subject: [PATCH 70/71] check for existing packages destdir default value git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@231 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- Makefile | 5 ++++- scripts/make_pkg | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 00d4eea..635a8d1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -DESTDIR=/usr +DESTDIR=/usr/local all: cd scripts && ./make_pkg @@ -11,3 +11,6 @@ install-package: install -m755 callirhoe $(DESTDIR)/bin/callirhoe install -m755 calmagick $(DESTDIR)/bin/calmagick install -m644 holidays/* $(DESTDIR)/share/callirhoe/holidays/ + +clean: + rm -f callirhoe calmagick diff --git a/scripts/make_pkg b/scripts/make_pkg index c62a89a..3e7b5b9 100755 --- a/scripts/make_pkg +++ b/scripts/make_pkg @@ -38,5 +38,5 @@ create_calmagick_package() { set -e cd .. -create_callirhoe_package -create_calmagick_package +[[ -x callirhoe ]] && echo "callirhoe package seems to exist, skipping; rm 'calliroe' to recreate" || create_callirhoe_package +[[ -x calmagick ]] && echo "calmagick package seems to exist, skipping; rm 'calmagick' to recreate" || create_calmagick_package From c0f65af50412546b9e880f3acf1cf2e7fa0e12c9 Mon Sep 17 00:00:00 2001 From: "geortz@gmail.com" Date: Thu, 6 Nov 2014 17:02:32 +0000 Subject: [PATCH 71/71] documentation git-svn-id: https://callirhoe.googlecode.com/svn/branches/phantome@232 81c8bb96-aa45-f2e2-0eef-c4fa4a15c6df --- INSTALL | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/INSTALL b/INSTALL index d7cb195..0aa5926 100644 --- a/INSTALL +++ b/INSTALL @@ -9,7 +9,7 @@ QUICK INSTALLATION GUIDE CONTENTS 1) FROM COMPRESSED ARCHIVE 2) FROM SVN - 3) INVOKING callirhoe FROM PATH + 3) INSTALLING INTO BINARY PATH 4) INSTALLATION FOR ARCH LINUX (rough installation guide for novice users...) @@ -20,7 +20,8 @@ Download the latest version from the project's page, or directly from: https://callirhoe.googlecode.com/svn/wiki/releases/ -You end up with a file named callirhoe-X.Y.Z.7z where X.Y.Z the version number (for example 0.4.0). +You end up with a file named callirhoe-X.Y.Z.7z where X.Y.Z the version +number (for example 0.4.0). Extract the contents of the archive $ 7z x callirhoe-X.Y.Z.7z @@ -32,7 +33,8 @@ Now you can launch the program, e.g. $ ./callirhoe.py foo.pdf -See section 3 for how to install callirhoe so that it lies in your executable path. +See section 3 for how to install callirhoe so that it lies in your +executable path. 2) FROM SVN @@ -52,48 +54,48 @@ You can launch the program as usual: $ ./callirhoe.py foo.pdf -3) INVOKING callirhoe FROM PATH +3) INSTALLING INTO BINARY PATH You can add a link to your path, $HOME/bin or /usr/local/bin: $ ln -s `pwd`/callirhoe.py $HOME/bin/callirhoe -You can do the same with calmagick.py. You may also install it system-wide, -for example in /opt. In this case, keep in mind, that ~/.callirhoe/ is also -searched for additional definitions, styles etc. +You can do the same with calmagick.py. You may also install it +system-wide, for example in /opt. In this case, keep in mind, that +~/.callirhoe/ is also searched for additional definitions, styles etc. -If you do not plan to mess with the source, you may create a binary python package. -This is not exactly a binary, it is a zip archive containing compiled python bytecode, -which is quite compact. To do so, go to the scripts directory: +If you do not plan to mess with the source, you may create a binary +python package. This is not exactly a binary, it is a zip archive +containing compiled python bytecode, which is quite compact. To do so, +simply run: -$ cd scripts +$ make -and run +This will create two executables, 'callirhoe' and 'calmagick'. Now you +can install them into your binary path as follows: -$ ./make_pkg +$ make install -This will create in the parent directory two executables, 'callirhoe' and 'calmagick'. -Now copy them to your binary path. And you can remove the source dir, as it is no longer -needed. You might want to copy the holiday data files first, if you want to use them -(callirhoe takes a full path to them, so you can store them wherever you want). +this will typically install to /usr/local/bin (and the holiday files into +/usr/local/share/callirhoe/holidays). You can specify another prefix: -On a linux system, you will additionally see a Makefile created, which you can alternatively -run with 'make install' to install the files in the standard places, -instead of manually copying them. +$ make install DESTDIR=/my/other/dir + +Now you can remove the source dir, as it is no longer needed. 4) INSTALLATION FOR ARCH LINUX -There is a PKGBUILD file you can use to install. -You can get the PKGBUILD either from SVN or compressed archive or from AUR. -For the first two options, the method to get the source tree is described in sections 1 and 2, -while for the third option you can get it from here: - +There is a PKGBUILD file you can use to install. Normally you get just +the PKGBUILD from the webpage from AUR (). It is also +included in the source distribution, but this is a bit redundant (see +below). Place the PKGBUILD into a directory and run: $ makepkg -si -( -s will automatically install missing depedencies ) +( -s will automatically install missing depedencies; also note that this +will redownload the source from the svn ) Arch will do the rest for you. @@ -101,4 +103,3 @@ In the unlikely event that you don't have "makepkg" already installed you can find information about it's installation here: https://wiki.archlinux.org/index.php/Arch_User_Repository -