/usr/share/pyshared/asrun/histor.py is in code-aster-run 1.13.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | # -*- coding: utf-8 -*-
# ==============================================================================
# COPYRIGHT (C) 1991 - 2003 EDF R&D WWW.CODE-ASTER.ORG
# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
# (AT YOUR OPTION) ANY LATER VERSION.
#
# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
# WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
# GENERAL PUBLIC LICENSE FOR MORE DETAILS.
#
# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
# ==============================================================================
"""
Define classes representing an histor file from issues objects.
"""
import os
import re
import datetime
from xml.sax import saxutils
from types import StringType, FloatType, IntType, LongType, ListType, TupleType
from asrun.common.i18n import _
from asrun.mystring import indent, convert
from asrun.common.utils import now
NumberTypes = (FloatType, IntType, LongType)
EnumTypes = (ListType, TupleType)
french_date_fmt = '%d/%m/%Y'
class HistorError(Exception):
"""Exception for this module
"""
def date_inverse(date, sep='/'):
"""Reverse the representation of a date : dd/mm/YY <---> YY/mm/dd.
"""
if isinstance(date, datetime.datetime) or type(date).__name__ == 'DateTime':
return date.strftime(french_date_fmt)
else:
# suppose `date` is in mysql format
l_d = str(date).split(sep)
l_d.reverse()
return sep.join(l_d)
class HISTOR:
"""Class representing a "standard" histor i.e. as a text file.
"""
CR = os.linesep
format = 'text'
header = ''
footer = ''
separ = '-'*80+CR
seprep = CR*2
mask = separ + """RESTITUTION FICHE %(id)06d DU %(date_emission)s
TYPE %(type_name)s concernant %(produit_name)s (VERSION %(version_name)s)
%(tma)sTITRE
%(_title)s
FONCTIONNALITE
%(reponse)s
RESU_FAUX_VERSION_EXPLOITATION : %(_fauxVexpl)s
RESU_FAUX_VERSION_DEVELOPPEMENT : %(_fauxVdev)s
RESTITUTION_VERSION_EXPLOITATION : %(_corrVexpl)s
RESTITUTION_VERSION_DEVELOPPEMENT : %(_corrVdev)s
IMPACT_DOCUMENTAIRE : %(_impactDoc)s
VALIDATION
%(_validation)s
%(fix_in)s%(nbjours)s"""
mask_nbjours = "NB_JOURS_TRAV : %s" + CR
mask_tma = 'TMA : %s' + CR
mask_restit = "DEJA RESTITUE DANS : %s" + CR
mask_user_begin = separ + \
'--- AUTEUR %(_loginaster)-12s %(_realname)-20s' + CR*2
mask_user_end = separ + CR
def __init__(self, **kargs):
"""Initialize histor object.
"""
self.l_bloc = []
def clean_dict(self, dico):
"""Keep only elements of dict of type string and number,
and escape all HTML characters.
"""
newd = {}
for k, v in dico.items():
if k == 'CR' or type(v) is StringType or type(v) in NumberTypes:
newd[k] = v
elif v is None:
newd[k] = ''
return newd
def DictIssue(self, issue, l_rep=None):
"""Represent an issue as a dict object.
l_rep : list of the content of messages to include.
"""
# 0. store issue infos
dico = issue.values.copy()
# _version is not always defined
try:
dico['version_name'] = issue['_version'].GetPrimValue()
except AttributeError:
dico['version_name'] = ''
dico.update({
'CR' : self.CR,
'type_name' : issue['_type'].GetPrimValue(),
'produit_name' : issue['_produit'].GetPrimValue(),
'reponse' : '',
'tma' : '',
'nbjours' : '',
'fix_in' : '',
'date_emission' : date_inverse(issue['_creation']),
})
# 1a. list of messages or last message
if l_rep != None and len(l_rep) > 0:
if not type(l_rep) in EnumTypes:
l_rep = [l_rep]
l_rep = [indent(convert(s), ' ') for s in l_rep]
dico['reponse'] = self.seprep.join(l_rep)
else:
d_msg = issue.GetLinks()
imsg = max(d_msg.keys())
dico['reponse'] = d_msg[imsg]['_summary'] + '...'
# 1b. text fields
for k in ('_title', '_validation'):
dico[k] = convert(dico[k])
# 2. champs OUI/NON
for key in ('_corrVdev', '_corrVexpl'):
if dico[key] != None:
dico[key] = 'OUI'
else:
dico[key] = 'NON'
for key in ('_fauxVdev', '_fauxVexpl'):
if dico[key] != None:
dico[key] = 'OUI DEPUIS : %s' % dico[key]
else:
dico[key] = 'NON'
# 3. "pour le compte de" field
if issue['_intervenant'] != None:
dico['tma'] = self.mask_tma % issue['_intervenant'].GetPrimValue()
# 4. show '_nbJours' field if no intervenant
if issue['_intervenant'] == None:
dico['nbjours'] = self.mask_nbjours % issue['_nbJours']
# 5. fixed in...
val = ""
if issue['_verCorrVexpl'] != None:
val += issue['_verCorrVexpl']
if issue['_verCorrVdev'] != None:
if val:
val += ", "
val += issue['_verCorrVdev']
if val:
dico['fix_in'] = self.mask_restit % val
# 6. keep only strings
dico = self.clean_dict(dico)
return dico
def AddIssue(self, issue, l_rep=None):
"""Add a bloc for an issue.
"""
self.l_bloc.append(self.mask % self.DictIssue(issue, l_rep))
def DictUser(self, user):
"""Represent an user as a dict object.
"""
# required fields for formatting
dico = {
'_loginaster' : _(u"unknown"),
'_realname' : _(u"unknown"),
}
if hasattr(user, 'values'):
dico = self.clean_dict(user.values.copy())
dico['CR'] = self.CR
return dico
def BeginUser(self, user):
"""Start a bloc to identify the user who answers following issues.
"""
self.l_bloc.append(self.mask_user_begin % self.DictUser(user))
def EndUser(self, user):
"""End the bloc.
"""
self.l_bloc.append(self.mask_user_end % self.DictUser(user))
def __repr__(self):
"""Modify representation.
"""
return self._getrepr()
def _getrepr(self):
"""Representation of the histor object.
"""
txt = [self.header]
txt.extend(self.l_bloc)
txt.append(self.footer)
return ''.join([convert(s) for s in txt])
class HISTOR_HTML(HISTOR):
"""Class representing a histor in HTML format.
"""
CR = '<br />'
format = 'html'
header = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>histor - Code_Aster</title>
</head>
<style type="text/css">
body {
font-family: monospace;
text-align: justify;
}
.fiche {
font-style: normal;
line-height: 1.5em ;
}
.par {
margin-left: 50px ;
line-height: 1.3em ;
}
.enteteuser {
font-weight: bold;
text-align: center;
}
</style>
<body>
"""
footer = """</body>
</html>
"""
separ = '<hr />'
mask = separ + """
<!-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -->
<div class="fiche">
RESTITUTION FICHE <a href="%(url_issue)s">%(id)06d</a> DU %(date_emission)s%(CR)s
TYPE %(type_name)s concernant %(produit_name)s (VERSION %(version_name)s)%(CR)s
%(tma)s%(CR)sTITRE
<div class="par">
%(_title)s
</div>
FONCTIONNALITE
<div class="par">
%(reponse)s
</div>
RESU_FAUX_VERSION_EXPLOITATION : %(_fauxVexpl)s%(CR)s
RESU_FAUX_VERSION_DEVELOPPEMENT : %(_fauxVdev)s%(CR)s
RESTITUTION_VERSION_EXPLOITATION : %(_corrVexpl)s%(CR)s
RESTITUTION_VERSION_DEVELOPPEMENT : %(_corrVdev)s%(CR)s
IMPACT_DOCUMENTAIRE : %(_impactDoc)s%(CR)s
VALIDATION
<div class="par">
%(_validation)s
</div>
%(fix_in)s%(CR)s%(nbjours)s%(CR)s</div>
"""
mask_user_begin = """
<!-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -->
%(CR)s
<p class="enteteuser">
AUTEUR %(_loginaster)s %(_realname)s
</p>
"""
mask_nbjours = "NB_JOURS_TRAV : %s"
mask_tma = 'TMA : %s'
mask_restit = "DEJA RESTITUE DANS : %s"
mask_user_end = separ + CR
def __init__(self, **kargs):
"""Initialize histor object.
"""
HISTOR.__init__(self)
# specific arguments
self.server_url = kargs.get('url', None)
self.fmt_url_issue = '%s/issue%%s' % saxutils.escape(self.server_url)
def clean_dict(self, dico):
"""Keep only elements of dict of type string and number,
and escape all HTML characters.
"""
newd = {}
for k, v in dico.items():
if k == 'CR' or type(v) in NumberTypes:
newd[k] = v
elif type(v) is StringType:
newd[k] = saxutils.escape(str(v))
elif v is None:
newd[k] = ''
return newd
def DictIssue(self, issue, l_rep=None):
"""Represent an issue as a dict object.
"""
dico = HISTOR.DictIssue(self, issue, l_rep)
# specific fields
dico['url_issue'] = self.fmt_url_issue % issue['id']
# multi-lines fields
for k in ('reponse',):
dico[k] = dico[k].replace(os.linesep, self.CR)
return dico
class HISTOR_FSQ(HISTOR):
"""Class representing issues for quality purpose.
"""
CR = os.linesep
format = 'fsq'
separ = CR
mask = separ + """Fiche %(id)d : %(_title)s
%(reponse)s
Risque de résultats faux depuis la version : %(_fauxVexpl)s %(_fauxVdev)s
"""
mask_user_begin = ""
mask_user_end = ""
def DictIssue(self, issue, l_rep=None):
"""Represent an issue as a dict object.
"""
dico = HISTOR.DictIssue(self, issue, l_rep)
# clean response
for k in ('reponse',):
dico[k] = re.sub(' +', ' ', dico[k])
dico[k] = dico[k].strip()
return dico
def InitHistor(format='text', **kargs):
"""Return a histor object according to `format`.
"""
if format == 'text':
return HISTOR(**kargs)
elif format == 'html':
return HISTOR_HTML(**kargs)
elif format == 'fsq':
return HISTOR_FSQ(**kargs)
else:
raise HistorError, _(u'Unknown histor format : %s') % str(format)
|