88import datetime
99import time
1010from threading import Thread
11- import subprocess
1211import sys
1312
1413OLD_VERSION = '1.86'
1514
15+
1616def strDateTime ():
1717 d = datetime .date .strftime (datetime .datetime .now ().date (), '%Y-%m-%d' )
1818 t = datetime .time .strftime (datetime .datetime .now ().time (), '%H:%M' )
1919 return d + ' ' + t
2020
21+
2122def overviewReport ():
2223 html = '<html><head><title>daca@home</title></head><body>\n '
2324 html += '<h1>daca@home</h1>\n '
@@ -29,13 +30,14 @@ def overviewReport():
2930 html += '</body></html>'
3031 return html
3132
32- def fmt (a ,b ,c ,d ,e ):
33+
34+ def fmt (a , b , c , d , e ):
3335 ret = a + ' '
34- while len (ret )< 10 :
36+ while len (ret ) < 10 :
3537 ret += ' '
3638 if len (ret ) == 10 :
3739 ret += b [:10 ] + ' '
38- while len (ret )< 21 :
40+ while len (ret ) < 21 :
3941 ret += ' '
4042 ret += b [- 5 :] + ' '
4143 while len (ret ) < 32 - len (c ):
@@ -54,7 +56,7 @@ def fmt(a,b,c,d,e):
5456def latestReport (latestResults ):
5557 html = '<html><head><title>Latest daca@home results</title></head><body>\n '
5658 html += '<h1>Latest daca@home results</h1>'
57- html += '<pre>\n <b>' + fmt ('Package' ,'Date Time ' ,OLD_VERSION ,'Head' ,'Diff' ) + '</b>\n '
59+ html += '<pre>\n <b>' + fmt ('Package' , 'Date Time ' , OLD_VERSION , 'Head' , 'Diff' ) + '</b>\n '
5860
5961 # Write report for latest results
6062 for filename in latestResults :
@@ -63,10 +65,10 @@ def latestReport(latestResults):
6365 package = filename [filename .rfind ('/' )+ 1 :]
6466
6567 datestr = ''
66- count = ['0' ,'0' ]
68+ count = ['0' , '0' ]
6769 lost = 0
6870 added = 0
69- for line in open (filename ,'rt' ):
71+ for line in open (filename , 'rt' ):
7072 line = line .strip ()
7173 current_year = datetime .date .today ().year
7274 if line .startswith (str (current_year ) + '-' ) or line .startswith (str (current_year - 1 ) + '-' ):
@@ -189,12 +191,12 @@ def diffReport(resultsPath):
189191 continue
190192 messageId = line [line .rfind ('[' )+ 1 :len (line )- 1 ]
191193
192- if not messageId in out :
193- out [messageId ] = [0 ,0 ]
194+ if messageId not in out :
195+ out [messageId ] = [0 , 0 ]
194196 out [messageId ][index ] += 1
195197 if uploadedToday :
196- if not messageId in outToday :
197- outToday [messageId ] = [0 ,0 ]
198+ if messageId not in outToday :
199+ outToday [messageId ] = [0 , 0 ]
198200 outToday [messageId ][index ] += 1
199201
200202 html = '<html><head><title>Diff report</title></head><body>\n '
@@ -213,7 +215,7 @@ def diffMessageIdReport(resultPath, messageId):
213215 for filename in sorted (glob .glob (resultPath + '/*' )):
214216 url = None
215217 diff = False
216- for line in open (filename ,'rt' ):
218+ for line in open (filename , 'rt' ):
217219 if line .startswith ('ftp://' ):
218220 url = line
219221 elif line == 'diff:\n ' :
@@ -236,7 +238,7 @@ def diffMessageIdTodayReport(resultPath, messageId):
236238 url = None
237239 diff = False
238240 firstLine = True
239- for line in open (filename ,'rt' ):
241+ for line in open (filename , 'rt' ):
240242 if firstLine :
241243 firstLine = False
242244 if not line .startswith (today ):
@@ -340,7 +342,7 @@ def headMessageIdReport(resultPath, messageId):
340342 for filename in sorted (glob .glob (resultPath + '/*' )):
341343 url = None
342344 headResults = False
343- for line in open (filename ,'rt' ):
345+ for line in open (filename , 'rt' ):
344346 if line .startswith ('ftp://' ):
345347 url = line
346348 elif line .startswith ('head results:' ):
@@ -365,7 +367,7 @@ def headMessageIdTodayReport(resultPath, messageId):
365367 url = None
366368 headResults = False
367369 firstLine = True
368- for line in open (filename ,'rt' ):
370+ for line in open (filename , 'rt' ):
369371 if firstLine :
370372 firstLine = False
371373 if not line .startswith (today ):
@@ -393,23 +395,24 @@ def timeReport(resultPath):
393395 totalTime184 = 0.0
394396 totalTimeHead = 0.0
395397 for filename in glob .glob (resultPath + '/*' ):
396- for line in open (filename ,'rt' ):
398+ for line in open (filename , 'rt' ):
397399 if not line .startswith ('elapsed-time:' ):
398400 continue
399401 splitline = line .strip ().split ()
400402 t184 = float (splitline [2 ])
401403 thead = float (splitline [1 ])
402404 totalTime184 += t184
403405 totalTimeHead += thead
404- if t184 > 1 and t184 * 2 < thead :
406+ if t184 > 1 and t184 * 2 < thead :
405407 text += filename [len (resultPath )+ 1 :] + ' ' + splitline [2 ] + ' ' + splitline [1 ] + '\n '
406- elif thead > 1 and thead * 2 < t184 :
408+ elif thead > 1 and thead * 2 < t184 :
407409 text += filename [len (resultPath )+ 1 :] + ' ' + splitline [2 ] + ' ' + splitline [1 ] + '\n '
408410 break
409411
410412 text += '\n Total time: ' + str (totalTime184 ) + ' ' + str (totalTimeHead )
411413 return text
412414
415+
413416def sendAll (connection , data ):
414417 while data :
415418 num = connection .send (data )
@@ -485,7 +488,7 @@ def run(self):
485488 print ('HTTP/1.1 404 Not Found' )
486489 self .connection .send ('HTTP/1.1 404 Not Found\r \n \r \n ' )
487490 else :
488- f = open (filename ,'rt' )
491+ f = open (filename , 'rt' )
489492 data = f .read ()
490493 f .close ()
491494 httpGetResponse (self .connection , data , 'text/plain' )
@@ -520,18 +523,18 @@ def server(server_address_port, packages, packageIndex, resultPath):
520523 if cmd .find ('\n ' ) < 1 :
521524 continue
522525 firstLine = cmd [:cmd .find ('\n ' )]
523- if re .match ('[a-zA-Z0-9./ ]+' ,firstLine ) is None :
526+ if re .match ('[a-zA-Z0-9./ ]+' , firstLine ) is None :
524527 connection .close ()
525- continue ;
528+ continue
526529 if cmd .startswith ('GET /' ):
527530 newThread = HttpClientThread (connection , cmd , resultPath , latestResults )
528531 newThread .start ()
529- elif cmd == 'GetCppcheckVersions\n ' :
532+ elif cmd == 'GetCppcheckVersions\n ' :
530533 reply = 'head ' + OLD_VERSION
531534 print ('[' + strDateTime () + '] GetCppcheckVersions: ' + reply )
532535 connection .send (reply )
533536 connection .close ()
534- elif cmd == 'get\n ' :
537+ elif cmd == 'get\n ' :
535538 pkg = packages [packageIndex ].strip ()
536539 packages [packageIndex ] = pkg
537540 packageIndex += 1
@@ -569,7 +572,7 @@ def server(server_address_port, packages, packageIndex, resultPath):
569572 print ('[' + strDateTime () + '] write:' + url )
570573
571574 # save data
572- res = re .match (r'ftp://.*pool/main/[^/]+/([^/]+)/[^/]*tar.gz' ,url )
575+ res = re .match (r'ftp://.*pool/main/[^/]+/([^/]+)/[^/]*tar.gz' , url )
573576 if res is None :
574577 print ('results not written. res is None.' )
575578 continue
@@ -592,6 +595,7 @@ def server(server_address_port, packages, packageIndex, resultPath):
592595 print ('[' + strDateTime () + '] invalid command: ' + firstLine )
593596 connection .close ()
594597
598+
595599if __name__ == "__main__" :
596600 workPath = os .path .expanduser ('~/daca@home' )
597601 os .chdir (workPath )
0 commit comments