Skip to content

Commit

Permalink
Move ServerGroup and group_servers from ui.search to server
Browse files Browse the repository at this point in the history
To avoid unnecessary dependency of CLI on Gtk.
  • Loading branch information
jirutka authored and jwijenbergh committed Nov 19, 2024
1 parent c11c5fa commit 466e38f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.
3 changes: 2 additions & 1 deletion eduvpn/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
SecureInternetServer,
Server,
ServerDatabase,
ServerGroup,
group_servers,
)
from eduvpn.settings import (
CLIENT_ID,
Expand All @@ -30,7 +32,6 @@
LETSCONNECT_CLIENT_ID,
LETSCONNECT_CONFIG_PREFIX,
)
from eduvpn.ui.search import ServerGroup, group_servers
from eduvpn.ui.utils import get_validity_text, should_show_error, translated_error
from eduvpn.utils import (
FAILOVERED_STATE,
Expand Down
29 changes: 29 additions & 0 deletions eduvpn/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,32 @@ def search_predefined(self, query: str):

def search_custom(self, query: str) -> Iterable[Server]:
yield Server(query, query) # type: ignore[arg-type]


class ServerGroup(enum.Enum):
INSTITUTE_ACCESS = enum.auto()
SECURE_INTERNET = enum.auto()
OTHER = enum.auto()


def group_servers(servers):
"""
Separate the servers into three groups.
"""
groups: Dict[ServerGroup, List[Server]] = { # type: ignore
ServerGroup.INSTITUTE_ACCESS: [],
ServerGroup.SECURE_INTERNET: [],
ServerGroup.OTHER: [],
}
for server in servers:
if isinstance(server, InstituteServer) or (
isinstance(server, DiscoServer) and server.server_type == "institute_access"
):
groups[ServerGroup.INSTITUTE_ACCESS].append(server)
elif isinstance(server, SecureInternetServer) or isinstance(server, DiscoOrganization):
groups[ServerGroup.SECURE_INTERNET].append(server)
elif isinstance(server, Server):
groups[ServerGroup.OTHER].append(server)
else:
continue
return groups
36 changes: 1 addition & 35 deletions eduvpn/ui/search.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import enum
from typing import Dict, List

from gi.overrides.Gtk import ListStore # type: ignore
from gi.repository import GLib

from eduvpn.discovery import DiscoOrganization, DiscoServer
from eduvpn.i18n import retrieve_country_name
from eduvpn.server import InstituteServer, SecureInternetServer, Server
from eduvpn.server import SecureInternetServer, ServerGroup, group_servers
from eduvpn.ui.utils import show_ui_component
from eduvpn.utils import run_in_background_thread, run_in_glib_thread


class ServerGroup(enum.Enum):
INSTITUTE_ACCESS = enum.auto()
SECURE_INTERNET = enum.auto()
OTHER = enum.auto()


group_scroll_component = {
ServerGroup.INSTITUTE_ACCESS: "institute_list",
ServerGroup.SECURE_INTERNET: "secure_internet_list",
Expand Down Expand Up @@ -82,29 +71,6 @@ def show_search_results(window: "EduVpnGtkWindow", show: bool) -> None: # type:
show_ui_component(window.server_list_container, show)


def group_servers(servers):
"""
Separate the servers into three groups.
"""
groups: Dict[ServerGroup, List[Server]] = { # type: ignore
ServerGroup.INSTITUTE_ACCESS: [],
ServerGroup.SECURE_INTERNET: [],
ServerGroup.OTHER: [],
}
for server in servers:
if isinstance(server, InstituteServer) or (
isinstance(server, DiscoServer) and server.server_type == "institute_access"
):
groups[ServerGroup.INSTITUTE_ACCESS].append(server)
elif isinstance(server, SecureInternetServer) or isinstance(server, DiscoOrganization):
groups[ServerGroup.SECURE_INTERNET].append(server)
elif isinstance(server, Server):
groups[ServerGroup.OTHER].append(server)
else:
continue
return groups


def show_group_tree(window: "EduVpnGtkWindow", group: ServerGroup, show: bool) -> None: # type: ignore # noqa: F821
"""
Set the visibility of the tree of result for a server type.
Expand Down

0 comments on commit 466e38f

Please sign in to comment.