Changeset 3335
- Timestamp:
- 02/18/08 17:15:34 (17 years ago)
- Location:
- pykota/trunk
- Files:
-
- 2 modified
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkbanner
r3332 r3335 47 47 48 48 import pykota.appinit 49 from pykota.utils import run, loginvalidparam 50 from pykota.commandline import PyKotaOptionParser 51 49 from pykota.utils import run 50 from pykota.commandline import PyKotaOptionParser, \ 51 checkandset_pagesize, \ 52 checkandset_savetoner 53 from pykota.pdfutils import getPageSize 52 54 from pykota.errors import PyKotaToolError 53 55 from pykota.tool import Tool 54 56 from pykota import version 55 57 56 def getPageSize(pgsize) :57 """Returns the correct page size or None if not found."""58 try :59 try :60 return getattr(reportlab.lib.pagesizes, pgsize.upper())61 except AttributeError :62 try :63 return getattr(reportlab.lib.pagesizes, pgsize.lower())64 except AttributeError :65 pass66 except UnicodeError :67 pass68 return None69 70 58 class PyKotaBanner(Tool) : 71 59 """A class for pkbanner.""" … … 241 229 242 230 if __name__ == "__main__" : 243 def checkandset_pagesize(option, opt, value, optionparser) :244 """Checks and sets the page size."""245 if getPageSize(value) is None :246 loginvalidparam(opt, value, option.default)247 setattr(optionparser.values, option.dest, option.default)248 else :249 setattr(optionparser.values, option.dest, value)250 251 def checkandset_savetoner(option, opt, value, optionparser) :252 """Checks and sets the save toner value."""253 if (value < 0.0) or (value > 99.0) :254 loginvalidparam(opt, value, option.default, \255 _("Allowed range is (0..99)"))256 setattr(optionparser.values, option.dest, option.default)257 else :258 setattr(optionparser.values, option.dest, value)259 260 231 # TODO : --papertray : to print banners on a different paper (colored for example) 261 232 parser = PyKotaOptionParser(description=_("Banner generator for PyKota.")) -
pykota/trunk/pykota/commandline.py
r3316 r3335 28 28 29 29 from pykota import version 30 from pykota.utils import loginvalidparam 31 32 def checkandset_pagesize(option, opt, value, optionparser) : 33 """Checks and sets the page size.""" 34 from pykota.pdfutils import getPageSize 35 if getPageSize(value) is None : 36 loginvalidparam(opt, value, option.default) 37 setattr(optionparser.values, option.dest, option.default) 38 else : 39 setattr(optionparser.values, option.dest, value) 40 41 def checkandset_savetoner(option, opt, value, optionparser) : 42 """Checks and sets the save toner value.""" 43 if (value < 0.0) or (value > 99.0) : 44 loginvalidparam(opt, value, option.default, \ 45 _("Allowed range is (0..99)")) 46 setattr(optionparser.values, option.dest, option.default) 47 else : 48 setattr(optionparser.values, option.dest, value) 30 49 31 50 class PyKotaOptionParser(optparse.OptionParser) : -
pykota/trunk/pykota/pdfutils.py
r3275 r3335 19 19 # $Id$ 20 20 # 21 22 """This module contains helper methods for PDF related work.""" 23 24 def getPageSize(pgsize) : 25 """Returns the correct page size or None if not found.""" 26 try : 27 import reportlab.lib.pagesizes as sizes 28 except ImportError : 29 pass 30 else : 31 try : 32 return getattr(sizes, pgsize.upper(), getattr(sizes, 33 pgsize.lower(), 34 None)) 35 except UnicodeError : 36 pass 37 return None