[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Simplify sort handling
commit fe2f2c33956d28bd6afd6f4c59688593fb1a653b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Aug 8 17:04:31 2015 -0700
Simplify sort handling
Move handling of 'sort by listing' to the panel which knows the listing type.
Also dropping the get_sort_values() which simply called get_sort_value() for
all entries.
---
nyx/connections/conn_panel.py | 13 ++++++++++++-
nyx/connections/entries.py | 38 +++++---------------------------------
2 files changed, 17 insertions(+), 34 deletions(-)
diff --git a/nyx/connections/conn_panel.py b/nyx/connections/conn_panel.py
index 76f6f16..6c17cad 100644
--- a/nyx/connections/conn_panel.py
+++ b/nyx/connections/conn_panel.py
@@ -158,7 +158,18 @@ class ConnectionPanel(panel.Panel, threading.Thread):
ordering_keys = [entries.SortAttr.keys()[entries.SortAttr.index_of(v)] for v in ordering]
nyx_config.set('features.connection.order', ', '.join(ordering_keys))
- self._entries.sort(key = lambda i: (i.get_sort_values(CONFIG['features.connection.order'], self.get_listing_type())))
+ def sort_type(attr):
+ if attr == entries.SortAttr.LISTING:
+ if self.get_listing_type() == entries.ListingType.IP_ADDRESS:
+ return entries.SortAttr.IP_ADDRESS
+ elif self.get_listing_type() == entries.ListingType.FINGERPRINT:
+ return entries.SortAttr.FINGERPRINT
+ elif self.get_listing_type() == entries.ListingType.NICKNAME:
+ return entries.SortAttr.NICKNAME
+
+ return attr
+
+ self._entries.sort(key = lambda i: [i.get_sort_value(sort_type(attr)) for attr in CONFIG['features.connection.order']])
self._entry_lines = list(itertools.chain.from_iterable([entry.get_lines() for entry in self._entries]))
def get_listing_type(self):
diff --git a/nyx/connections/entries.py b/nyx/connections/entries.py
index 4fb981d..f0b06d3 100644
--- a/nyx/connections/entries.py
+++ b/nyx/connections/entries.py
@@ -132,20 +132,7 @@ class ConnectionPanelEntry:
return self.lines
- def get_sort_values(self, sort_attrs, listing_type):
- """
- Provides the value used in comparisons to sort based on the given
- attribute.
-
- Arguments:
- sort_attrs - list of SortAttr values for the field being sorted on
- listing_type - ListingType enumeration for the attribute we're listing
- entries by
- """
-
- return [self.get_sort_value(attr, listing_type) for attr in sort_attrs]
-
- def get_sort_value(self, attr, listing_type):
+ def get_sort_value(self, attr):
"""
Provides the value of a single attribute used for sorting purposes.
"""
@@ -156,18 +143,15 @@ class ConnectionPanelEntry:
if self.is_private():
return SCRUBBED_IP_VAL # orders at the end
- return address_to_int(connection_line.connection.remote_address)
+ sort_value = address_to_int(connection_line.connection.remote_address) * PORT_COUNT
+ sort_value += connection_line.connection.remote_port
+ return sort_value
elif attr == SortAttr.PORT:
return connection_line.connection.remote_port
elif attr == SortAttr.FINGERPRINT:
return connection_line.get_fingerprint('UNKNOWN')
elif attr == SortAttr.NICKNAME:
- my_nickname = connection_line.get_nickname()
-
- if my_nickname:
- return my_nickname.lower()
- else:
- return 'z' * 20 # orders at the end
+ return connection_line.get_nickname('z' * 20)
elif attr == SortAttr.CATEGORY:
import nyx.connections.conn_entry
return nyx.connections.conn_entry.Category.index_of(self.get_type())
@@ -178,16 +162,6 @@ class ConnectionPanelEntry:
return ''
else:
return connection_line.get_locale('')
- elif attr == SortAttr.LISTING:
- if listing_type == ListingType.IP_ADDRESS:
- # uses the IP address as the primary value, and port as secondary
- sort_value = self.get_sort_value(SortAttr.IP_ADDRESS, listing_type) * PORT_COUNT
- sort_value += self.get_sort_value(SortAttr.PORT, listing_type)
- return sort_value
- elif listing_type == ListingType.FINGERPRINT:
- return self.get_sort_value(SortAttr.FINGERPRINT, listing_type)
- elif listing_type == ListingType.NICKNAME:
- return self.get_sort_value(SortAttr.NICKNAME, listing_type)
else:
return ''
@@ -224,8 +198,6 @@ class ConnectionPanelLine:
width - available space to display in
current_time - unix timestamp for what the results should consider to be
the current time (this may be ignored due to caching)
- listing_type - ListingType enumeration for the highest priority content
- to be displayed
"""
if self._listing_cache_args != (width, listing_type):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits