rework the DelugeWeb class so it's completely self contained

This commit is contained in:
Damien Churchill 2009-03-07 12:42:09 +00:00
parent 8e62f5b3a8
commit 8fda4d1fde
2 changed files with 16 additions and 16 deletions

View File

@ -35,6 +35,7 @@ import tempfile
import pkg_resources import pkg_resources
from twisted.application import service, internet from twisted.application import service, internet
from twisted.internet import reactor
from twisted.internet.defer import Deferred from twisted.internet.defer import Deferred
from twisted.web import http, resource, server, static from twisted.web import http, resource, server, static
@ -69,8 +70,8 @@ current_dir = os.path.dirname(__file__)
CONFIG_DEFAULTS = { CONFIG_DEFAULTS = {
"port": 8112, "port": 8112,
"template": "slate", "template": "slate",
"pwd_salt": "2\xe8\xc7\xa6(n\x81_\x8f\xfc\xdf\x8b\xd1\x1e\xd5\x90", "pwd_salt": u"2\xe8\xc7\xa6(n\x81_\x8f\xfc\xdf\x8b\xd1\x1e\xd5\x90",
"pwd_md5": ".\xe8w\\+\xec\xdb\xf2id4F\xdb\rUc", "pwd_md5": u".\xe8w\\+\xec\xdb\xf2id4F\xdb\rUc",
"base": "", "base": "",
"sessions": [], "sessions": [],
"sidebar_show_zero": False, "sidebar_show_zero": False,
@ -586,8 +587,18 @@ class DelugeWeb(component.Component):
return 1 return 1
SetConsoleCtrlHandler(win_handler) SetConsoleCtrlHandler(win_handler)
def shutdown(self): def start(self):
print "Starting server in PID %s." % os.getpid()
reactor.listenTCP(self.port, self.site)
print "serving on 0.0.0.0:%(port)s view at http://127.0.0.1:%(port)s" % {
"port": self.port
}
reactor.run()
def shutdown(self, *args):
log.info("Shutting down webserver")
self.config.save() self.config.save()
reactor.stop()
if __name__ == "__builtin__": if __name__ == "__builtin__":
deluge_web = DelugeWeb() deluge_web = DelugeWeb()
@ -596,7 +607,5 @@ if __name__ == "__builtin__":
i = internet.TCPServer(deluge_web.port, deluge_web.site) i = internet.TCPServer(deluge_web.port, deluge_web.site)
i.setServiceParent(sc) i.setServiceParent(sc)
elif __name__ == "__main__": elif __name__ == "__main__":
from twisted.internet import reactor
deluge_web = DelugeWeb() deluge_web = DelugeWeb()
reactor.listenTCP(deluge_web.port, deluge_web.site) deluge_web.start()
reactor.run()

View File

@ -22,18 +22,9 @@
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
# #
from twisted.internet import reactor
class WebUI: class WebUI:
def __init__(self, args): def __init__(self, args):
import os
import server import server
print "Starting server in PID %s." % os.getpid()
deluge_web = server.DelugeWeb() deluge_web = server.DelugeWeb()
reactor.listenTCP(deluge_web.port, deluge_web.site) deluge_web.start()
print "serving on 0.0.0.0:%(port)s view at http://127.0.0.1:%(port)s" % {
"port": deluge_web.port
}
reactor.run()