"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tools/donate-cpu-server.py" between
cppcheck-1.86.tar.gz and cppcheck-1.87.tar.gz

About: Cppcheck is a static analysis tool for C/C++ code. It checks for memory leaks, mismatching allocation-deallocation, buffer overrun, and many more.

donate-cpu-server.py  (cppcheck-1.86):donate-cpu-server.py  (cppcheck-1.87)
# Server for 'donate-cpu.py' # Server for 'donate-cpu.py'
import glob import glob
import os import os
import socket import socket
import re import re
import datetime import datetime
import time import time
from threading import Thread from threading import Thread
import subprocess
import sys import sys
import urllib
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'
html += '<a href="crash">Crash report</a><br>\n' html += '<a href="crash.html">Crash report</a><br>\n'
html += '<a href="diff">Diff report</a><br>\n' html += '<a href="diff.html">Diff report</a><br>\n'
html += '<a href="head.html">HEAD report</a><br>\n'
html += '<a href="latest.html">Latest results</a><br>\n' html += '<a href="latest.html">Latest results</a><br>\n'
html += '<a href="time">Time report</a><br>\n' html += '<a href="time.html">Time report</a><br>\n'
html += '<a href="check_library_function_report.html">checkLibraryFunction r
eport</a><br>\n'
html += '<a href="check_library_noreturn_report.html">checkLibraryNoReturn r
eport</a><br>\n'
html += '<a href="check_library_use_ignore_report.html">checkLibraryUseIgnor
e report</a><br>\n'
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 + ' ' column_width = [15, 10, 5, 6, 6, 8]
while len(ret)<10: ret = a
ret += ' ' while len(ret) < column_width[0]:
if len(ret) == 10:
ret += b[:10] + ' '
while len(ret)<21:
ret += ' '
ret += b[-5:] + ' '
while len(ret) < 32-len(c):
ret += ' ' ret += ' '
ret += c + ' ' if len(ret) == column_width[0]:
while len(ret) < 37-len(d): ret += ' ' + b[:10]
while len(ret) < (column_width[0] + 1 + column_width[1]):
ret += ' ' ret += ' '
ret += d ret += ' '
ret += ' ' + e ret += b[-5:].rjust(column_width[2]) + ' '
ret += c.rjust(column_width[3]) + ' '
ret += d.rjust(column_width[4]) + ' '
ret += e.rjust(column_width[5])
if a != 'Package': if a != 'Package':
pos = ret.find(' ') pos = ret.find(' ')
ret = '<a href="' + a + '">' + a + '</a>' + ret[pos:] ret = '<a href="' + a + '">' + a + '</a>' + ret[pos:]
return ret return ret
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>\n'
html += '<pre>\n<b>' + fmt('Package','Date Time ','1.85','Head','Diff' html += '<pre>\n<b>' + fmt('Package', 'Date Time ', OLD_VERSION, 'Head
) + '</b>\n' ', 'Diff') + '</b>\n'
# Write report for latest results # Write report for latest results
for filename in latestResults: for filename in latestResults:
if not os.path.isfile(filename): if not os.path.isfile(filename):
continue continue
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()
if line.startswith('2018-'): current_year = datetime.date.today().year
if line.startswith(str(current_year) + '-') or line.startswith(str(c
urrent_year - 1) + '-'):
datestr = line datestr = line
#elif line.startswith('cppcheck:'): #elif line.startswith('cppcheck:'):
# cppcheck = line[9:] # cppcheck = line[9:]
elif line.startswith('count: '): elif line.startswith('count: '):
count = line.split(' ')[1:] count = line.split(' ')[1:]
elif line.startswith('head '): elif line.startswith('head ') and not line.startswith('head results: '):
added += 1 added += 1
elif line.startswith('1.85 '): elif line.startswith(OLD_VERSION + ' '):
lost += 1 lost += 1
diff = '' diff = ''
if lost > 0: if lost > 0:
diff += '-' + str(lost) diff += '-' + str(lost)
if added > 0: if added > 0:
diff += '+' + str(added) diff += '+' + str(added)
html += fmt(package, datestr, count[1], count[0], diff) + '\n' html += fmt(package, datestr, count[1], count[0], diff) + '\n'
html += '</pre></body></html>\n' html += '</pre></body></html>\n'
return html return html
def crashReport(): def crashReport():
html = '<html><head><title>Crash report</title></head><body>\n' html = '<html><head><title>Crash report</title></head><body>\n'
html += '<h1>Crash report</h1>\n' html += '<h1>Crash report</h1>\n'
html += '<pre>\n' html += '<pre>\n'
html += '<b>Package 1.85 Head</b>\n' html += '<b>Package ' + OLD_VERSION + ' Hea d</b>\n'
for filename in sorted(glob.glob(os.path.expanduser('~/daca@home/donated-res ults/*'))): for filename in sorted(glob.glob(os.path.expanduser('~/daca@home/donated-res ults/*'))):
if not os.path.isfile(filename): if not os.path.isfile(filename):
continue continue
for line in open(filename, 'rt'): for line in open(filename, 'rt'):
if not line.startswith('count:'): if not line.startswith('count:'):
continue continue
if line.find('Crash') < 0: if line.find('Crash') < 0:
break break
packageName = filename[filename.rfind('/')+1:] packageName = filename[filename.rfind('/')+1:]
counts = line.strip().split(' ') counts = line.strip().split(' ')
skipping to change at line 121 skipping to change at line 126
out = '<a href="' + packageName + '">' + packageName + '</a>' + out[ out.find(' '):] out = '<a href="' + packageName + '">' + packageName + '</a>' + out[ out.find(' '):]
html += out + '\n' html += out + '\n'
break break
html += '</pre>\n' html += '</pre>\n'
html += '</body></html>\n' html += '</body></html>\n'
return html return html
def diffReportFromDict(out, today): def diffReportFromDict(out, today):
html = '<pre>\n' html = '<pre>\n'
html += '<b>MessageID 1.85 Head</b>\n' html += '<b>MessageID ' + OLD_VERSION + ' Head< /b>\n'
sum0 = 0 sum0 = 0
sum1 = 0 sum1 = 0
for messageId in sorted(out.keys()): for messageId in sorted(out.keys()):
line = messageId + ' ' line = messageId + ' '
counts = out[messageId] counts = out[messageId]
sum0 += counts[0] sum0 += counts[0]
sum1 += counts[1] sum1 += counts[1]
if counts[0] > 0: if counts[0] > 0:
c = str(counts[0]) c = str(counts[0])
while len(line) < 40 - len(c): while len(line) < 40 - len(c):
skipping to change at line 176 skipping to change at line 181
for line in open(filename, 'rt'): for line in open(filename, 'rt'):
if firstLine: if firstLine:
if line.startswith(today): if line.startswith(today):
uploadedToday = True uploadedToday = True
firstLine = False firstLine = False
continue continue
line = line.strip() line = line.strip()
if not line.endswith(']'): if not line.endswith(']'):
continue continue
index = None index = None
if line.startswith('1.85 '): if line.startswith(OLD_VERSION + ' '):
index = 0 index = 0
elif line.startswith('head '): elif line.startswith('head '):
index = 1 index = 1
else: else:
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'
html += '<h1>Diff report</h1>\n' html += '<h1>Diff report</h1>\n'
html += '<h2>Uploaded today</h2>' html += '<h2>Uploaded today</h2>'
html += diffReportFromDict(outToday, 'today') html += diffReportFromDict(outToday, 'today')
html += '<h2>All</h2>' html += '<h2>All</h2>'
html += diffReportFromDict(out, '') html += diffReportFromDict(out, '')
return html return html
def diffMessageIdReport(resultPath, messageId): def diffMessageIdReport(resultPath, messageId):
text = messageId + '\n' text = messageId + '\n'
e = '[' + messageId + ']\n' e = '[' + messageId + ']\n'
for filename in sorted(glob.glob(resultPath + '/*')): for filename in sorted(glob.glob(resultPath + '/*')):
if not os.path.isfile(filename):
continue
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':
diff = True diff = True
elif not diff: elif not diff:
continue continue
elif line.endswith(e): elif line.endswith(e):
if url: if url:
text += url text += url
url = None url = None
text += line text += line
return text return text
def diffMessageIdTodayReport(resultPath, messageId): def diffMessageIdTodayReport(resultPath, messageId):
text = messageId + '\n' text = messageId + '\n'
e = '[' + messageId + ']\n' e = '[' + messageId + ']\n'
today = strDateTime()[:10] today = strDateTime()[:10]
for filename in sorted(glob.glob(resultPath + '/*')): for filename in sorted(glob.glob(resultPath + '/*')):
if not os.path.isfile(filename):
continue
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):
break break
if line.startswith('ftp://'): if line.startswith('ftp://'):
url = line url = line
elif line == 'diff:\n': elif line == 'diff:\n':
diff = True diff = True
elif not diff: elif not diff:
continue continue
elif line.endswith(e): elif line.endswith(e):
if url: if url:
text += url text += url
url = None url = None
text += line text += line
return text return text
def headReportFromDict(out, today):
html = '<pre>\n'
html += '<b>MessageID Count</b>\n'
sumTotal = 0
for messageId in sorted(out.keys()):
line = messageId + ' '
counts = out[messageId]
sumTotal += counts
if counts > 0:
c = str(counts)
while len(line) < 48 - len(c):
line += ' '
line += c + ' '
line = '<a href="head' + today + '-' + messageId + '">' + messageId + '<
/a>' + line[line.find(' '):]
html += line + '\n'
# Sum
html += '================================================\n'
line = ''
while len(line) < 48 - len(str(sumTotal)):
line += ' '
line += str(sumTotal) + ' '
html += line + '\n'
html += '</pre>\n'
return html
def headReport(resultsPath):
out = {}
outToday = {}
today = strDateTime()[:10]
for filename in sorted(glob.glob(resultsPath + '/*')):
if not os.path.isfile(filename):
continue
uploadedToday = False
firstLine = True
headResults = False
for line in open(filename, 'rt'):
if firstLine:
if line.startswith(today):
uploadedToday = True
firstLine = False
continue
line = line.strip()
if line.startswith('head results:'):
headResults = True
continue
if line.startswith('diff:'):
if headResults:
break
if not headResults:
continue
if not line.endswith(']'):
continue
if ': note: ' in line:
# notes normally do not contain message ids but can end with ']'
continue
messageId = line[line.rfind('[')+1:len(line)-1]
if messageId not in out:
out[messageId] = 0
out[messageId] += 1
if uploadedToday:
if messageId not in outToday:
outToday[messageId] = 0
outToday[messageId] += 1
html = '<html><head><title>HEAD report</title></head><body>\n'
html += '<h1>HEAD report</h1>\n'
html += '<h2>Uploaded today</h2>'
html += headReportFromDict(outToday, 'today')
html += '<h2>All</h2>'
html += headReportFromDict(out, '')
return html
def headMessageIdReport(resultPath, messageId):
text = messageId + '\n'
e = '[' + messageId + ']\n'
for filename in sorted(glob.glob(resultPath + '/*')):
if not os.path.isfile(filename):
continue
url = None
headResults = False
for line in open(filename, 'rt'):
if line.startswith('ftp://'):
url = line
elif line.startswith('head results:'):
headResults = True
elif not headResults:
continue
elif headResults and line.startswith('diff:'):
break
elif line.endswith(e):
if url:
text += url
url = None
text += line
return text
def headMessageIdTodayReport(resultPath, messageId):
text = messageId + '\n'
e = '[' + messageId + ']\n'
today = strDateTime()[:10]
for filename in sorted(glob.glob(resultPath + '/*')):
if not os.path.isfile(filename):
continue
url = None
headResults = False
firstLine = True
for line in open(filename, 'rt'):
if firstLine:
firstLine = False
if not line.startswith(today):
break
if line.startswith('ftp://'):
url = line
elif line.startswith('head results:'):
headResults = True
elif not headResults:
continue
elif headResults and line.startswith('diff:'):
break
elif line.endswith(e):
if url:
text += url
url = None
text += line
return text
def timeReport(resultPath): def timeReport(resultPath):
text = 'Time report\n\n' html = '<html><head><title>Time report</title></head><body>\n'
text += 'Package 1.85 Head\n' html += '<h1>Time report</h1>\n'
html += '<pre>\n'
column_widths = [25, 10, 10, 10]
html += '<b>'
html += 'Package '.ljust(column_widths[0]) + ' ' + \
OLD_VERSION.rjust(column_widths[1]) + ' ' + \
'Head'.rjust(column_widths[2]) + ' ' + \
'Factor'.rjust(column_widths[3])
html += '</b>\n'
totalTime184 = 0.0 total_time_base = 0.0
totalTimeHead = 0.0 total_time_head = 0.0
for filename in glob.glob(resultPath + '/*'): for filename in glob.glob(resultPath + '/*'):
for line in open(filename,'rt'): if not os.path.isfile(filename):
continue
for line in open(filename, 'rt'):
if not line.startswith('elapsed-time:'): if not line.startswith('elapsed-time:'):
continue continue
splitline = line.strip().split() split_line = line.strip().split()
t184 = float(splitline[2]) time_base = float(split_line[2])
thead = float(splitline[1]) time_head = float(split_line[1])
totalTime184 += t184 total_time_base += time_base
totalTimeHead += thead total_time_head += time_head
if t184>1 and t184*2 < thead: suspicious_time_difference = False
text += filename[filename.find('/')+1:] + ' ' + splitline[2] + ' if time_base > 1 and time_base*2 < time_head:
' + splitline[1] + '\n' suspicious_time_difference = True
elif thead>1 and thead*2 < t184: elif time_head > 1 and time_head*2 < time_base:
text += filename[filename.find('/')+1:] + ' ' + splitline[2] + ' suspicious_time_difference = True
' + splitline[1] + '\n' if suspicious_time_difference:
if time_base > 0.0:
time_factor = time_head / time_base
else:
time_factor = 0.0
html += filename[len(resultPath)+1:].ljust(column_widths[0]) + '
' + \
split_line[2].rjust(column_widths[1]) + ' ' + \
split_line[1].rjust(column_widths[2]) + ' ' + \
'{:.2f}'.format(time_factor).rjust(column_widths[3]) + '\n'
break break
text += '\nTotal time: ' + str(totalTime184) + ' ' + str(totalTimeHead) html += '\n'
if total_time_base > 0.0:
total_time_factor = total_time_head / total_time_base
else:
total_time_factor = 0.0
html += 'Time for all packages (not just the ones listed above):\n'
html += 'Total time: '.ljust(column_widths[0]) + ' ' + \
str(total_time_base).rjust(column_widths[1]) + ' ' + \
str(total_time_head).rjust(column_widths[2]) + ' ' + \
'{:.2f}'.format(total_time_factor).rjust(column_widths[3])
html += '\n'
html += '</pre>\n'
html += '</body></html>\n'
return html
def check_library_report(result_path, message_id):
if message_id not in ('checkLibraryNoReturn', 'checkLibraryFunction', 'check
LibraryUseIgnore'):
error_message = 'Invalid value ' + message_id + ' for message_id paramet
er.'
print(error_message)
return error_message
functions_shown_max = 50000
html = '<html><head><title>' + message_id + ' report</title></head><body>\n'
html += '<h1>' + message_id + ' report</h1>\n'
html += 'Top ' + str(functions_shown_max) + ' functions are shown.'
html += '<pre>\n'
column_widths = [10, 100]
html += '<b>'
html += 'Count'.rjust(column_widths[0]) + ' ' + \
'Function'
html += '</b>\n'
function_counts = dict()
for filename in glob.glob(result_path + '/*'):
if not os.path.isfile(filename):
continue
info_messages = False
for line in open(filename, 'rt'):
if line == 'info messages:\n':
info_messages = True
if not info_messages:
continue
if line.endswith('[' + message_id + ']\n'):
if message_id is 'checkLibraryFunction':
function_name = line[(line.find('for function ') + len('for
function ')):line.rfind('[') - 1]
else:
function_name = line[(line.find(': Function ') + len(': Func
tion ')):line.rfind('should have') - 1]
function_counts[function_name] = function_counts.setdefault(func
tion_name, 0) + 1
functions_shown = 0
for function_name, count in sorted(function_counts.iteritems(), key=lambda (
k, v): (v, k), reverse=True):
if functions_shown >= functions_shown_max:
break
html += str(count).rjust(column_widths[0]) + ' ' + \
'<a href="check_library-' + urllib.quote_plus(function_name) + '
">' + function_name + '</a>\n'
functions_shown += 1
html += '\n'
html += '</pre>\n'
html += '</body></html>\n'
return html
# Lists all checkLibrary* messages regarding the given function name
def check_library_function_name(result_path, function_name):
print('check_library_function_name')
text = ''
function_name = urllib.unquote_plus(function_name)
for filename in glob.glob(result_path + '/*'):
if not os.path.isfile(filename):
continue
info_messages = False
url = None
cppcheck_options = None
for line in open(filename, 'rt'):
if line.startswith('ftp://'):
url = line
elif line.startswith('cppcheck-options:'):
cppcheck_options = line
elif line == 'info messages:\n':
info_messages = True
if not info_messages:
continue
if '[checkLibrary' in line:
if (' ' + function_name) in line:
if url:
text += url
url = None
if cppcheck_options:
text += cppcheck_options
cppcheck_options = None
text += line
return text return text
def sendAll(connection, data): def sendAll(connection, data):
while data: while data:
num = connection.send(data) num = connection.send(data)
if num < len(data): if num < len(data):
data = data[num:] data = data[num:]
else: else:
data = None data = None
skipping to change at line 299 skipping to change at line 553
Thread.__init__(self) Thread.__init__(self)
self.connection = connection self.connection = connection
self.cmd = cmd[:cmd.find('\n')] self.cmd = cmd[:cmd.find('\n')]
self.resultPath = resultPath self.resultPath = resultPath
self.latestResults = latestResults self.latestResults = latestResults
def run(self): def run(self):
try: try:
cmd = self.cmd cmd = self.cmd
print('[' + strDateTime() + '] ' + cmd) print('[' + strDateTime() + '] ' + cmd)
res = re.match(r'GET /([a-zA-Z0-9_\-\.\+]*) HTTP', cmd) res = re.match(r'GET /([a-zA-Z0-9_\-\.\+%]*) HTTP', cmd)
if res is None: if res is None:
self.connection.close() self.connection.close()
return return
url = res.group(1) url = res.group(1)
if url == '': if url == '':
html = overviewReport() html = overviewReport()
httpGetResponse(self.connection, html, 'text/html') httpGetResponse(self.connection, html, 'text/html')
elif url == 'latest.html': elif url == 'latest.html':
html = latestReport(self.latestResults) html = latestReport(self.latestResults)
httpGetResponse(self.connection, html, 'text/html') httpGetResponse(self.connection, html, 'text/html')
elif url == 'crash': elif url == 'crash.html':
html = crashReport() html = crashReport()
httpGetResponse(self.connection, html, 'text/html') httpGetResponse(self.connection, html, 'text/html')
elif url == 'diff': elif url == 'diff.html':
html = diffReport(self.resultPath) html = diffReport(self.resultPath)
httpGetResponse(self.connection, html, 'text/html') httpGetResponse(self.connection, html, 'text/html')
elif url.startswith('difftoday-'): elif url.startswith('difftoday-'):
messageId = url[10:] messageId = url[10:]
text = diffMessageIdTodayReport(self.resultPath, messageId) text = diffMessageIdTodayReport(self.resultPath, messageId)
httpGetResponse(self.connection, text, 'text/plain') httpGetResponse(self.connection, text, 'text/plain')
elif url.startswith('diff-'): elif url.startswith('diff-'):
messageId = url[5:] messageId = url[5:]
text = diffMessageIdReport(self.resultPath, messageId) text = diffMessageIdReport(self.resultPath, messageId)
httpGetResponse(self.connection, text, 'text/plain') httpGetResponse(self.connection, text, 'text/plain')
elif url == 'time': elif url == 'head.html':
html = headReport(self.resultPath)
httpGetResponse(self.connection, html, 'text/html')
elif url.startswith('headtoday-'):
messageId = url[10:]
text = headMessageIdTodayReport(self.resultPath, messageId)
httpGetResponse(self.connection, text, 'text/plain')
elif url.startswith('head-'):
messageId = url[5:]
text = headMessageIdReport(self.resultPath, messageId)
httpGetResponse(self.connection, text, 'text/plain')
elif url == 'time.html':
text = timeReport(self.resultPath) text = timeReport(self.resultPath)
httpGetResponse(self.connection, text, 'text/html')
elif url == 'check_library_function_report.html':
text = check_library_report(self.resultPath + '/' + 'info_output
', message_id='checkLibraryFunction')
httpGetResponse(self.connection, text, 'text/html')
elif url == 'check_library_noreturn_report.html':
text = check_library_report(self.resultPath + '/' + 'info_output
', message_id='checkLibraryNoReturn')
httpGetResponse(self.connection, text, 'text/html')
elif url == 'check_library_use_ignore_report.html':
text = check_library_report(self.resultPath + '/' + 'info_output
', message_id='checkLibraryUseIgnore')
httpGetResponse(self.connection, text, 'text/html')
elif url.startswith('check_library-'):
print('check library function !')
function_name = url[len('check_library-'):]
text = check_library_function_name(self.resultPath + '/' + 'info
_output', function_name)
httpGetResponse(self.connection, text, 'text/plain') httpGetResponse(self.connection, text, 'text/plain')
else: else:
filename = resultPath + '/' + url filename = resultPath + '/' + url
if not os.path.isfile(filename): if not os.path.isfile(filename):
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')
finally: finally:
time.sleep(1) time.sleep(1)
self.connection.close() self.connection.close()
def server(server_address_port, packages, packageIndex, resultPath): def server(server_address_port, packages, packageIndex, resultPath):
socket.setdefaulttimeout(30) socket.setdefaulttimeout(30)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
skipping to change at line 367 skipping to change at line 646
print('[' + strDateTime() + '] waiting for a connection') print('[' + strDateTime() + '] waiting for a connection')
connection, client_address = sock.accept() connection, client_address = sock.accept()
try: try:
cmd = connection.recv(128) cmd = connection.recv(128)
except socket.error: except socket.error:
connection.close() connection.close()
continue continue
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, latestResu lts) newThread = HttpClientThread(connection, cmd, resultPath, latestResu lts)
newThread.start() newThread.start()
elif cmd=='GetCppcheckVersions\n': elif cmd == 'GetCppcheckVersions\n':
print('[' + strDateTime() + '] GetCppcheckVersions: head 1.85') reply = 'head ' + OLD_VERSION
connection.send('head 1.85') print('[' + strDateTime() + '] GetCppcheckVersions: ' + 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
if packageIndex >= len(packages): if packageIndex >= len(packages):
packageIndex = 0 packageIndex = 0
f = open('package-index.txt', 'wt') f = open('package-index.txt', 'wt')
f.write(str(packageIndex) + '\n') f.write(str(packageIndex) + '\n')
f.close() f.close()
print('[' + strDateTime() + '] get:' + pkg) print('[' + strDateTime() + '] get:' + pkg)
connection.send(pkg) connection.send(pkg)
connection.close() connection.close()
elif cmd.startswith('write\nftp://'): elif cmd.startswith('write\nftp://'):
# read data # read data
data = cmd[6:] data = cmd[6:]
try: try:
t = 0 t = 0
while (len(data) < 1024 * 1024) and (not data.endswith('\nDONE') max_data_size = 2 * 1024 * 1024
) and (t < 10): while (len(data) < max_data_size) and (not data.endswith('\nDONE
')) and (t < 10):
d = connection.recv(1024) d = connection.recv(1024)
if d: if d:
t = 0 t = 0
data += d data += d
else: else:
time.sleep(0.2) time.sleep(0.2)
t += 0.2 t += 0.2
connection.close() connection.close()
except socket.error as e: except socket.error as e:
pass pass
pos = data.find('\n') pos = data.find('\n')
if pos < 10: if pos < 10:
continue continue
url = data[:pos] url = data[:pos]
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
if url not in packages: if url not in packages:
url2 = url + '\n' url2 = url + '\n'
if url2 not in packages: if url2 not in packages:
print('results not written. url is not in packages.') print('results not written. url is not in packages.')
continue continue
print('results added for package ' + res.group(1)) print('results added for package ' + res.group(1))
filename = resultPath + '/' + res.group(1) filename = resultPath + '/' + res.group(1)
with open(filename, 'wt') as f: with open(filename, 'wt') as f:
f.write(strDateTime() + '\n' + data) f.write(strDateTime() + '\n' + data)
# track latest added results.. # track latest added results..
if len(latestResults) >= 20: if len(latestResults) >= 20:
latestResults = latestResults[1:] latestResults = latestResults[1:]
latestResults.append(filename) latestResults.append(filename)
with open('latest.txt', 'wt') as f: with open('latest.txt', 'wt') as f:
f.write(' '.join(latestResults)) f.write(' '.join(latestResults))
elif cmd.startswith('write_info\nftp://'):
# read data
data = cmd[11:]
try:
t = 0
max_data_size = 1024 * 1024
while (len(data) < max_data_size) and (not data.endswith('\nDONE
')) and (t < 10):
d = connection.recv(1024)
if d:
t = 0
data += d
else:
time.sleep(0.2)
t += 0.2
connection.close()
except socket.error as e:
pass
pos = data.find('\n')
if pos < 10:
continue
url = data[:pos]
print('[' + strDateTime() + '] write_info:' + url)
# save data
res = re.match(r'ftp://.*pool/main/[^/]+/([^/]+)/[^/]*tar.gz', url)
if res is None:
print('info output not written. res is None.')
continue
if url not in packages:
url2 = url + '\n'
if url2 not in packages:
print('info output not written. url is not in packages.')
continue
print('adding info output for package ' + res.group(1))
info_path = resultPath + '/' + 'info_output'
if not os.path.exists(info_path):
os.mkdir(info_path)
filename = info_path + '/' + res.group(1)
with open(filename, 'wt') as f:
f.write(strDateTime() + '\n' + data)
else: else:
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)
resultPath = workPath + '/donated-results' resultPath = workPath + '/donated-results'
f = open('packages.txt', 'rt') f = open('packages.txt', 'rt')
 End of changes. 41 change blocks. 
66 lines changed or deleted 404 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)