@@ -11,6 +11,7 @@ import os
1111import re
1212import sys
1313import subprocess
14+ import time
1415
1516from collections import Counter
1617from pygments import highlight
@@ -470,7 +471,7 @@ def blame_lookup(blame_data, line):
470471 return next ((data for start , end , data in blame_data if line >= start and line < end ), {})
471472
472473
473- def tr_str (td_th , line , id , cwe , severity , message , author , author_mail , date , add_author , tr_class = None , htmlfile = None , message_class = None ):
474+ def tr_str (td_th , line , id , cwe , severity , message , timestamp , author , author_mail , date , add_author , tr_class = None , htmlfile = None , message_class = None ):
474475 ret = ''
475476 if htmlfile :
476477 ret += '<%s><a href="%s#line-%d">%d</a></%s>' % (td_th , htmlfile , line , line , td_th )
@@ -485,6 +486,9 @@ def tr_str(td_th, line, id, cwe, severity, message, author, author_mail, date, a
485486 message_attribute = ''
486487 ret += '<%s%s>%s</%s>' % (td_th , message_attribute , html_escape (message ), td_th )
487488
489+ if timestamp :
490+ ret += '<%s>%s</%s>' % (td_th , timestamp , td_th )
491+
488492 for field in add_author :
489493 if field == 'name' :
490494 ret += '<%s>%s</%s>' % (td_th , html_escape (author ), td_th )
@@ -556,6 +560,7 @@ class CppCheckHandler(XmlContentHandler):
556560 self .errors = []
557561 self .version = '1'
558562 self .versionCppcheck = ''
563+ self .timestamp = ''
559564
560565 def startElement (self , name , attributes ):
561566 if name == 'results' :
@@ -579,6 +584,7 @@ class CppCheckHandler(XmlContentHandler):
579584 }],
580585 'id' : attributes ['id' ],
581586 'severity' : attributes ['severity' ],
587+ 'timestamp' : self .timestamp ,
582588 'msg' : attributes ['msg' ]
583589 })
584590
@@ -592,6 +598,7 @@ class CppCheckHandler(XmlContentHandler):
592598 'line' : 0 ,
593599 'id' : attributes ['id' ],
594600 'severity' : attributes ['severity' ],
601+ 'timestamp' : self .timestamp ,
595602 'msg' : attributes ['msg' ],
596603 'verbose' : attributes .get ('verbose' )
597604 }
@@ -694,6 +701,13 @@ def main() -> None:
694701 try :
695702 contentHandler = CppCheckHandler ()
696703 for fname in options .file or [sys .stdin ]:
704+ if options .file is not None :
705+ t = os .path .getmtime (fname )
706+ else :
707+ t = time .time ()
708+ t_s = time .ctime (t )
709+ if t_s is not None :
710+ contentHandler .timestamp = t_s
697711 xml_parse (fname , contentHandler )
698712 except (XmlParseException , ValueError ) as msg :
699713 print ('Failed to parse cppcheck xml file: %s' % msg )
@@ -865,7 +879,7 @@ def main() -> None:
865879 output_file .write ('\n <table class=\" summaryTable\" >' )
866880 output_file .write (
867881 '\n %s' %
868- tr_str ('th' , 'Line' , 'Id' , 'CWE' , 'Severity' , 'Message' , 'Author' , 'Author mail' , 'Date (DD/MM/YYYY)' , add_author = add_author_information ))
882+ tr_str ('th' , 'Line' , 'Id' , 'CWE' , 'Severity' , 'Message' , 'Timestamp' , ' Author' , 'Author mail' , 'Date (DD/MM/YYYY)' , add_author = add_author_information ))
869883
870884 for filename , data in sorted (files .items ()):
871885 file_error = filename in decode_errors or filename .endswith ('*' )
@@ -905,7 +919,7 @@ def main() -> None:
905919
906920 output_file .write (
907921 '\n %s' %
908- tr_str ('td' , line , error ["id" ], cwe_url , error ["severity" ], error ["msg" ],
922+ tr_str ('td' , line , error ["id" ], cwe_url , error ["severity" ], error ["msg" ], error [ "timestamp" ],
909923 git_blame_dict .get ('author' , 'Unknown' ), git_blame_dict .get ('author-mail' , '---' ),
910924 git_blame_dict .get ('author-time' , '---' ),
911925 tr_class = to_css_selector (error ["id" ]) + ' sev_' + error ["severity" ] + ' issue' ,
0 commit comments