diff options
author | jchu <jchu> | 2004-12-13 04:12:12 +0100 |
---|---|---|
committer | jchu <jchu> | 2004-12-13 04:12:12 +0100 |
commit | c0b9a256aa09ca448d45c81f001857920dcc51b9 (patch) | |
tree | d68f4a54eb31769ddf11655f14a6ed476740d3fa /tupkg/server | |
parent | e69d7b1356ea0506062585cbb4800e454d7fb2e3 (diff) | |
download | aur-c0b9a256aa09ca448d45c81f001857920dcc51b9.tar.gz aur-c0b9a256aa09ca448d45c81f001857920dcc51b9.tar.xz |
added incoming directory support and made the server not use 100% cpu busy waiting
Diffstat (limited to 'tupkg/server')
-rwxr-xr-x | tupkg/server/tupkgs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/tupkg/server/tupkgs b/tupkg/server/tupkgs index 1aba7947..1c617077 100755 --- a/tupkg/server/tupkgs +++ b/tupkg/server/tupkgs @@ -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 |