Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit f132bcf

Browse files
committed
Move ServerGroup and group_servers from ui.search to server
To avoid unnecessary dependency of CLI on Gtk.
1 parent c11c5fa commit f132bcf

File tree

3 files changed

+32
-36
lines changed

3 files changed

+32
-36
lines changed

eduvpn/cli.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
SecureInternetServer,
2323
Server,
2424
ServerDatabase,
25+
ServerGroup,
26+
group_servers,
2527
)
2628
from eduvpn.settings import (
2729
CLIENT_ID,
@@ -30,7 +32,6 @@
3032
LETSCONNECT_CLIENT_ID,
3133
LETSCONNECT_CONFIG_PREFIX,
3234
)
33-
from eduvpn.ui.search import ServerGroup, group_servers
3435
from eduvpn.ui.utils import get_validity_text, should_show_error, translated_error
3536
from eduvpn.utils import (
3637
FAILOVERED_STATE,

eduvpn/server.py

+29
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,32 @@ def search_predefined(self, query: str):
320320

321321
def search_custom(self, query: str) -> Iterable[Server]:
322322
yield Server(query, query) # type: ignore[arg-type]
323+
324+
325+
class ServerGroup(enum.Enum):
326+
INSTITUTE_ACCESS = enum.auto()
327+
SECURE_INTERNET = enum.auto()
328+
OTHER = enum.auto()
329+
330+
331+
def group_servers(servers):
332+
"""
333+
Separate the servers into three groups.
334+
"""
335+
groups: Dict[ServerGroup, List[Server]] = { # type: ignore
336+
ServerGroup.INSTITUTE_ACCESS: [],
337+
ServerGroup.SECURE_INTERNET: [],
338+
ServerGroup.OTHER: [],
339+
}
340+
for server in servers:
341+
if isinstance(server, InstituteServer) or (
342+
isinstance(server, DiscoServer) and server.server_type == "institute_access"
343+
):
344+
groups[ServerGroup.INSTITUTE_ACCESS].append(server)
345+
elif isinstance(server, SecureInternetServer) or isinstance(server, DiscoOrganization):
346+
groups[ServerGroup.SECURE_INTERNET].append(server)
347+
elif isinstance(server, Server):
348+
groups[ServerGroup.OTHER].append(server)
349+
else:
350+
continue
351+
return groups

eduvpn/ui/search.py

+1-35
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
import enum
2-
from typing import Dict, List
3-
41
from gi.overrides.Gtk import ListStore # type: ignore
52
from gi.repository import GLib
63

7-
from eduvpn.discovery import DiscoOrganization, DiscoServer
84
from eduvpn.i18n import retrieve_country_name
9-
from eduvpn.server import InstituteServer, SecureInternetServer, Server
5+
from eduvpn.server import SecureInternetServer, ServerGroup, group_servers
106
from eduvpn.ui.utils import show_ui_component
117
from eduvpn.utils import run_in_background_thread, run_in_glib_thread
128

13-
14-
class ServerGroup(enum.Enum):
15-
INSTITUTE_ACCESS = enum.auto()
16-
SECURE_INTERNET = enum.auto()
17-
OTHER = enum.auto()
18-
19-
209
group_scroll_component = {
2110
ServerGroup.INSTITUTE_ACCESS: "institute_list",
2211
ServerGroup.SECURE_INTERNET: "secure_internet_list",
@@ -82,29 +71,6 @@ def show_search_results(window: "EduVpnGtkWindow", show: bool) -> None: # type:
8271
show_ui_component(window.server_list_container, show)
8372

8473

85-
def group_servers(servers):
86-
"""
87-
Separate the servers into three groups.
88-
"""
89-
groups: Dict[ServerGroup, List[Server]] = { # type: ignore
90-
ServerGroup.INSTITUTE_ACCESS: [],
91-
ServerGroup.SECURE_INTERNET: [],
92-
ServerGroup.OTHER: [],
93-
}
94-
for server in servers:
95-
if isinstance(server, InstituteServer) or (
96-
isinstance(server, DiscoServer) and server.server_type == "institute_access"
97-
):
98-
groups[ServerGroup.INSTITUTE_ACCESS].append(server)
99-
elif isinstance(server, SecureInternetServer) or isinstance(server, DiscoOrganization):
100-
groups[ServerGroup.SECURE_INTERNET].append(server)
101-
elif isinstance(server, Server):
102-
groups[ServerGroup.OTHER].append(server)
103-
else:
104-
continue
105-
return groups
106-
107-
10874
def show_group_tree(window: "EduVpnGtkWindow", group: ServerGroup, show: bool) -> None: # type: ignore # noqa: F821
10975
"""
11076
Set the visibility of the tree of result for a server type.

0 commit comments

Comments
 (0)