Added cleanup for temp directories

This commit is contained in:
Sebastian Lohff 2012-04-07 03:02:20 +02:00
parent 771d383b81
commit d46cc10107
1 changed files with 10 additions and 3 deletions

View File

@ -189,10 +189,13 @@ def main():
handler = FilePutter
server = ThreadedHTTPServer(('', args.port), handler)
print "Serving \"%s\" under port %d" % (args.filename, args.port)
if args.upload:
print "Serving \"%s\" under port %d" % (args.filename, args.port)
else:
print "Serving \"%s\" for uploads under port %d" % (args.filename, args.port)
# print urls with local network adresses
print "\nSome addresses this file will be available under:"
print "\nSome addresses this will be available under:"
# ip and ifconfig sometimes are located in /sbin/
os.environ['PATH'] += ':/sbin:/usr/sbin'
@ -229,8 +232,12 @@ def main():
server.serve_forever()
except KeyboardInterrupt:
server.socket.close()
# cleanup potential upload directory
if dirCreated and len(os.listdir(args.filename)) == 0:
# created upload dir was not used
os.rmdir(args.filename)
print "Good bye.."
# XXX: cleanup upload directory
if __name__ == '__main__':
main()