Author: andar

Revision: 5857

Log:
        Fix 'autostart localhost if needed' option

Diff:
Modified: branches/1.2_RC/ChangeLog
===================================================================
--- branches/1.2_RC/ChangeLog   2009-10-21 20:30:07 UTC (rev 5856)
+++ branches/1.2_RC/ChangeLog   2009-10-23 01:07:46 UTC (rev 5857)
@@ -3,6 +3,7 @@
        * Fix path errors when adding torrents externally in Windows
        * Fix localclient authentication by stripping the lines read from the 
auth file
        * Do not try to call doIteration() on the reactor if it has already 
stopped
+       * Fix 'autostart localhost if needed' option
 
 ==== Core ====
        * Fix saving torrent state on fresh configs

Modified: branches/1.2_RC/deluge/ui/gtkui/gtkui.py
===================================================================
--- branches/1.2_RC/deluge/ui/gtkui/gtkui.py    2009-10-21 20:30:07 UTC (rev 
5856)
+++ branches/1.2_RC/deluge/ui/gtkui/gtkui.py    2009-10-23 01:07:46 UTC (rev 
5857)
@@ -299,9 +299,38 @@
             if self.config["autoconnect"]:
                 for host in self.connectionmanager.config["hosts"]:
                     if host[0] == self.config["autoconnect_host_id"]:
+                        try_connect = True
+                        # Check to see if we need to start the localhost daemon
+                        if self.config["autostart_localhost"] and host[1] in 
("localhost", "127.0.0.1"):
+                            log.debug("Autostarting localhost:%s", host[2])
+                            try_connect = client.start_daemon(host[2], 
deluge.configmanager.get_config_dir())
+                            log.debug("Localhost started: %s", try_connect)
+                            if not try_connect:
+                                dialogs.ErrorDialog(
+                                    _("Error Starting Daemon"),
+                                    _("There was an error starting the daemon 
process.  Try running it from a console to see if there is an error.")).run()
+                                
+                        # We'll try 30 reconnects at 500ms intervals
+                        try_counter = 30
+                        
                         def on_connect(connector):
                             component.start()
-                        client.connect(*host[1:]).addCallback(on_connect)
+                        def on_connect_fail(result, try_counter):
+                            log.error("Connection to host failed..")
+                            # We failed connecting to the daemon, but lets try 
again
+                            if try_counter:
+                                log.info("Retrying connection.. Retries left: 
%s", try_counter)
+                                try_counter -= 1
+                                import time
+                                time.sleep(0.5)
+                                do_connect()
+                            return result
+                            
+                        def do_connect():
+                            
client.connect(*host[1:]).addCallback(on_connect).addErrback(on_connect_fail, 
try_counter)
+                                                    
+                        if try_connect:
+                            do_connect()
 
             if self.config["show_connection_manager_on_start"]:
                 # XXX: We need to call a simulate() here, but this could be a 
bug in twisted

Modified: trunk/deluge/ui/gtkui/gtkui.py
===================================================================
--- trunk/deluge/ui/gtkui/gtkui.py      2009-10-21 20:30:07 UTC (rev 5856)
+++ trunk/deluge/ui/gtkui/gtkui.py      2009-10-23 01:07:46 UTC (rev 5857)
@@ -299,9 +299,39 @@
             if self.config["autoconnect"]:
                 for host in self.connectionmanager.config["hosts"]:
                     if host[0] == self.config["autoconnect_host_id"]:
+                        try_connect = True
+                        # Check to see if we need to start the localhost daemon
+                        if self.config["autostart_localhost"] and host[1] in 
("localhost", "127.0.0.1"):
+                            log.debug("Autostarting localhost:%s", host[2])
+                            try_connect = client.start_daemon(host[2], 
deluge.configmanager.get_config_dir())
+                            log.debug("Localhost started: %s", try_connect)
+                            if not try_connect:
+                                dialogs.ErrorDialog(
+                                    _("Error Starting Daemon"),
+                                    _("There was an error starting the daemon 
process.  Try running it from a console to see if there is an error.")).run()
+                                
+                        # We'll try 30 reconnects at 500ms intervals
+                        try_counter = 30
+                        
                         def on_connect(connector):
                             component.start()
-                        client.connect(*host[1:]).addCallback(on_connect)
+                        def on_connect_fail(result, try_counter):
+                            log.error("Connection to host failed..")
+                            # We failed connecting to the daemon, but lets try 
again
+                            if try_counter:
+                                log.info("Retrying connection.. Retries left: 
%s", try_counter)
+                                try_counter -= 1
+                                import time
+                                time.sleep(0.5)
+                                do_connect()
+                            return result
+                            
+                        def do_connect():
+                            
client.connect(*host[1:]).addCallback(on_connect).addErrback(on_connect_fail, 
try_counter)
+                                                    
+                        if try_connect:
+                            do_connect()
+                                                    
 
             if self.config["show_connection_manager_on_start"]:
                 # XXX: We need to call a simulate() here, but this could be a 
bug in twisted



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to