mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-11 03:55:43 +00:00
Enabled 'start local daemon' in ConnectionManager.
Change startup scripts: deluged runs daemon and deluge runs ui. Minor fix-ups.
This commit is contained in:
parent
60eeb8deed
commit
1f8884f903
@ -53,6 +53,7 @@ from deluge.core.signalmanager import SignalManager
|
|||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
DEFAULT_PREFS = {
|
DEFAULT_PREFS = {
|
||||||
|
"daemon_port": 58846,
|
||||||
"compact_allocation": True,
|
"compact_allocation": True,
|
||||||
"download_location": deluge.common.get_default_download_dir(),
|
"download_location": deluge.common.get_default_download_dir(),
|
||||||
"listen_ports": [6881, 6891],
|
"listen_ports": [6881, 6891],
|
||||||
@ -81,14 +82,21 @@ class Core(
|
|||||||
threading.Thread,
|
threading.Thread,
|
||||||
ThreadingMixIn,
|
ThreadingMixIn,
|
||||||
SimpleXMLRPCServer.SimpleXMLRPCServer):
|
SimpleXMLRPCServer.SimpleXMLRPCServer):
|
||||||
def __init__(self):
|
def __init__(self, port):
|
||||||
log.debug("Core init..")
|
log.debug("Core init..")
|
||||||
threading.Thread.__init__(self)
|
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
|
# Setup the xmlrpc server
|
||||||
try:
|
try:
|
||||||
|
log.info("Starting XMLRPC server on port %s", port)
|
||||||
SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(
|
SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(
|
||||||
self, ("localhost", 58846), logRequests=False, allow_none=True)
|
self, ("localhost", port), logRequests=False, allow_none=True)
|
||||||
except:
|
except:
|
||||||
log.info("Daemon already running or port not available..")
|
log.info("Daemon already running or port not available..")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
@ -116,8 +124,6 @@ class Core(
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Starts the core"""
|
"""Starts the core"""
|
||||||
# Get config
|
|
||||||
self.config = ConfigManager("core.conf", DEFAULT_PREFS)
|
|
||||||
|
|
||||||
# Create the client fingerprint
|
# Create the client fingerprint
|
||||||
version = []
|
version = []
|
||||||
|
@ -35,9 +35,9 @@ from deluge.core.core import Core
|
|||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
class Daemon:
|
class Daemon:
|
||||||
def __init__(self):
|
def __init__(self, port):
|
||||||
# Start the core as a thread and join it until it's done
|
# 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.start()
|
||||||
self.core.join()
|
self.core.join()
|
||||||
|
|
||||||
|
@ -39,52 +39,47 @@
|
|||||||
import os
|
import os
|
||||||
from optparse import OptionParser
|
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
|
import deluge.common
|
||||||
|
|
||||||
def main():
|
def start_ui():
|
||||||
"""Entry point for Deluge"""
|
"""Entry point for ui script"""
|
||||||
# Setup the argument parser
|
# Setup the argument parser
|
||||||
parser = OptionParser(usage="%prog [options] [actions]",
|
parser = OptionParser(usage="%prog [options] [actions]",
|
||||||
version=deluge.common.get_version())
|
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
|
# Get the options and args from the OptionParser
|
||||||
(options, args) = parser.parse_args()
|
(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("options: %s", options)
|
||||||
log.debug("args: %s", args)
|
log.debug("args: %s", args)
|
||||||
|
|
||||||
pid = None
|
from deluge.ui.ui import UI
|
||||||
|
|
||||||
# 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..")
|
log.info("Starting ui..")
|
||||||
UI()
|
UI()
|
||||||
|
|
||||||
def start_daemon():
|
def start_daemon():
|
||||||
"""Entry point for daemon script"""
|
"""Entry point for daemon script"""
|
||||||
|
# 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.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..")
|
log.info("Starting daemon..")
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
if not pid:
|
if not pid:
|
||||||
Daemon()
|
Daemon(options.port)
|
||||||
|
@ -115,6 +115,18 @@ def get_core_uri():
|
|||||||
"""Get the core URI"""
|
"""Get the core URI"""
|
||||||
return _core.get_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():
|
def shutdown():
|
||||||
"""Shutdown the core daemon"""
|
"""Shutdown the core daemon"""
|
||||||
try:
|
try:
|
||||||
|
@ -35,6 +35,7 @@ import gtk, gtk.glade
|
|||||||
import pkg_resources
|
import pkg_resources
|
||||||
import gobject
|
import gobject
|
||||||
import socket
|
import socket
|
||||||
|
import os
|
||||||
|
|
||||||
import deluge.ui.component as component
|
import deluge.ui.component as component
|
||||||
import deluge.xmlrpclib as xmlrpclib
|
import deluge.xmlrpclib as xmlrpclib
|
||||||
@ -266,16 +267,21 @@ class ConnectionManager(component.Component):
|
|||||||
paths = self.hostlist.get_selection().get_selected_rows()[1]
|
paths = self.hostlist.get_selection().get_selected_rows()[1]
|
||||||
row = self.liststore.get_iter(paths[0])
|
row = self.liststore.get_iter(paths[0])
|
||||||
status = self.liststore.get_value(row, HOSTLIST_COL_STATUS)
|
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\
|
if HOSTLIST_STATUS[status] == "Online" or\
|
||||||
HOSTLIST_STATUS[status] == "Connected":
|
HOSTLIST_STATUS[status] == "Connected":
|
||||||
# We need to stop this daemon
|
# We need to stop this daemon
|
||||||
uri = self.liststore.get_value(row, HOSTLIST_COL_URI)
|
|
||||||
uri = "http://" + uri
|
uri = "http://" + uri
|
||||||
# Call the shutdown method on the daemon
|
# Call the shutdown method on the daemon
|
||||||
core = xmlrpclib.ServerProxy(uri)
|
core = xmlrpclib.ServerProxy(uri)
|
||||||
core.shutdown()
|
core.shutdown()
|
||||||
# Update display to show change
|
# Update display to show change
|
||||||
self.update()
|
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):
|
def on_button_close_clicked(self, widget):
|
||||||
log.debug("on_button_close_clicked")
|
log.debug("on_button_close_clicked")
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import socket
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user