Donate CPU: updated server

This commit is contained in:
Daniel Marjamäki 2018-08-23 22:13:53 +02:00
parent 1e919e696b
commit b049203be7
1 changed files with 8 additions and 3 deletions

View File

@ -33,13 +33,15 @@ while True:
try: try:
cmd = connection.recv(16) cmd = connection.recv(16)
if cmd=='get\n': if cmd=='get\n':
connection.sendall(packages[packageIndex].strip()) packages[packageIndex] = packages[packageIndex].strip()
print('get:' + packages[packageIndex])
connection.sendall(packages[packageIndex])
packageIndex += 1 packageIndex += 1
if packageIndex >= len(packages): if packageIndex >= len(packages):
packageIndex = 0 packageIndex = 0
elif cmd.startswith('write\n'): elif cmd.startswith('write\n'):
data = cmd[6:] data = cmd[6:]
while True: while len(data) < 1024 * 1024:
d = connection.recv(1024) d = connection.recv(1024)
if d: if d:
data += d data += d
@ -48,12 +50,15 @@ while True:
pos = data.find('\n') pos = data.find('\n')
if data.startswith('ftp://') and pos > 10: if data.startswith('ftp://') and pos > 10:
url = data[:pos] url = data[:pos]
print('write:'+url)
res = re.match(r'ftp://.*pool/main/[^/]+/([^/]+)/[^/]*tar.gz',url) res = re.match(r'ftp://.*pool/main/[^/]+/([^/]+)/[^/]*tar.gz',url)
if res and (url+'\n' in packages): if res and url in packages:
print('results added for package ' + res.group(1)) print('results added for package ' + res.group(1))
f = open(resultPath + '/' + res.group(1), 'wt') f = open(resultPath + '/' + res.group(1), 'wt')
f.write(data[pos+1:]) f.write(data[pos+1:])
f.close() f.close()
else:
print('invalid cmd')
finally: finally:
connection.close() connection.close()