Enabled 'start local daemon' in ConnectionManager.

Change startup scripts: deluged runs daemon and deluge runs ui.
Minor fix-ups.
This commit is contained in:
Andrew Resch 2007-10-25 07:42:14 +00:00
parent 60eeb8deed
commit 1f8884f903
7 changed files with 62 additions and 42 deletions

View File

@ -53,6 +53,7 @@ from deluge.core.signalmanager import SignalManager
from deluge.log import LOG as log
DEFAULT_PREFS = {
"daemon_port": 58846,
"compact_allocation": True,
"download_location": deluge.common.get_default_download_dir(),
"listen_ports": [6881, 6891],
@ -81,14 +82,21 @@ class Core(
threading.Thread,
ThreadingMixIn,
SimpleXMLRPCServer.SimpleXMLRPCServer):
def __init__(self):
def __init__(self, port):
log.debug("Core init..")
threading.Thread.__init__(self)
# Get config
self.config = ConfigManager("core.conf", DEFAULT_PREFS)
if port == None:
port = self.config["daemon_port"]
# Setup the xmlrpc server
try:
log.info("Starting XMLRPC server on port %s", port)
SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(
self, ("localhost", 58846), logRequests=False, allow_none=True)
self, ("localhost", port), logRequests=False, allow_none=True)
except:
log.info("Daemon already running or port not available..")
sys.exit(0)
@ -116,8 +124,6 @@ class Core(
def run(self):
"""Starts the core"""
# Get config
self.config = ConfigManager("core.conf", DEFAULT_PREFS)
# Create the client fingerprint
version = []

View File

@ -35,9 +35,9 @@ from deluge.core.core import Core
from deluge.log import LOG as log
class Daemon:
def __init__(self):
def __init__(self, port):
# Start the core as a thread and join it until it's done
self.core = Core()
self.core = Core(port)
self.core.start()
self.core.join()

View File

@ -39,52 +39,47 @@
import os
from optparse import OptionParser
from deluge.core.daemon import Daemon
from deluge.ui.ui import UI
from deluge.log import LOG as log
import deluge.common
def main():
"""Entry point for Deluge"""
def start_ui():
"""Entry point for ui script"""
# Setup the argument parser
parser = OptionParser(usage="%prog [options] [actions]",
version=deluge.common.get_version())
parser.add_option("--daemon", dest="daemon", help="Start Deluge daemon",
metavar="DAEMON", action="store_true", default=False)
parser.add_option("--ui", dest="ui", help="Start Deluge UI",
metavar="UI", action="store_true", default=False)
# Get the options and args from the OptionParser
(options, args) = parser.parse_args()
log.info("Deluge %s", deluge.common.get_version())
from deluge.log import LOG as log
log.info("Deluge ui %s", deluge.common.get_version())
log.debug("options: %s", options)
log.debug("args: %s", args)
pid = None
# Start the daemon
if options.daemon:
log.info("Starting daemon..")
# We need to fork() the process to run it in the background...
# FIXME: We cannot use fork() on Windows
pid = os.fork()
if not pid:
# Since we are starting daemon this process will not start a UI
options.ui = False
# Create the daemon object
Daemon()
# Start the UI
if options.ui:
log.info("Starting ui..")
UI()
from deluge.ui.ui import UI
log.info("Starting ui..")
UI()
def start_daemon():
"""Entry point for daemon script"""
log.info("Deluge daemon %s", deluge.common.get_version())
# Setup the argument parser
parser = OptionParser(usage="%prog [options] [actions]",
version=deluge.common.get_version())
parser.add_option("-p", "--port", dest="port",
help="Port daemon will listen on", action="store", type="int")
# Get the options and args from the OptionParser
(options, args) = parser.parse_args()
from deluge.log import LOG as log
log.info("Deluge daemon %s", deluge.common.get_version())
log.debug("options: %s", options)
log.debug("args: %s", args)
from deluge.core.daemon import Daemon
log.info("Starting daemon..")
pid = os.fork()
if not pid:
Daemon()
Daemon(options.port)

View File

@ -114,7 +114,19 @@ def set_core_uri(uri):
def get_core_uri():
"""Get the core URI"""
return _core.get_core_uri()
def is_localhost():
"""Returns True if core is a localhost"""
# Get the uri
uri = _core.get_core_uri()
if uri != None:
# Get the host
host = uri[7:].split(":")[0]
if host == "localhost" or host == "127.0.0.1":
return True
return False
def shutdown():
"""Shutdown the core daemon"""
try:

View File

@ -35,6 +35,7 @@ import gtk, gtk.glade
import pkg_resources
import gobject
import socket
import os
import deluge.ui.component as component
import deluge.xmlrpclib as xmlrpclib
@ -266,17 +267,22 @@ class ConnectionManager(component.Component):
paths = self.hostlist.get_selection().get_selected_rows()[1]
row = self.liststore.get_iter(paths[0])
status = self.liststore.get_value(row, HOSTLIST_COL_STATUS)
uri = self.liststore.get_value(row, HOSTLIST_COL_URI)
port = uri.split(":")[1]
if HOSTLIST_STATUS[status] == "Online" or\
HOSTLIST_STATUS[status] == "Connected":
# We need to stop this daemon
uri = self.liststore.get_value(row, HOSTLIST_COL_URI)
uri = "http://" + uri
# Call the shutdown method on the daemon
core = xmlrpclib.ServerProxy(uri)
core.shutdown()
# Update display to show change
self.update()
elif HOSTLIST_STATUS[status] == "Offline":
log.debug("Start localhost daemon..")
# Spawn a local daemon
os.popen("deluged -p %s" % port)
def on_button_close_clicked(self, widget):
log.debug("on_button_close_clicked")
self.hide()

View File

@ -32,6 +32,7 @@
# statement from all source files in the program, then also delete it here.
import sys
import socket
import gobject

View File

@ -194,6 +194,6 @@ setup(
cmdclass=cmdclass,
entry_points = """
[console_scripts]
deluge = deluge.main:main
deluge = deluge.main:start_ui
deluged = deluge.main:start_daemon
""")