Module: deluge
Branch: master
Commit: 8a15a18361ec4625a4396a75d570a84d49faede2

Author: Pedro Algarvio, aka, s0undt3ch <[email protected]>
Date:   Mon Mar  8 02:06:15 2010 +0000

PEP-8 and seed/peer sorting support.

---

 deluge/core/core.py            |    9 ++--
 deluge/ui/gtkui/torrentview.py |  101 +++++++++++++++++++++------------------
 2 files changed, 59 insertions(+), 51 deletions(-)

diff --git a/deluge/core/core.py b/deluge/core/core.py
index 4b95e4d..939697b 100644
--- a/deluge/core/core.py
+++ b/deluge/core/core.py
@@ -17,9 +17,9 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with deluge.    If not, write to:
-#      The Free Software Foundation, Inc.,
-#      51 Franklin Street, Fifth Floor
-#      Boston, MA  02110-1301, USA.
+#     The Free Software Foundation, Inc.,
+#     51 Franklin Street, Fifth Floor
+#     Boston, MA  02110-1301, USA.
 #
 #    In addition, as a special exception, the copyright holders give
 #    permission to link the code of portions of this program with the OpenSSL
@@ -741,7 +741,8 @@ class Core(component.Component):
         """
         from twisted.web.client import getPage
 
-        d = getPage("http://deluge-torrent.org/test_port.php?port=%s"; % 
self.get_listen_port())
+        d = getPage("http://deluge-torrent.org/test_port.php?port=%s"; %
+                    self.get_listen_port(), timeout=30)
 
         def on_get_page(result):
             return bool(int(result))
diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py
index 7998fb1..2af62ef 100644
--- a/deluge/ui/gtkui/torrentview.py
+++ b/deluge/ui/gtkui/torrentview.py
@@ -148,6 +148,27 @@ def eta_column_sort(model, iter1, iter2, data):
     if v2 > v1:
         return -1
 
+def seed_peer_column_sort(model, iter1, iter2, data):
+    v1 = model[iter1][data]         # num seeds/peers
+    v3 = model[iter2][data]         # num seeds/peers
+    if v1 == v3:
+        v2 = model[iter1][data+1]   # total seeds/peers
+        v4 = model[iter2][data+1]   # total seeds/peers
+        if v2 == v4:
+            return 0
+        if v2 > v4:
+            return -1
+        if v2 < v4:
+            return 1
+    if v1 == 0:
+        return 1
+    if v3 == 0:
+        return -1
+    if v1 > v3:
+        return 1
+    if v3 > v1:
+        return -1
+
 class TorrentView(listview.ListView, component.Component):
     """TorrentView handles the listing of torrents."""
     def __init__(self):
@@ -176,54 +197,40 @@ class TorrentView(listview.ListView, component.Component):
         # Add the columns to the listview
         self.add_text_column("torrent_id", hidden=True)
         self.add_bool_column("dirty", hidden=True)
-        self.add_func_column("#", cell_data_queue, [int], 
status_field=["queue"], sort_func=queue_column_sort)
-        self.add_texticon_column(_("Name"), status_field=["state", "name"],
-                                            function=cell_data_statusicon)
-        self.add_func_column(_("Size"),
-                                            listview.cell_data_size,
-                                            [gobject.TYPE_UINT64],
-                                            status_field=["total_wanted"])
+        self.add_func_column("#", cell_data_queue, [int],
+                             status_field=["queue"],
+                             sort_func=queue_column_sort)
+        self.add_texticon_column(_("Name"),
+                                 status_field=["state", "name"],
+                                 function=cell_data_statusicon)
+        self.add_func_column(_("Size"), listview.cell_data_size,
+                             [gobject.TYPE_UINT64],
+                             status_field=["total_wanted"])
         self.add_progress_column(_("Progress"),
-                                    status_field=["progress", "state"],
-                                    col_types=[float, str],
-                                    function=cell_data_progress)
-        self.add_func_column(_("Seeders"),
-                                        listview.cell_data_peer,
-                                        [int, int],
-                                        status_field=["num_seeds",
-                                                        "total_seeds"])
-        self.add_func_column(_("Peers"),
-                                        listview.cell_data_peer,
-                                        [int, int],
-                                        status_field=["num_peers",
-                                                        "total_peers"])
-        self.add_func_column(_("Down Speed"),
-                                        listview.cell_data_speed,
-                                        [float],
-                                        status_field=["download_payload_rate"])
-        self.add_func_column(_("Up Speed"),
-                                        listview.cell_data_speed,
-                                        [float],
-                                        status_field=["upload_payload_rate"])
-        self.add_func_column(_("ETA"),
-                                            listview.cell_data_time,
-                                            [int],
-                                            status_field=["eta"],
-                                            sort_func=eta_column_sort)
-        self.add_func_column(_("Ratio"),
-                                            listview.cell_data_ratio,
-                                            [float],
-                                            status_field=["ratio"])
-        self.add_func_column(_("Avail"),
-                                            listview.cell_data_ratio,
-                                            [float],
-                                            
status_field=["distributed_copies"])
-        self.add_func_column(_("Added"),
-                                            listview.cell_data_date,
-                                            [float],
-                                            status_field=["time_added"])
-        self.add_texticon_column(_("Tracker"), status_field=["tracker_host", 
"tracker_host"],
-                                    function=cell_data_trackericon)
+                                 status_field=["progress", "state"],
+                                 col_types=[float, str],
+                                 function=cell_data_progress)
+        self.add_func_column(_("Seeders"), listview.cell_data_peer, [int, int],
+                             status_field=["num_seeds", "total_seeds"],
+                             sort_func=seed_peer_column_sort)
+        self.add_func_column(_("Peers"), listview.cell_data_peer, [int, int],
+                             status_field=["num_peers", "total_peers"],
+                             sort_func=seed_peer_column_sort)
+        self.add_func_column(_("Down Speed"), listview.cell_data_speed, 
[float],
+                             status_field=["download_payload_rate"])
+        self.add_func_column(_("Up Speed"), listview.cell_data_speed, [float],
+                             status_field=["upload_payload_rate"])
+        self.add_func_column(_("ETA"), listview.cell_data_time, [int],
+                             status_field=["eta"], sort_func=eta_column_sort)
+        self.add_func_column(_("Ratio"), listview.cell_data_ratio, [float],
+                             status_field=["ratio"])
+        self.add_func_column(_("Avail"), listview.cell_data_ratio, [float],
+                             status_field=["distributed_copies"])
+        self.add_func_column(_("Added"), listview.cell_data_date, [float],
+                             status_field=["time_added"])
+        self.add_texticon_column(_("Tracker"),
+                                 status_field=["tracker_host", "tracker_host"],
+                                 function=cell_data_trackericon)
 
         self.add_text_column(_("Save Path"), status_field=["save_path"])
 

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