[PythonReports-checkins] PythonReports/PythonReports builder.py, 1.3, 1.4
Brought to you by:
a1s
From: alexander s. <a1...@us...> - 2006-12-06 16:13:39
|
Update of /cvsroot/pythonreports/PythonReports/PythonReports In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23499 Modified Files: builder.py Log Message: fix errors and some warnings reported by pylint Index: builder.py =================================================================== RCS file: /cvsroot/pythonreports/PythonReports/PythonReports/builder.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** builder.py 4 Nov 2006 14:53:17 -0000 1.3 --- builder.py 6 Dec 2006 16:13:37 -0000 1.4 *************** *** 2,5 **** --- 2,6 ---- # FIXME: column-based variables are not intelligible """History (most recent first): + 05-dec-2006 [als] fix errors and some warnings reported by pylint 04-nov-2006 [als] Builder: delay text_drivers initialization until run, added backend selection parameters for __init__ *************** *** 57,60 **** --- 58,65 ---- 11-jul-2006 [als] created """ + __version__ = "$Revision$"[11:-2] + __date__ = "$Date$"[7:-2] + + __all__ = ["Builder"] import math *************** *** 67,75 **** from PythonReports.datatypes import * - __version__ = "$Revision$"[11:-2] - __date__ = "$Date$"[7:-2] - - __all__ = ["Builder"] - class Variable(object): --- 72,75 ---- *************** *** 82,105 **** """ # Most variables use builtin list to accumulate values # these helper classes are used in special cases # for uniform accumulation calls ! class AccumulateDistinct(set): def append(self, value): self.add(value) ! class AccumulateFloat(list): def append(self, value): ! super(AccumulateFloat, self).append(float(value)) ! class KeepFirst(list): value = NOTHING def append(self, value): if self.value is NOTHING: self[:] = [value] ! class UseCurrent(list): def append(self, value): self[:] = [value] --- 82,130 ---- """ + # attributes initialized from template element + name = REQUIRED + expr = REQUIRED + init = None + calc = "first" + iter = "detail" + itergrp = None + reset = "report" + resetgrp = None + # Most variables use builtin list to accumulate values # these helper classes are used in special cases # for uniform accumulation calls ! class _Accumulator(object): ! """Base class for value accumulators""" ! # pylint: disable-msg=R0903 ! # R0903: Too few public methods ! def append(self, value): ! """Add a value to the accumulated sequence""" ! ! class AccumulateDistinct(_Accumulator, set): ! """Distinct values accumulator""" def append(self, value): + """Add a value to the accumulated sequence""" self.add(value) ! class AccumulateFloat(_Accumulator, list): ! """Accumulator forcing all values to be float""" def append(self, value): ! """Add a value to the accumulated sequence""" ! super(Variable.AccumulateFloat, self).append(float(value)) ! class KeepFirst(_Accumulator, list): ! """"Accumulator" always keeping the first value of the sequence""" value = NOTHING def append(self, value): + """Add a value to the accumulated sequence""" if self.value is NOTHING: self[:] = [value] ! class UseCurrent(_Accumulator, list): ! """"Accumulator" always returning current value of the sequence""" def append(self, value): + """Add a value to the accumulated sequence""" self[:] = [value] *************** *** 108,141 **** @staticmethod def first(value): return value[0] @staticmethod def count(value): return len(value) @staticmethod def avg(value): return sum(value) / len(value) @staticmethod def min(value): return min(value) @staticmethod def max(value): return max(value) @staticmethod def var(value): ! _avg = avg(value) ! return sum([(_item - _avg) ** 2 for _item in _value]) / len(value) @staticmethod def std(value): ! return math.sqrt(avg(value)) # sum must be defined last to use builtin sum in other calculations @staticmethod def sum(value): if isinstance(value[0], basestring): return "".join(value) --- 133,178 ---- @staticmethod def first(value): + """Return the first element of the value sequence""" return value[0] @staticmethod def count(value): + """Return number of elements in the value sequence""" return len(value) @staticmethod def avg(value): + """Return an average value of a float sequence""" return sum(value) / len(value) @staticmethod def min(value): + """Return minimal value of the value sequence""" return min(value) @staticmethod def max(value): + """Return maximal value of the value sequence""" return max(value) @staticmethod def var(value): ! """Return variance from the average of a float sequence""" ! _avg = Variable.avg(value) ! return sum([(_item - _avg) ** 2 for _item in value]) / len(value) @staticmethod def std(value): ! """Return standard deviation of a float sequence""" ! return math.sqrt(Variable.var(value)) # sum must be defined last to use builtin sum in other calculations @staticmethod def sum(value): + """Return sum of the sequence values + + If values are strings, return concatenated string. + + """ if isinstance(value[0], basestring): return "".join(value) *************** *** 205,208 **** --- 242,246 ---- @property def value(self): + """Variable evaluation result""" if self.values: return self._compute(self.values) *************** *** 292,296 **** # self.sysvars[_name] = _var.value ! def add_variables(self, *vars): """Add report variable definitions --- 330,334 ---- # self.sysvars[_name] = _var.value ! def add_variables(self, *variables): """Add report variable definitions *************** *** 298,302 **** """ ! for _var in vars: self.variables[_var.name] = _var --- 336,340 ---- """ ! for _var in variables: self.variables[_var.name] = _var *************** *** 326,329 **** --- 364,370 ---- """ + # pylint: disable-msg=R0903 + # R0903: Too few public methods + ### attributes: # *************** *** 341,344 **** --- 382,388 ---- # otext: output text, wrapped to box width + # make pylint happy + section = style = printable = tbox = bbox = obox = text = otext = None + class Section(list): *************** *** 391,395 **** self.builder = builder self.template = template ! self.tbox = Box.from_element(template.find("box")) if context: self.build(context) --- 435,440 ---- self.builder = builder self.template = template ! self.box = self.tbox = Box.from_element(template.find("box")) ! self.resizeable = False if context: self.build(context) *************** *** 430,439 **** _printwhen = _style.get("printwhen") if _printwhen: ! _rv = bool(contex.eval(_printwhen)) break self.printable = _rv return _rv ! def compose_style(self, context, need_attrs, styles): """Return style attributes collected from a style sequence --- 475,485 ---- _printwhen = _style.get("printwhen") if _printwhen: ! _rv = bool(context.eval(_printwhen)) break self.printable = _rv return _rv ! @staticmethod ! def compose_style(context, need_attrs, styles): """Return style attributes collected from a style sequence *************** *** 778,782 **** (_prp_type, _prp_attrs) = self.PRINTOUTS[_template.tag] _prp_tag = _prp_type.tag ! _attrib=dict([(_name, _template.get(_name)) for _name in _prp_attrs]) # add style attributes (must be done before constructor is called) --- 824,828 ---- (_prp_type, _prp_attrs) = self.PRINTOUTS[_template.tag] _prp_tag = _prp_type.tag ! _attrib = dict([(_name, _template.get(_name)) for _name in _prp_attrs]) # add style attributes (must be done before constructor is called) *************** *** 862,865 **** --- 908,914 ---- """ + # pylint: disable-msg=R0903 + # R0903: Too few public methods + colcount = 1 # number of columns colgap = 0 # space between columns *************** *** 960,965 **** super(Builder, self).__init__() if isinstance(template, basestring): ! template = prt.load(template) ! self.template = template self.data = data if parameters: --- 1009,1015 ---- super(Builder, self).__init__() if isinstance(template, basestring): ! self.template = prt.load(template) ! else: ! self.template = template self.data = data if parameters: *************** *** 970,981 **** self.text_driver_factory = drivers.get_driver("Text", text_backend) self.image_driver_factory = drivers.get_driver("Image", image_backend) ! self.basedir = template.getroot().get("basedir", None) if not self.basedir: ! if template.filename: ! self.basedir = os.path.dirname(template.filename) else: self.basedir = os.getcwd() self.variables = [Variable(_item) ! for _item in template.variables.itervalues()] # image collections: # - kept in files --- 1020,1033 ---- self.text_driver_factory = drivers.get_driver("Text", text_backend) self.image_driver_factory = drivers.get_driver("Image", image_backend) ! self.basedir = self.template.getroot().get("basedir", None) if not self.basedir: ! if self.template.filename: ! self.basedir = os.path.dirname(self.template.filename) else: self.basedir = os.getcwd() self.variables = [Variable(_item) ! for _item in self.template.variables.itervalues()] ! # text rendering drivers, will be re-evaluated in .run() ! self.text_drivers = {} # image collections: # - kept in files *************** *** 987,991 **** self.images_loaded = {} # ! _layout = template.find("layout") self.template_pagefooter = _layout.find("footer") # list of group templates --- 1039,1043 ---- self.images_loaded = {} # ! _layout = self.template.find("layout") self.template_pagefooter = _layout.find("footer") # list of group templates *************** *** 1052,1056 **** _imgdata = Data.get_data(_imgdata) _image = self.image_driver_factory.fromdata( ! _imgdata, type=_type, name=_name) self.images_named[_name] = _image self.images_loaded[_imgdata] = _image --- 1104,1108 ---- _imgdata = Data.get_data(_imgdata) _image = self.image_driver_factory.fromdata( ! _imgdata, img_type=_type, name=_name) self.images_named[_name] = _image self.images_loaded[_imgdata] = _image *************** *** 1067,1071 **** if _imgdata not in self.images_loaded: _image = self.image_driver_factory.fromdata(_imgdata, ! type=_type) self.images_loaded[_imgdata] = _image return self.images_loaded[_imgdata] --- 1119,1123 ---- if _imgdata not in self.images_loaded: _image = self.image_driver_factory.fromdata(_imgdata, ! img_type=_type) self.images_loaded[_imgdata] = _image return self.images_loaded[_imgdata] *************** *** 1165,1169 **** _colcount = _columns.get("count") _colgap = _columns.get("gap") ! _width=(parent_frame.width - ((_colcount - 1) * _colgap)) / _colcount _frame = parent_frame.make_child(width=_width, colcount=_colcount, colgap=_colgap) --- 1217,1221 ---- _colcount = _columns.get("count") _colgap = _columns.get("gap") ! _width = (parent_frame.width - ((_colcount - 1) * _colgap)) / _colcount _frame = parent_frame.make_child(width=_width, colcount=_colcount, colgap=_colgap) *************** *** 1201,1205 **** # processing takes about 10s # and output generation takes about .4s ! _start_time = time.time() if item_callback: _callback = item_callback --- 1253,1257 ---- # processing takes about 10s # and output generation takes about .4s ! #_start_time = time.time() if item_callback: _callback = item_callback *************** *** 1277,1281 **** if _name not in _parameters: _value = _context.eval(_parm.get("default")) ! if _item_prompt: # TODO? parameter input with wx or Tkinter GUI _input = raw_input("%s [%s]: " % (_name, _value)) --- 1329,1333 ---- if _name not in _parameters: _value = _context.eval(_parm.get("default")) ! if _parm.prompt: # TODO? parameter input with wx or Tkinter GUI _input = raw_input("%s [%s]: " % (_name, _value)) *************** *** 1522,1529 **** return None if context is None: ! context = self.context _frame = self.section_frames[template] ! context["COLUMN_NUMBER"] = _frame.column + 1 ! _section = Section(self, template, context) if not _section.printable: return None --- 1574,1583 ---- return None if context is None: ! _context = self.context ! else: ! _context = context _frame = self.section_frames[template] ! _context["COLUMN_NUMBER"] = _frame.column + 1 ! _section = Section(self, template, _context) if not _section.printable: return None *************** *** 1535,1540 **** and (_section.template.tag != "footer"): self.eject(_frame) ! context["COLUMN_NUMBER"] = _frame.column + 1 ! _section.build(context) if not _section.printable: return None --- 1589,1594 ---- and (_section.template.tag != "footer"): self.eject(_frame) ! _context["COLUMN_NUMBER"] = _frame.column + 1 ! _section.build(_context) if not _section.printable: return None |