Fix #565 wait for the deluged process to start to prevent defunct
processes
This commit is contained in:
parent
1aa33421e9
commit
dc0a2ce52e
|
@ -2,19 +2,19 @@
|
|||
# connectionmanager.py
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||
#
|
||||
#
|
||||
# Deluge is free software.
|
||||
#
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
|
@ -70,9 +70,9 @@ class ConnectionManager(component.Component):
|
|||
component.Component.__init__(self, "ConnectionManager")
|
||||
# Get the glade file for the connection manager
|
||||
self.glade = gtk.glade.XML(
|
||||
pkg_resources.resource_filename("deluge.ui.gtkui",
|
||||
pkg_resources.resource_filename("deluge.ui.gtkui",
|
||||
"glade/connection_manager.glade"))
|
||||
|
||||
|
||||
self.window = component.get("MainWindow")
|
||||
self.config = ConfigManager("hostlist.conf", DEFAULT_CONFIG)
|
||||
self.gtkui_config = ConfigManager("gtkui.conf")
|
||||
|
@ -81,19 +81,19 @@ class ConnectionManager(component.Component):
|
|||
self.connection_manager.set_transient_for(self.window.window)
|
||||
self.hostlist = self.glade.get_widget("hostlist")
|
||||
self.connection_manager.set_icon(common.get_logo(32))
|
||||
|
||||
|
||||
self.glade.get_widget("image1").set_from_pixbuf(common.get_logo(32))
|
||||
|
||||
|
||||
self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str, int)
|
||||
|
||||
# Holds the online status of hosts
|
||||
self.online_status = {}
|
||||
|
||||
|
||||
# Fill in hosts from config file
|
||||
for host in self.config["hosts"]:
|
||||
row = self.liststore.append()
|
||||
self.liststore.set_value(row, HOSTLIST_COL_URI, host)
|
||||
|
||||
|
||||
# Setup host list treeview
|
||||
self.hostlist.set_model(self.liststore)
|
||||
render = gtk.CellRendererPixbuf()
|
||||
|
@ -103,7 +103,7 @@ class ConnectionManager(component.Component):
|
|||
render = gtk.CellRendererText()
|
||||
column = gtk.TreeViewColumn("Host", render, text=HOSTLIST_COL_URI)
|
||||
self.hostlist.append_column(column)
|
||||
|
||||
|
||||
self.glade.signal_autoconnect({
|
||||
"on_button_addhost_clicked": self.on_button_addhost_clicked,
|
||||
"on_button_removehost_clicked": self.on_button_removehost_clicked,
|
||||
|
@ -115,22 +115,22 @@ class ConnectionManager(component.Component):
|
|||
"on_chk_autostart_toggled": self.on_chk_autostart_toggled,
|
||||
"on_chk_donotshow_toggled": self.on_chk_donotshow_toggled
|
||||
})
|
||||
|
||||
|
||||
self.connection_manager.connect("delete-event", self.on_delete_event)
|
||||
# Connect to the 'changed' event of TreeViewSelection to get selection
|
||||
# changes.
|
||||
self.hostlist.get_selection().connect("changed",
|
||||
self.hostlist.get_selection().connect("changed",
|
||||
self.on_selection_changed)
|
||||
|
||||
|
||||
self.hostlist.connect("row-activated", self._on_row_activated)
|
||||
|
||||
|
||||
# If classic mode is set, we just start up a localhost daemon and connect to it
|
||||
if self.gtkui_config["classic_mode"]:
|
||||
uri = "http://localhost:58846"
|
||||
if deluge.common.windows_check():
|
||||
win32api.WinExec("deluged -p 58846")
|
||||
else:
|
||||
subprocess.Popen(["deluged", "-p 58846"])
|
||||
subprocess.call(["deluged", "-p 58846"])
|
||||
time.sleep(0.1)
|
||||
# We need to wait for the host to start before connecting
|
||||
while not self.test_online_status(uri):
|
||||
|
@ -142,7 +142,7 @@ class ConnectionManager(component.Component):
|
|||
# This controls the timer, if it's set to false the update timer will stop.
|
||||
self._do_update = True
|
||||
self._update_list()
|
||||
|
||||
|
||||
# Auto connect to a host if applicable
|
||||
if self.gtkui_config["autoconnect"] and \
|
||||
self.gtkui_config["autoconnect_host_uri"] != None:
|
||||
|
@ -165,19 +165,19 @@ class ConnectionManager(component.Component):
|
|||
if deluge.common.windows_check():
|
||||
win32api.WinExec("deluged -p %s" % port)
|
||||
else:
|
||||
subprocess.Popen(["deluged", "-p %s" % port])
|
||||
subprocess.call(["deluged", "-p %s" % port])
|
||||
# We need to wait for the host to start before connecting
|
||||
while not self.test_online_status(uri):
|
||||
time.sleep(0.01)
|
||||
client.set_core_uri(uri)
|
||||
self.hide()
|
||||
|
||||
|
||||
def start(self):
|
||||
if self.gtkui_config["autoconnect"]:
|
||||
# We need to update the autoconnect_host_uri on connection to host
|
||||
# start() gets called whenever we get a new connection to a host
|
||||
self.gtkui_config["autoconnect_host_uri"] = client.get_core_uri()
|
||||
|
||||
|
||||
def show(self):
|
||||
# Set the checkbuttons according to config
|
||||
self.glade.get_widget("chk_autoconnect").set_active(
|
||||
|
@ -186,13 +186,13 @@ class ConnectionManager(component.Component):
|
|||
self.gtkui_config["autostart_localhost"])
|
||||
self.glade.get_widget("chk_donotshow").set_active(
|
||||
not self.gtkui_config["show_connection_manager_on_start"])
|
||||
|
||||
|
||||
# Setup timer to update host status
|
||||
self._update_timer = gobject.timeout_add(1000, self._update_list)
|
||||
self._update_list()
|
||||
self._update_list()
|
||||
self.connection_manager.show_all()
|
||||
|
||||
|
||||
def hide(self):
|
||||
self.connection_manager.hide()
|
||||
self._do_update = False
|
||||
|
@ -213,31 +213,31 @@ class ConnectionManager(component.Component):
|
|||
online = self.online_status[uri]
|
||||
except:
|
||||
online = False
|
||||
|
||||
|
||||
if online:
|
||||
image = gtk.STOCK_YES
|
||||
online = HOSTLIST_STATUS.index("Online")
|
||||
else:
|
||||
image = gtk.STOCK_NO
|
||||
online = HOSTLIST_STATUS.index("Offline")
|
||||
|
||||
|
||||
if uri == current_uri:
|
||||
# We are connected to this host, so lets display the connected
|
||||
# icon.
|
||||
image = gtk.STOCK_CONNECT
|
||||
online = HOSTLIST_STATUS.index("Connected")
|
||||
|
||||
|
||||
pixbuf = self.connection_manager.render_icon(
|
||||
image, gtk.ICON_SIZE_MENU)
|
||||
|
||||
|
||||
model.set_value(row, HOSTLIST_COL_PIXBUF, pixbuf)
|
||||
model.set_value(row, HOSTLIST_COL_STATUS, online)
|
||||
|
||||
|
||||
current_uri = client.get_core_uri()
|
||||
self.liststore.foreach(update_row)
|
||||
# Update the buttons
|
||||
self.update_buttons()
|
||||
|
||||
|
||||
# See if there is any row selected
|
||||
paths = self.hostlist.get_selection().get_selected_rows()[1]
|
||||
if len(paths) < 1:
|
||||
|
@ -246,7 +246,7 @@ class ConnectionManager(component.Component):
|
|||
# Then select the first row
|
||||
self.hostlist.get_selection().select_iter(self.liststore.get_iter_first())
|
||||
return self._do_update
|
||||
|
||||
|
||||
def update_buttons(self):
|
||||
"""Updates the buttons based on selection"""
|
||||
if self.liststore.iter_n_children(None) < 1:
|
||||
|
@ -260,7 +260,7 @@ class ConnectionManager(component.Component):
|
|||
"_Start Daemon")
|
||||
self.glade.get_widget("label_startdaemon").set_use_underline(
|
||||
True)
|
||||
|
||||
|
||||
# Get the selected row's URI
|
||||
paths = self.hostlist.get_selection().get_selected_rows()[1]
|
||||
# If nothing is selected, just return
|
||||
|
@ -269,12 +269,12 @@ class ConnectionManager(component.Component):
|
|||
row = self.liststore.get_iter(paths[0])
|
||||
uri = self.liststore.get_value(row, HOSTLIST_COL_URI)
|
||||
status = self.liststore.get_value(row, HOSTLIST_COL_STATUS)
|
||||
|
||||
|
||||
# Check to see if a localhost is selected
|
||||
localhost = False
|
||||
if uri.split(":")[0] == "localhost" or uri.split(":")[0] == "127.0.0.1":
|
||||
localhost = True
|
||||
|
||||
|
||||
# Make actual URI string
|
||||
uri = "http://" + uri
|
||||
|
||||
|
@ -282,7 +282,7 @@ class ConnectionManager(component.Component):
|
|||
self.glade.get_widget("button_startdaemon").set_sensitive(True)
|
||||
self.glade.get_widget("button_connect").set_sensitive(True)
|
||||
self.glade.get_widget("button_removehost").set_sensitive(True)
|
||||
|
||||
|
||||
# See if this is the currently connected URI
|
||||
if status == HOSTLIST_STATUS.index("Connected"):
|
||||
# Display a disconnect button if we're connected to this host
|
||||
|
@ -300,7 +300,7 @@ class ConnectionManager(component.Component):
|
|||
gtk.STOCK_STOP, gtk.ICON_SIZE_MENU)
|
||||
self.glade.get_widget("label_startdaemon").set_text(
|
||||
"_Stop Daemon")
|
||||
|
||||
|
||||
# Update the start daemon button if the selected host is localhost
|
||||
if localhost and status == HOSTLIST_STATUS.index("Offline"):
|
||||
# The localhost is not online
|
||||
|
@ -308,25 +308,25 @@ class ConnectionManager(component.Component):
|
|||
gtk.STOCK_EXECUTE, gtk.ICON_SIZE_MENU)
|
||||
self.glade.get_widget("label_startdaemon").set_text(
|
||||
"_Start Daemon")
|
||||
|
||||
|
||||
if not localhost:
|
||||
# An offline host
|
||||
self.glade.get_widget("button_startdaemon").set_sensitive(False)
|
||||
|
||||
# Make sure label is displayed correctly using mnemonics
|
||||
# Make sure label is displayed correctly using mnemonics
|
||||
self.glade.get_widget("label_startdaemon").set_use_underline(
|
||||
True)
|
||||
|
||||
|
||||
def save(self):
|
||||
"""Save the current host list to file"""
|
||||
def append_row(model=None, path=None, row=None, columns=None):
|
||||
hostlist.append(model.get_value(row, HOSTLIST_COL_URI))
|
||||
|
||||
|
||||
hostlist = []
|
||||
self.liststore.foreach(append_row, hostlist)
|
||||
self.config["hosts"] = hostlist
|
||||
self.config.save()
|
||||
|
||||
|
||||
def test_online_status(self, uri):
|
||||
"""Tests the status of URI.. Returns True or False depending on status.
|
||||
"""
|
||||
|
@ -341,12 +341,12 @@ class ConnectionManager(component.Component):
|
|||
del host
|
||||
self.online_status[uri] = online
|
||||
return online
|
||||
|
||||
|
||||
## Callbacks
|
||||
def on_delete_event(self, widget, event):
|
||||
self.hide()
|
||||
return True
|
||||
|
||||
|
||||
def on_button_addhost_clicked(self, widget):
|
||||
log.debug("on_button_addhost_clicked")
|
||||
dialog = self.glade.get_widget("addhost_dialog")
|
||||
|
@ -356,11 +356,11 @@ class ConnectionManager(component.Component):
|
|||
response = dialog.run()
|
||||
if response == 1:
|
||||
# We add the host
|
||||
self.add_host(hostname_entry.get_text(),
|
||||
self.add_host(hostname_entry.get_text(),
|
||||
port_spinbutton.get_value_as_int())
|
||||
|
||||
dialog.hide()
|
||||
|
||||
dialog.hide()
|
||||
|
||||
def add_host(self, hostname, port):
|
||||
"""Adds the host to the list"""
|
||||
if hostname.startswith("http://"):
|
||||
|
@ -369,8 +369,8 @@ class ConnectionManager(component.Component):
|
|||
# Check to make sure the hostname is at least 1 character long
|
||||
if len(hostname) < 1:
|
||||
return
|
||||
|
||||
# Get the port and concatenate the hostname string
|
||||
|
||||
# Get the port and concatenate the hostname string
|
||||
hostname = hostname + ":" + str(port)
|
||||
|
||||
# Check to see if there is already an entry for this host and return
|
||||
|
@ -382,7 +382,7 @@ class ConnectionManager(component.Component):
|
|||
self.liststore.foreach(each_row, None)
|
||||
if hostname in self.hosts_liststore:
|
||||
return
|
||||
|
||||
|
||||
# Host isn't in the list, so lets add it
|
||||
row = self.liststore.append()
|
||||
self.liststore.set_value(row, HOSTLIST_COL_URI, hostname)
|
||||
|
@ -390,20 +390,20 @@ class ConnectionManager(component.Component):
|
|||
self.save()
|
||||
# Update the status of the hosts
|
||||
self._update_list()
|
||||
|
||||
|
||||
def on_button_removehost_clicked(self, widget):
|
||||
log.debug("on_button_removehost_clicked")
|
||||
# Get the selected rows
|
||||
paths = self.hostlist.get_selection().get_selected_rows()[1]
|
||||
for path in paths:
|
||||
self.liststore.remove(self.liststore.get_iter(path))
|
||||
|
||||
|
||||
# Update the hostlist
|
||||
self._update_list()
|
||||
|
||||
|
||||
# Save the host list
|
||||
self.save()
|
||||
|
||||
|
||||
def on_button_startdaemon_clicked(self, widget):
|
||||
log.debug("on_button_startdaemon_clicked")
|
||||
if self.liststore.iter_n_children(None) < 1:
|
||||
|
@ -412,7 +412,7 @@ class ConnectionManager(component.Component):
|
|||
# ..and start the daemon.
|
||||
self.start_localhost(58846)
|
||||
return
|
||||
|
||||
|
||||
paths = self.hostlist.get_selection().get_selected_rows()[1]
|
||||
if len(paths) < 1:
|
||||
return
|
||||
|
@ -431,7 +431,7 @@ class ConnectionManager(component.Component):
|
|||
self.update()
|
||||
elif HOSTLIST_STATUS[status] == "Offline":
|
||||
self.start_localhost(port)
|
||||
|
||||
|
||||
def start_localhost(self, port):
|
||||
"""Starts a localhost daemon"""
|
||||
port = str(port)
|
||||
|
@ -440,7 +440,7 @@ class ConnectionManager(component.Component):
|
|||
if deluge.common.windows_check():
|
||||
win32api.WinExec("deluged -p %s" % port)
|
||||
else:
|
||||
subprocess.Popen(["deluged", "-p %s" % port])
|
||||
subprocess.call(["deluged", "-p %s" % port])
|
||||
|
||||
def on_button_close_clicked(self, widget):
|
||||
log.debug("on_button_close_clicked")
|
||||
|
@ -458,7 +458,7 @@ class ConnectionManager(component.Component):
|
|||
port = uri.split(":")[1]
|
||||
if uri.split(":")[0] == "localhost":
|
||||
localhost = True
|
||||
|
||||
|
||||
uri = "http://" + uri
|
||||
if status == HOSTLIST_STATUS.index("Connected"):
|
||||
# Stop all the components first.
|
||||
|
@ -467,7 +467,7 @@ class ConnectionManager(component.Component):
|
|||
client.set_core_uri(None)
|
||||
self._update_list()
|
||||
return
|
||||
|
||||
|
||||
# Test the host to see if it is online or not. We don't use the status
|
||||
# column information because it can be up to 5 seconds out of sync.
|
||||
if not self.test_online_status(uri):
|
||||
|
@ -477,14 +477,14 @@ class ConnectionManager(component.Component):
|
|||
self.start_localhost(port)
|
||||
# We need to wait for the host to start before connecting
|
||||
while not self.test_online_status(uri):
|
||||
time.sleep(0.01)
|
||||
time.sleep(0.01)
|
||||
client.set_core_uri(uri)
|
||||
self._update_list()
|
||||
self.hide()
|
||||
|
||||
|
||||
# Update the list to show proper status
|
||||
self._update_list()
|
||||
|
||||
|
||||
return
|
||||
|
||||
# Status is OK, so lets change to this host
|
||||
|
@ -509,11 +509,10 @@ class ConnectionManager(component.Component):
|
|||
log.debug("on_chk_donotshow_toggled")
|
||||
value = widget.get_active()
|
||||
self.gtkui_config["show_connection_manager_on_start"] = not value
|
||||
|
||||
|
||||
def on_selection_changed(self, treeselection):
|
||||
log.debug("on_selection_changed")
|
||||
self.update_buttons()
|
||||
|
||||
def _on_row_activated(self, tree, path, view_column):
|
||||
def _on_row_activated(self, tree, path, view_column):
|
||||
self.on_button_connect_clicked(self.glade.get_widget("button_connect"))
|
||||
|
||||
|
|
Loading…
Reference in New Issue