1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2022 EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
24 Gestion simple de rapports structurés créés par l'utilisateur.
26 __author__ = "Jean-Philippe ARGAUD"
31 # ==============================================================================
32 # Classes de services non utilisateur
34 class _ReportPartM__(object):
36 Store and retrieve the data for C: internal class
38 def __init__(self, part="default"):
39 self.__part = str(part)
43 def append(self, content, style="p", position=-1):
45 self.__styles.append(style)
46 self.__content.append(content)
48 self.__styles.insert(position, style)
49 self.__content.insert(position, content)
55 def get_content(self):
58 class _ReportM__(object):
60 Store and retrieve the data for C: internal class
62 def __init__(self, part='default'):
64 self.__document[part] = _ReportPartM__(part)
66 def append(self, content, style="p", position=-1, part='default'):
67 if part not in self.__document:
68 self.__document[part] = _ReportPartM__(part)
69 self.__document[part].append(content, style, position)
73 op = list(self.__document.keys()) ; op.sort()
74 return [self.__document[k].get_styles() for k in op]
76 def get_content(self):
77 op = list(self.__document.keys()) ; op.sort()
78 return [self.__document[k].get_content() for k in op]
83 class __ReportC__(object):
85 Get user commands, update M and V: user intertace to create the report
89 def append(self, content="", style="p", position=-1, part="default"):
90 return self.m.append(content, style, position, part)
93 st = self.m.get_styles()
94 ct = self.m.get_content()
100 class __ReportV__(object):
102 Interact with user and C: template for reports
105 default_filename="report.txt"
107 def __init__(self, c):
110 def save(self, filename=None):
112 filename = self.default_filename
113 _filename = os.path.abspath(filename)
116 fid = open(_filename, 'w')
119 return filename, _filename
122 return self.c.retrieve()
131 # ==============================================================================
132 # Classes d'interface utilisateur : ReportViewIn*, ReportStorage
133 # Tags de structure : (title, h1, h2, h3, p, uli, oli, <b></b>, <i></i>)
135 class ReportViewInHtml(__ReportV__):
140 default_filename="report.html"
147 st, ct = self.retrieve()
148 inuLi, inoLi = False, False
149 pg = "<html>\n<head>"
150 pg += "\n<title>Report in HTML</title>"
151 pg += "\n</head>\n<body>"
152 for k,ps in enumerate(st):
155 ii = ps.index("title")
157 pg += "%s\n%s\n%s"%('<hr noshade><h1 align="center">',title,'</h1><hr noshade>')
160 for i,s in enumerate(ps):
162 if s == "uli" and not inuLi:
165 elif s == "oli" and not inoLi:
168 elif s != "uli" and inuLi:
171 elif s != "oli" and inoLi:
177 if s == t: s = self.tags[t]
178 pg += "\n<%s>%s</%s>"%(s,c,s)
179 pg += "\n</body>\n</html>"
182 class ReportViewInRst(__ReportV__):
187 default_filename="report.rst"
207 st, ct = self.retrieve()
208 inuLi, inoLi = False, False
210 for k,ps in enumerate(st):
213 ii = ps.index("title")
215 pg += "%s\n%s\n%s"%("="*80,title,"="*80)
218 for i,s in enumerate(ps):
220 if s == "uli" and not inuLi:
223 elif s == "oli" and not inoLi:
226 elif s != "uli" and inuLi:
229 elif s != "oli" and inoLi:
232 for t in self.translation:
233 c = c.replace(t,self.translation[t])
234 if s in self.titles.keys():
235 pg += "\n%s\n%s\n%s"%(self.titles[s][0]*len(c),c,self.titles[s][1]*len(c))
236 elif s in self.tags.keys():
237 pg += "%s%s%s"%(self.tags[s][0],c,self.tags[s][1])
241 class ReportViewInPlainTxt(__ReportV__):
246 default_filename="report.txt"
266 st, ct = self.retrieve()
267 inuLi, inoLi = False, False
269 for k,ps in enumerate(st):
272 ii = ps.index("title")
274 pg += "%s\n%s\n%s"%("="*80,title,"="*80)
277 for i,s in enumerate(ps):
279 if s == "uli" and not inuLi:
281 elif s == "oli" and not inoLi:
283 elif s != "uli" and inuLi:
285 elif s != "oli" and inoLi:
287 for t in self.translation:
288 c = c.replace(t,self.translation[t])
289 if s in self.titles.keys():
290 pg += "\n%s\n%s\n%s"%(self.titles[s][0]*len(c),c,self.titles[s][1]*len(c))
291 elif s in self.tags.keys():
292 pg += "\n%s%s%s"%(self.tags[s][0],c,self.tags[s][1])
297 # Interface utilisateur de stockage des informations
298 ReportStorage = __ReportC__
300 # ==============================================================================
301 if __name__ == "__main__":
302 print('\n AUTODIAGNOSTIC\n')