mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
added incoming directory support and made the server not use 100% cpu busy waiting
This commit is contained in:
parent
e69d7b1356
commit
c0b9a256aa
1 changed files with 21 additions and 2 deletions
|
@ -27,15 +27,18 @@ import MySQLdb.connections
|
|||
import ConfigParser
|
||||
import getopt
|
||||
import os.path
|
||||
import os
|
||||
import time
|
||||
|
||||
CACHEDIR = '/var/cache/tupkgs/'
|
||||
INCOMINGDIR = '/var/cache/tupkgs/incomplete/'
|
||||
CONFIGFILE = '/etc/tupkgs.conf'
|
||||
|
||||
config = ConfigParser.ConfigParser()
|
||||
|
||||
class ClientFile:
|
||||
def __init__(self, filename, actual_size, actual_md5):
|
||||
self.pathname = CACHEDIR + filename
|
||||
self.pathname = INCOMINGDIR + filename
|
||||
self.filename = filename
|
||||
self.fd = open(self.pathname, "w+b")
|
||||
self.actual_size = actual_size
|
||||
|
@ -57,6 +60,13 @@ class ClientFile:
|
|||
self.fd.seek(cur)
|
||||
self.md5 = md5sum.hexdigest()
|
||||
|
||||
def finishDownload(self):
|
||||
self.fd.close();
|
||||
newpathname = CACHEDIR + self.filename
|
||||
os.rename(self.pathname, newpathname)
|
||||
self.pathname = newpathname
|
||||
self.fd = open(self.pathname, "a+b")
|
||||
|
||||
class ClientSocket(threading.Thread):
|
||||
def __init__(self, sock, db, **other):
|
||||
threading.Thread.__init__(self, *other)
|
||||
|
@ -142,6 +152,7 @@ class ClientSocket(threading.Thread):
|
|||
i.fd.write(self.reliableRead(1024))
|
||||
count += 1024
|
||||
i.fd.flush()
|
||||
i.finishDownload()
|
||||
reply = {'numpkgs': len(self.files)}
|
||||
for i, v in enumerate(self.files):
|
||||
v.makeMd5()
|
||||
|
@ -246,6 +257,14 @@ def main(argv=None):
|
|||
passwd=config.get('mysql', 'password'),
|
||||
db=config.get('mysql', 'db'))
|
||||
|
||||
print "Verifying "+CACHEDIR+" and "+INCOMINGDIR+" exist"
|
||||
if not os.path.isdir(CACHEDIR):
|
||||
print "Creating "+CACHEDIR
|
||||
os.mkdir(CACHEDIR, 0755)
|
||||
if not os.path.isdir(INCOMINGDIR):
|
||||
print "Creating "+INCOMINGDIR
|
||||
os.mkdir(INCOMINGDIR, 0755)
|
||||
|
||||
print "Starting ServerSocket"
|
||||
servsock = ServerSocket(dbconn, confdict['port'], confdict['maxqueue'])
|
||||
servsock.start()
|
||||
|
@ -253,7 +272,7 @@ def main(argv=None):
|
|||
try:
|
||||
while running:
|
||||
# Maybe do stuff here?
|
||||
pass
|
||||
time.sleep(10)
|
||||
except KeyboardInterrupt:
|
||||
running = 0
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue