@@ -11,6 +11,7 @@ import os
11
11
import re
12
12
import sys
13
13
import subprocess
14
+ import time
14
15
15
16
from collections import Counter
16
17
from pygments import highlight
@@ -470,7 +471,7 @@ def blame_lookup(blame_data, line):
470
471
return next ((data for start , end , data in blame_data if line >= start and line < end ), {})
471
472
472
473
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 ):
474
475
ret = ''
475
476
if htmlfile :
476
477
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
485
486
message_attribute = ''
486
487
ret += '<%s%s>%s</%s>' % (td_th , message_attribute , html_escape (message ), td_th )
487
488
489
+ if timestamp :
490
+ ret += '<%s>%s</%s>' % (td_th , timestamp , td_th )
491
+
488
492
for field in add_author :
489
493
if field == 'name' :
490
494
ret += '<%s>%s</%s>' % (td_th , html_escape (author ), td_th )
@@ -556,6 +560,7 @@ class CppCheckHandler(XmlContentHandler):
556
560
self .errors = []
557
561
self .version = '1'
558
562
self .versionCppcheck = ''
563
+ self .timestamp = ''
559
564
560
565
def startElement (self , name , attributes ):
561
566
if name == 'results' :
@@ -579,6 +584,7 @@ class CppCheckHandler(XmlContentHandler):
579
584
}],
580
585
'id' : attributes ['id' ],
581
586
'severity' : attributes ['severity' ],
587
+ 'timestamp' : self .timestamp ,
582
588
'msg' : attributes ['msg' ]
583
589
})
584
590
@@ -592,6 +598,7 @@ class CppCheckHandler(XmlContentHandler):
592
598
'line' : 0 ,
593
599
'id' : attributes ['id' ],
594
600
'severity' : attributes ['severity' ],
601
+ 'timestamp' : self .timestamp ,
595
602
'msg' : attributes ['msg' ],
596
603
'verbose' : attributes .get ('verbose' )
597
604
}
@@ -694,6 +701,13 @@ def main() -> None:
694
701
try :
695
702
contentHandler = CppCheckHandler ()
696
703
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
697
711
xml_parse (fname , contentHandler )
698
712
except (XmlParseException , ValueError ) as msg :
699
713
print ('Failed to parse cppcheck xml file: %s' % msg )
@@ -865,7 +879,7 @@ def main() -> None:
865
879
output_file .write ('\n <table class=\" summaryTable\" >' )
866
880
output_file .write (
867
881
'\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 ))
869
883
870
884
for filename , data in sorted (files .items ()):
871
885
file_error = filename in decode_errors or filename .endswith ('*' )
@@ -905,7 +919,7 @@ def main() -> None:
905
919
906
920
output_file .write (
907
921
'\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" ],
909
923
git_blame_dict .get ('author' , 'Unknown' ), git_blame_dict .get ('author-mail' , '---' ),
910
924
git_blame_dict .get ('author-time' , '---' ),
911
925
tr_class = to_css_selector (error ["id" ]) + ' sev_' + error ["severity" ] + ' issue' ,
0 commit comments