donate-cpu-server.py: Fix PEP 8 and other warnings (#1578)
There should be no functional changes. Tested locally.
This commit is contained in:
parent
f673d552cb
commit
1dc5ff022e
|
@ -8,16 +8,17 @@ import re
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
OLD_VERSION = '1.86'
|
OLD_VERSION = '1.86'
|
||||||
|
|
||||||
|
|
||||||
def strDateTime():
|
def strDateTime():
|
||||||
d = datetime.date.strftime(datetime.datetime.now().date(), '%Y-%m-%d')
|
d = datetime.date.strftime(datetime.datetime.now().date(), '%Y-%m-%d')
|
||||||
t = datetime.time.strftime(datetime.datetime.now().time(), '%H:%M')
|
t = datetime.time.strftime(datetime.datetime.now().time(), '%H:%M')
|
||||||
return d + ' ' + t
|
return d + ' ' + t
|
||||||
|
|
||||||
|
|
||||||
def overviewReport():
|
def overviewReport():
|
||||||
html = '<html><head><title>daca@home</title></head><body>\n'
|
html = '<html><head><title>daca@home</title></head><body>\n'
|
||||||
html += '<h1>daca@home</h1>\n'
|
html += '<h1>daca@home</h1>\n'
|
||||||
|
@ -29,13 +30,14 @@ def overviewReport():
|
||||||
html += '</body></html>'
|
html += '</body></html>'
|
||||||
return html
|
return html
|
||||||
|
|
||||||
def fmt(a,b,c,d,e):
|
|
||||||
|
def fmt(a, b, c, d, e):
|
||||||
ret = a + ' '
|
ret = a + ' '
|
||||||
while len(ret)<10:
|
while len(ret) < 10:
|
||||||
ret += ' '
|
ret += ' '
|
||||||
if len(ret) == 10:
|
if len(ret) == 10:
|
||||||
ret += b[:10] + ' '
|
ret += b[:10] + ' '
|
||||||
while len(ret)<21:
|
while len(ret) < 21:
|
||||||
ret += ' '
|
ret += ' '
|
||||||
ret += b[-5:] + ' '
|
ret += b[-5:] + ' '
|
||||||
while len(ret) < 32-len(c):
|
while len(ret) < 32-len(c):
|
||||||
|
@ -54,7 +56,7 @@ def fmt(a,b,c,d,e):
|
||||||
def latestReport(latestResults):
|
def latestReport(latestResults):
|
||||||
html = '<html><head><title>Latest daca@home results</title></head><body>\n'
|
html = '<html><head><title>Latest daca@home results</title></head><body>\n'
|
||||||
html += '<h1>Latest daca@home results</h1>'
|
html += '<h1>Latest daca@home results</h1>'
|
||||||
html += '<pre>\n<b>' + fmt('Package','Date Time ',OLD_VERSION,'Head','Diff') + '</b>\n'
|
html += '<pre>\n<b>' + fmt('Package', 'Date Time ', OLD_VERSION, 'Head', 'Diff') + '</b>\n'
|
||||||
|
|
||||||
# Write report for latest results
|
# Write report for latest results
|
||||||
for filename in latestResults:
|
for filename in latestResults:
|
||||||
|
@ -63,10 +65,10 @@ def latestReport(latestResults):
|
||||||
package = filename[filename.rfind('/')+1:]
|
package = filename[filename.rfind('/')+1:]
|
||||||
|
|
||||||
datestr = ''
|
datestr = ''
|
||||||
count = ['0','0']
|
count = ['0', '0']
|
||||||
lost = 0
|
lost = 0
|
||||||
added = 0
|
added = 0
|
||||||
for line in open(filename,'rt'):
|
for line in open(filename, 'rt'):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
current_year = datetime.date.today().year
|
current_year = datetime.date.today().year
|
||||||
if line.startswith(str(current_year) + '-') or line.startswith(str(current_year - 1) + '-'):
|
if line.startswith(str(current_year) + '-') or line.startswith(str(current_year - 1) + '-'):
|
||||||
|
@ -189,12 +191,12 @@ def diffReport(resultsPath):
|
||||||
continue
|
continue
|
||||||
messageId = line[line.rfind('[')+1:len(line)-1]
|
messageId = line[line.rfind('[')+1:len(line)-1]
|
||||||
|
|
||||||
if not messageId in out:
|
if messageId not in out:
|
||||||
out[messageId] = [0,0]
|
out[messageId] = [0, 0]
|
||||||
out[messageId][index] += 1
|
out[messageId][index] += 1
|
||||||
if uploadedToday:
|
if uploadedToday:
|
||||||
if not messageId in outToday:
|
if messageId not in outToday:
|
||||||
outToday[messageId] = [0,0]
|
outToday[messageId] = [0, 0]
|
||||||
outToday[messageId][index] += 1
|
outToday[messageId][index] += 1
|
||||||
|
|
||||||
html = '<html><head><title>Diff report</title></head><body>\n'
|
html = '<html><head><title>Diff report</title></head><body>\n'
|
||||||
|
@ -213,7 +215,7 @@ def diffMessageIdReport(resultPath, messageId):
|
||||||
for filename in sorted(glob.glob(resultPath + '/*')):
|
for filename in sorted(glob.glob(resultPath + '/*')):
|
||||||
url = None
|
url = None
|
||||||
diff = False
|
diff = False
|
||||||
for line in open(filename,'rt'):
|
for line in open(filename, 'rt'):
|
||||||
if line.startswith('ftp://'):
|
if line.startswith('ftp://'):
|
||||||
url = line
|
url = line
|
||||||
elif line == 'diff:\n':
|
elif line == 'diff:\n':
|
||||||
|
@ -236,7 +238,7 @@ def diffMessageIdTodayReport(resultPath, messageId):
|
||||||
url = None
|
url = None
|
||||||
diff = False
|
diff = False
|
||||||
firstLine = True
|
firstLine = True
|
||||||
for line in open(filename,'rt'):
|
for line in open(filename, 'rt'):
|
||||||
if firstLine:
|
if firstLine:
|
||||||
firstLine = False
|
firstLine = False
|
||||||
if not line.startswith(today):
|
if not line.startswith(today):
|
||||||
|
@ -340,7 +342,7 @@ def headMessageIdReport(resultPath, messageId):
|
||||||
for filename in sorted(glob.glob(resultPath + '/*')):
|
for filename in sorted(glob.glob(resultPath + '/*')):
|
||||||
url = None
|
url = None
|
||||||
headResults = False
|
headResults = False
|
||||||
for line in open(filename,'rt'):
|
for line in open(filename, 'rt'):
|
||||||
if line.startswith('ftp://'):
|
if line.startswith('ftp://'):
|
||||||
url = line
|
url = line
|
||||||
elif line.startswith('head results:'):
|
elif line.startswith('head results:'):
|
||||||
|
@ -365,7 +367,7 @@ def headMessageIdTodayReport(resultPath, messageId):
|
||||||
url = None
|
url = None
|
||||||
headResults = False
|
headResults = False
|
||||||
firstLine = True
|
firstLine = True
|
||||||
for line in open(filename,'rt'):
|
for line in open(filename, 'rt'):
|
||||||
if firstLine:
|
if firstLine:
|
||||||
firstLine = False
|
firstLine = False
|
||||||
if not line.startswith(today):
|
if not line.startswith(today):
|
||||||
|
@ -393,7 +395,7 @@ def timeReport(resultPath):
|
||||||
totalTime184 = 0.0
|
totalTime184 = 0.0
|
||||||
totalTimeHead = 0.0
|
totalTimeHead = 0.0
|
||||||
for filename in glob.glob(resultPath + '/*'):
|
for filename in glob.glob(resultPath + '/*'):
|
||||||
for line in open(filename,'rt'):
|
for line in open(filename, 'rt'):
|
||||||
if not line.startswith('elapsed-time:'):
|
if not line.startswith('elapsed-time:'):
|
||||||
continue
|
continue
|
||||||
splitline = line.strip().split()
|
splitline = line.strip().split()
|
||||||
|
@ -401,15 +403,16 @@ def timeReport(resultPath):
|
||||||
thead = float(splitline[1])
|
thead = float(splitline[1])
|
||||||
totalTime184 += t184
|
totalTime184 += t184
|
||||||
totalTimeHead += thead
|
totalTimeHead += thead
|
||||||
if t184>1 and t184*2 < thead:
|
if t184 > 1 and t184*2 < thead:
|
||||||
text += filename[len(resultPath)+1:] + ' ' + splitline[2] + ' ' + splitline[1] + '\n'
|
text += filename[len(resultPath)+1:] + ' ' + splitline[2] + ' ' + splitline[1] + '\n'
|
||||||
elif thead>1 and thead*2 < t184:
|
elif thead > 1 and thead*2 < t184:
|
||||||
text += filename[len(resultPath)+1:] + ' ' + splitline[2] + ' ' + splitline[1] + '\n'
|
text += filename[len(resultPath)+1:] + ' ' + splitline[2] + ' ' + splitline[1] + '\n'
|
||||||
break
|
break
|
||||||
|
|
||||||
text += '\nTotal time: ' + str(totalTime184) + ' ' + str(totalTimeHead)
|
text += '\nTotal time: ' + str(totalTime184) + ' ' + str(totalTimeHead)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def sendAll(connection, data):
|
def sendAll(connection, data):
|
||||||
while data:
|
while data:
|
||||||
num = connection.send(data)
|
num = connection.send(data)
|
||||||
|
@ -485,7 +488,7 @@ class HttpClientThread(Thread):
|
||||||
print('HTTP/1.1 404 Not Found')
|
print('HTTP/1.1 404 Not Found')
|
||||||
self.connection.send('HTTP/1.1 404 Not Found\r\n\r\n')
|
self.connection.send('HTTP/1.1 404 Not Found\r\n\r\n')
|
||||||
else:
|
else:
|
||||||
f = open(filename,'rt')
|
f = open(filename, 'rt')
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
httpGetResponse(self.connection, data, 'text/plain')
|
httpGetResponse(self.connection, data, 'text/plain')
|
||||||
|
@ -520,18 +523,18 @@ def server(server_address_port, packages, packageIndex, resultPath):
|
||||||
if cmd.find('\n') < 1:
|
if cmd.find('\n') < 1:
|
||||||
continue
|
continue
|
||||||
firstLine = cmd[:cmd.find('\n')]
|
firstLine = cmd[:cmd.find('\n')]
|
||||||
if re.match('[a-zA-Z0-9./ ]+',firstLine) is None:
|
if re.match('[a-zA-Z0-9./ ]+', firstLine) is None:
|
||||||
connection.close()
|
connection.close()
|
||||||
continue;
|
continue
|
||||||
if cmd.startswith('GET /'):
|
if cmd.startswith('GET /'):
|
||||||
newThread = HttpClientThread(connection, cmd, resultPath, latestResults)
|
newThread = HttpClientThread(connection, cmd, resultPath, latestResults)
|
||||||
newThread.start()
|
newThread.start()
|
||||||
elif cmd=='GetCppcheckVersions\n':
|
elif cmd == 'GetCppcheckVersions\n':
|
||||||
reply = 'head ' + OLD_VERSION
|
reply = 'head ' + OLD_VERSION
|
||||||
print('[' + strDateTime() + '] GetCppcheckVersions: ' + reply)
|
print('[' + strDateTime() + '] GetCppcheckVersions: ' + reply)
|
||||||
connection.send(reply)
|
connection.send(reply)
|
||||||
connection.close()
|
connection.close()
|
||||||
elif cmd=='get\n':
|
elif cmd == 'get\n':
|
||||||
pkg = packages[packageIndex].strip()
|
pkg = packages[packageIndex].strip()
|
||||||
packages[packageIndex] = pkg
|
packages[packageIndex] = pkg
|
||||||
packageIndex += 1
|
packageIndex += 1
|
||||||
|
@ -569,7 +572,7 @@ def server(server_address_port, packages, packageIndex, resultPath):
|
||||||
print('[' + strDateTime() + '] write:' + url)
|
print('[' + strDateTime() + '] write:' + url)
|
||||||
|
|
||||||
# save data
|
# save data
|
||||||
res = re.match(r'ftp://.*pool/main/[^/]+/([^/]+)/[^/]*tar.gz',url)
|
res = re.match(r'ftp://.*pool/main/[^/]+/([^/]+)/[^/]*tar.gz', url)
|
||||||
if res is None:
|
if res is None:
|
||||||
print('results not written. res is None.')
|
print('results not written. res is None.')
|
||||||
continue
|
continue
|
||||||
|
@ -592,6 +595,7 @@ def server(server_address_port, packages, packageIndex, resultPath):
|
||||||
print('[' + strDateTime() + '] invalid command: ' + firstLine)
|
print('[' + strDateTime() + '] invalid command: ' + firstLine)
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
workPath = os.path.expanduser('~/daca@home')
|
workPath = os.path.expanduser('~/daca@home')
|
||||||
os.chdir(workPath)
|
os.chdir(workPath)
|
||||||
|
|
Loading…
Reference in New Issue