1 |
# |
# |
2 |
# This file is part of GNU Enterprise. |
# This file is part of GNU Enterprise. |
3 |
# |
# |
4 |
# GNU Enterprise is free software; you can redistribute it |
# GNU Enterprise is free software; you can redistribute it |
5 |
# and/or modify it under the terms of the GNU General Public |
# and/or modify it under the terms of the GNU General Public |
6 |
# License as published by the Free Software Foundation; either |
# License as published by the Free Software Foundation; either |
7 |
# version 2, or (at your option) any later version. |
# version 2, or (at your option) any later version. |
8 |
# |
# |
9 |
# GNU Enterprise is distributed in the hope that it will be |
# GNU Enterprise is distributed in the hope that it will be |
10 |
# useful, but WITHOUT ANY WARRANTY; without even the implied |
# useful, but WITHOUT ANY WARRANTY; without even the implied |
11 |
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
12 |
# PURPOSE. See the GNU General Public License for more details. |
# PURPOSE. See the GNU General Public License for more details. |
13 |
# |
# |
14 |
# You should have received a copy of the GNU General Public |
# You should have received a copy of the GNU General Public |
15 |
# License along with program; see the file COPYING. If not, |
# License along with program; see the file COPYING. If not, |
16 |
# write to the Free Software Foundation, Inc., 59 Temple Place |
# write to the Free Software Foundation, Inc., 59 Temple Place |
17 |
# - Suite 330, Boston, MA 02111-1307, USA. |
# - Suite 330, Boston, MA 02111-1307, USA. |
18 |
# |
# |
30 |
# |
# |
31 |
|
|
32 |
from gnue.common.GObjects import * |
from gnue.common.GObjects import * |
33 |
|
from gnue.common.GRootObj import GRootObj |
34 |
from gnue.common import GDebug |
from gnue.common import GDebug |
35 |
|
from gnue.common.GTrigger import GTriggerExtension |
36 |
|
|
37 |
import sys |
import sys |
38 |
import GRParser |
import GRParser |
39 |
import GRParameters |
import GRParameters |
43 |
import GRExceptions |
import GRExceptions |
44 |
|
|
45 |
|
|
46 |
class GRReport(GObj): |
class GRReport(GRootObj, GObj, GTriggerExtension): |
47 |
def __init__(self, parent=None): |
def __init__(self, parent=None): |
48 |
|
GTriggerExtension.__init__(self) |
49 |
|
GRootObj.__init__(self, 'report', GRParser.getXMLelements, GRParser) |
50 |
GObj.__init__(self, parent, type='GRReport') |
GObj.__init__(self, parent, type='GRReport') |
51 |
self._connections = None # This will be set by GRParser.loadReport |
self._connections = None # This will be set by GRParser.loadFile |
52 |
self._inits = (self.initialize,self.postInit) |
self._inits = (self.initialize,self.postInit) |
53 |
self._datasourceDictionary = {} |
self._datasourceDictionary = {} |
54 |
self._parameters = None |
self._parameters = None |
55 |
|
|
56 |
|
# |
57 |
|
# New trigger support |
58 |
|
# |
59 |
|
self._triggerDictionary = {} |
60 |
|
self._triggerns={} |
61 |
|
|
62 |
|
self._validTriggers = { 'ON-STARTUP': 'On-Startup', |
63 |
|
'ON-EXIT': 'On-Exit' } |
64 |
|
|
65 |
|
#self._triggerGlobal = 1 |
66 |
|
self._triggerFunctions = {} |
67 |
|
self._app = None |
68 |
|
|
69 |
|
|
70 |
def initialize(self): |
def initialize(self): |
71 |
pass |
self.initTriggerSystem() |
72 |
|
self._triggerns.update(self._triggerNamespaceTree._globalNamespace) |
73 |
|
|
74 |
def postInit(self): |
def postInit(self): |
75 |
if not self._parameters: |
if not self._parameters: |
76 |
self._parameters = GRParameters.GRParameters(self) |
self._parameters = GRParameters.GRParameters(self) |
77 |
|
|
|
|
|
|
def dumpXML(self, treeDump=1, gap=" "): |
|
|
return GObj.dumpXML(self, |
|
|
GRParser.getXMLelements(), treeDump, gap, xmlnamespaces={}) |
|
|
|
|
|
|
|
78 |
# |
# |
79 |
# Process the report and generate output per the report definition. |
# Process the report and generate output per the report definition. |
80 |
# Destination must be a file handle (StringIO will work as well) |
# Destination must be a file handle (StringIO will work as well) |
84 |
|
|
85 |
import GRDataMapper |
import GRDataMapper |
86 |
|
|
87 |
|
|
88 |
# Connect to databases |
# Connect to databases |
89 |
GDebug.printMesg(3,"Initializing DataSource Connections") |
GDebug.printMesg(3,"Initializing DataSource Connections") |
90 |
|
|
97 |
|
|
98 |
|
|
99 |
# |
# |
100 |
# Raise exceptions if _sources or _parameters is None |
# Raise exceptions if _sources or _layout is None |
101 |
# |
# |
102 |
if sources == None: |
if sources == None: |
103 |
raise NoSourcesSection, "No <sources> section has been defined." |
raise NoSourcesSection, "No <sources> section has been defined." |
119 |
mapper = GRDataMapper.GRDataMapper(sources) |
mapper = GRDataMapper.GRDataMapper(sources) |
120 |
layout.prepare(mapper, parameters) |
layout.prepare(mapper, parameters) |
121 |
|
|
122 |
|
self.processTrigger('On-Startup') |
123 |
# Write common header information |
# Write common header information |
124 |
if not omitGNUeXML: |
if not omitGNUeXML: |
125 |
|
|
129 |
ns = "" |
ns = "" |
130 |
|
|
131 |
# TODO: other encodings??? |
# TODO: other encodings??? |
132 |
dest.write ('<?xml version="1.0" encoding="ISO-8859-1"?>\n') |
encoding= sys.getdefaultencoding() |
133 |
|
if encoding == 'ascii': |
134 |
|
encoding = 'iso8859-1' # TODO: fix this when we have [common] section |
135 |
|
try: # in gnue.conf |
136 |
|
encoding = gConfig('formFontEncoding') |
137 |
|
except: |
138 |
|
pass |
139 |
|
dest.write ('<?xml version="1.0" encoding="%s"?>\n'%encoding) |
140 |
|
|
141 |
#TODO: (?) dest.write ('<!DOCTYPE ... >\n') |
#TODO: (?) dest.write ('<!DOCTYPE ... >\n') |
142 |
dest.write ('<gnue:report-output xmlns:gnue="GNUe:Reports:Base"%s>\n' % ns) |
dest.write ('<gnue:report-output xmlns:gnue="GNUe:Reports:Base"%s>\n' % ns) |
143 |
|
|
144 |
dest.write (" <gnue:report-request>\n") |
dest.write (" <gnue:report-request>\n") |
145 |
dest.write ( parameters.getRunOptionsAsXML() ) |
dest.write ( parameters.getRunOptionsAsXML() ) |
146 |
dest.write ( sortoptions.getRunOptionsAsXML() ) |
dest.write ( sortoptions.getRunOptionsAsXML() ) |
151 |
if not omitGNUeXML: |
if not omitGNUeXML: |
152 |
dest.write ("\n</gnue:report-output>\n") |
dest.write ("\n</gnue:report-output>\n") |
153 |
|
|
154 |
|
self.processTrigger('On-Exit') |
155 |
|
|
156 |
def getChildOfType(self, type): |
def getChildOfType(self, type): |
157 |
rv = None |
rv = None |