Author: johnnyg

Revision: 5551

Log:
        download_file now returns the filename of the downloaded file
when the deferred is successfully fired.
Updated the docstrings in HTTPDownloader.

Diff:
Modified: trunk/deluge/core/core.py
===================================================================
--- trunk/deluge/core/core.py   2009-07-25 01:49:05 UTC (rev 5550)
+++ trunk/deluge/core/core.py   2009-07-25 03:56:33 UTC (rev 5551)
@@ -267,7 +267,7 @@
         :returns: a Deferred which returns the torrent_id as a str or None
         """
         log.info("Attempting to add url %s", url)
-        def on_get_file(result):
+        def on_get_file(filename):
             # We got the file, so add it to the session
             data = open(filename, "rb").read()
             return self.add_torrent_file(filename, base64.encodestring(data), 
options)
@@ -278,8 +278,7 @@
             log.error("Reason: %s", failure.getErrorMessage())
             return failure
 
-        filename = url.split("/")[-1]
-        d = download_file(url, filename, headers=headers)
+        d = download_file(url, url.split("/")[-1], headers=headers)
         d.addCallback(on_get_file)
         d.addErrback(on_get_file_error)
         return d

Modified: trunk/deluge/httpdownloader.py
===================================================================
--- trunk/deluge/httpdownloader.py      2009-07-25 01:49:05 UTC (rev 5550)
+++ trunk/deluge/httpdownloader.py      2009-07-25 03:56:33 UTC (rev 5551)
@@ -43,14 +43,19 @@
     """
     def __init__(self, url, filename, part_callback=None, headers=None):
         """
-        :param url: str, the url to download from
-        :param filename: str, the filename to save the file as
-        :param part_callback: func, a function to be called when a part of data
+        :param url: the url to download from
+        :type url: string
+        :param filename: the filename to save the file as
+        :type filename: string
+        :param part_callback: a function to be called when a part of data
             is received, it's signature should be: func(data, current_length, 
total_length)
-        :param headers: dict, any optional headers to send
+        :type part_callback: function
+        :param headers: any optional headers to send
+        :type headers: dictionary
         """
         self.__part_callback = part_callback
         self.current_length = 0
+        self.value = filename
         client.HTTPDownloader.__init__(self, url, filename, headers=headers)
 
     def gotStatus(self, version, status, message):
@@ -83,11 +88,19 @@
     Downloads a file from a specific URL and returns a Deferred.  You can also
     specify a callback function to be called as parts are received.
 
-    :param url: str, the url to download from
-    :param filename: str, the filename to save the file as
-    :param callback: func, a function to be called when a part of data is 
received,
+    :param url: the url to download from
+    :type url: string
+    :param filename: the filename to save the file as
+    :type filename: string
+    :param callback: a function to be called when a part of data is received,
          it's signature should be: func(data, current_length, total_length)
-    :param headers: dict, any optional headers to send
+    :type callback: function
+    :param headers: any optional headers to send
+    :type headers: dictionary
+
+    :returns: the filename of the downloaded file
+    :rtype: Deferred
+
     :raises t.w.e.PageRedirect: when server responds with a temporary redirect
          or permanently moved.
     :raises t.w.e.Error: for all other HTTP response errors (besides OK)

Modified: trunk/deluge/ui/gtkui/addtorrentdialog.py
===================================================================
--- trunk/deluge/ui/gtkui/addtorrentdialog.py   2009-07-25 01:49:05 UTC (rev 
5550)
+++ trunk/deluge/ui/gtkui/addtorrentdialog.py   2009-07-25 03:56:33 UTC (rev 
5551)
@@ -636,7 +636,7 @@
 
         def on_download_success(result):
             log.debug("Download success!")
-            self.add_from_files([tmp_file])
+            self.add_from_files([result])
             dialog.destroy()
 
         def on_download_fail(result):

Modified: trunk/deluge/ui/web/json_api.py
===================================================================
--- trunk/deluge/ui/web/json_api.py     2009-07-25 01:49:05 UTC (rev 5550)
+++ trunk/deluge/ui/web/json_api.py     2009-07-25 03:56:33 UTC (rev 5551)
@@ -456,12 +456,9 @@
         """
         
         tmp_file = os.path.join(tempfile.gettempdir(), url.split("/")[-1])
-        return httpdownloader.download_file(url, 
tmp_file).addCallback(self._on_torrent_downloaded, tmp_file)
+        log.debug("filename: %s", tmp_file)
+        return httpdownloader.download_file(url, tmp_file)
     
-    def _on_torrent_downloaded(self, result, filename):
-        log.debug("filename: %s", filename)
-        return filename
-
     @export
     def get_torrent_info(self, filename):
         """



--~--~---------~--~----~------------~-------~--~----~
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