Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
All: Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijenbergh committed Oct 29, 2024
1 parent dcfbd17 commit e2cc8ba
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 100 deletions.
4 changes: 2 additions & 2 deletions eduvpn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@


class SettingDescriptor(Generic[T]):
def __set_name__(self, owner: Type["Configuration"], name: str) -> None:
def __set_name__(self, _owner: Type["Configuration"], name: str) -> None:
self.name = name

def __get__(self, instance: Type["Configuration"], owner: Type["Configuration"]) -> bool:
def __get__(self, instance: Type["Configuration"], _owner: Type["Configuration"]) -> bool:
return instance.get_setting(self.name) # type: ignore

def __set__(self, instance: Type["Configuration"], value: T) -> None:
Expand Down
23 changes: 1 addition & 22 deletions eduvpn/nm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from shutil import rmtree
from socket import AF_INET, AF_INET6, IPPROTO_TCP, SOCK_DGRAM, socket
from tempfile import mkdtemp
from typing import Any, Callable, Optional, TextIO, Tuple
from typing import Any, Callable, Optional, TextIO

from eduvpn_common.main import EduVPN, Jar
from gi.repository.Gio import Cancellable, Task # type: ignore
Expand Down Expand Up @@ -348,17 +348,6 @@ def ovpn_import(self, target: Path) -> Optional["NM.Connection"]:
conn.normalize()
return conn

def import_ovpn_with_certificate(self, ovpn: Ovpn, private_key: str, certificate: str) -> "NM.SimpleConnection":
"""
Import the OVPN string into Network Manager.
"""
target_parent = Path(mkdtemp())
target = target_parent / f"{self.variant.name}.ovpn"
write_ovpn(ovpn, private_key, certificate, target)
connection = self.ovpn_import(target)
rmtree(target_parent)
return connection

def import_ovpn(self, ovpn: Ovpn) -> "NM.SimpleConnection":
"""
Import the OVPN string into Network Manager.
Expand Down Expand Up @@ -911,16 +900,6 @@ def wrapped_connection_added(client: "NM.Client", active_con: "NM.ActiveConnecti
self.client.connect("active-connection-added", wrapped_connection_added)
return True

def connection_status(
self,
) -> Tuple[Optional[str], Optional["NM.ActiveConnectionState"]]:
con = self.client.get_primary_connection()
if not isinstance(con, NM.VpnConnection):
return None, None
uuid = con.get_uuid()
status = con.get_state()
return uuid, status


def action_with_mainloop(action: Callable):
_logger.debug("calling action with CLI mainloop")
Expand Down
25 changes: 0 additions & 25 deletions eduvpn/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from eduvpn.settings import IMAGE_PREFIX

logger = logging.getLogger(__name__)
TranslatedStr = Union[str, Dict[str, str]]


class Profile:
Expand Down Expand Up @@ -85,14 +84,6 @@ def identifier(self) -> str:
def category_id(self) -> ServerType:
return ServerType.CUSTOM

@property
def category(self) -> str:
"""Return the category of the server as a string
:return: The category string
:rtype: str
"""
return str(self.category_id)


class InstituteServer(Server):
"""The class that represents an Institute Access Server
Expand All @@ -117,14 +108,6 @@ def __init__(
def category_id(self) -> ServerType:
return ServerType.INSTITUTE_ACCESS

@property
def category(self) -> str:
"""Return the category of the server as a string
:return: The category string
:rtype: str
"""
return str(self.category_id)


class SecureInternetServer(Server):
"""The class that represents a Secure Internet Server
Expand Down Expand Up @@ -157,14 +140,6 @@ def __init__(
def category_id(self) -> ServerType:
return ServerType.SECURE_INTERNET

@property
def category(self) -> str:
"""Return the category of the server as a string
:return: The category string
:rtype: str
"""
return str(self.category_id)


def parse_secure_internet(si: dict) -> Optional[SecureInternetServer]:
profiles = parse_profiles(si["profiles"])
Expand Down
1 change: 0 additions & 1 deletion eduvpn/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This module contains code to maintain a simple metadata storage in ~/.config/eduvpn/
"""

from os import PathLike
from typing import Optional

from eduvpn.ovpn import Ovpn
Expand Down
2 changes: 1 addition & 1 deletion eduvpn/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def expired_deactivate():
expired_deactivate()

@ui_transition(State.GOT_CONFIG, StateType.ENTER)
def enter_NoActiveConnection(self, old_state, new_state):
def enter_NoActiveConnection(self, _old_state, _new_state):
if not self.window.is_visible():
# Quit the app if no window is open when the connection is deactivated.
logger.debug("connection deactivated while window closed")
Expand Down
69 changes: 20 additions & 49 deletions eduvpn/ui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def is_dark(rgb):
class ValidityTimers:
def __init__(self):
self.cancel_timers = []
self.num = 0

def add_absolute(self, call: Callable, abstime: datetime):
delta = abstime - datetime.now()
Expand Down Expand Up @@ -182,7 +181,6 @@ def setup(self, builder: Builder, application: Type["EduVpnGtkApplication"]) ->
# Whether or not the profile that is selected is the 'same' one as before
# This is used so it doesn't fully trigger the callback
self.set_same_profile = False
self.is_selected = False

self.app_logo = builder.get_object("appLogo")
self.app_logo_info = builder.get_object("appLogoInfo")
Expand Down Expand Up @@ -681,29 +679,6 @@ def update_connection_validity(self, validity: Validity) -> None:

self.eduvpn_app.enter_SessionExpiredState()

# Shows notifications according to https://docs.eduvpn.org/server/v3/client-implementation-notes.html#expiry
# The 0th case is handled with a separate notification inside of the expiry text handler
def ensure_expiry_notification_text(self, validity: Validity) -> None:
hours = [4, 2, 1]
for h in hours:
if h in self.shown_notification_times:
continue
delta = validity.remaining - timedelta(hours=h)
total_secs = delta.total_seconds()
if total_secs <= 0 and total_secs >= -120:
self.eduvpn_app.enter_SessionPendingExpiryState(h)
self.shown_notification_times.add(h)
break

# Show renew button or not
def update_connection_renew(self, expire_time) -> None:
if self.app.model.should_renew_button():
# Show renew button
self.renew_session_button.show()

validity = self.app.model.get_expiry(expire_time)
self.ensure_expiry_notification_text(validity)

def update_connection_status(self, connected: bool) -> None:
if connected:
self.connection_status_label.set_text(_("Connected"))
Expand Down Expand Up @@ -805,10 +780,6 @@ def exit_search(self):
search.show_search_components(self, False)
search.exit_server_search(self)

def exit_ConfigureCustomServer(self, old_state, new_state):
if not self.app.variant.use_predefined_servers:
self.add_custom_server_button_container.hide()

def fill_secure_location_combo(self, curr, locs):
locs_store = Gtk.ListStore(GdkPixbuf.Pixbuf, GObject.TYPE_STRING, GObject.TYPE_STRING)
active_loc = 0
Expand Down Expand Up @@ -869,46 +840,46 @@ def enter_MainState(self, old_state: str, servers):
self.app.config.ignore_keyring_warning = self.keyring_do_not_show.get_active()

@ui_transition(State.MAIN, StateType.LEAVE)
def exit_MainState(self, old_state, new_state):
def exit_MainState(self, _old_state, _data):
search.show_result_components(self, False)
self.add_other_server_button_container.hide()
search.exit_server_search(self)
self.change_location_combo.hide()

@ui_transition(State.OAUTH_STARTED, StateType.ENTER)
def enter_oauth_setup(self, old_state, url):
def enter_oauth_setup(self, _old_state, data):
self.show_page(self.oauth_page)
self.oauth_cancel_button.show()

@ui_transition(State.OAUTH_STARTED, StateType.LEAVE)
def exit_oauth_setup(self, old_state, data):
def exit_oauth_setup(self, _old_state, _data):
self.hide_page(self.oauth_page)
self.oauth_cancel_button.hide()

@ui_transition(State.ADDING_SERVER, StateType.ENTER)
def enter_chosenServerInformation(self, new_state, data):
def enter_chosenServerInformation(self, _old_state, _data):
self.show_loading_page(
_("Adding server"),
_("Loading server information..."),
)

@ui_transition(State.ADDING_SERVER, StateType.LEAVE)
def exit_chosenServerInformation(self, old_state, data):
def exit_chosenServerInformation(self, _old_state, _data):
self.hide_loading_page()

@ui_transition(State.GETTING_CONFIG, StateType.ENTER)
def enter_GettingConfig(self, new_state, data):
def enter_GettingConfig(self, _old_state, _data):
self.show_loading_page(
_("Getting a VPN configuration"),
_("Loading server information..."),
)

@ui_transition(State.GETTING_CONFIG, StateType.LEAVE)
def exit_GettingConfig(self, old_state, data):
def exit_GettingConfig(self, _old_state, _data):
self.hide_loading_page()

@ui_transition(State.ASK_PROFILE, StateType.ENTER)
def enter_ChooseProfile(self, new_state, data):
def enter_ChooseProfile(self, _old_state, data):
self.show_back_button(True)
self.show_page(self.choose_profile_page)
self.profile_list.show()
Expand All @@ -935,13 +906,13 @@ def enter_ChooseProfile(self, new_state, data):
profiles_list_model.append([str(profile), (setter, profile_id)])

@ui_transition(State.ASK_PROFILE, StateType.LEAVE)
def exit_ChooseProfile(self, old_state, data):
def exit_ChooseProfile(self, old_state, _data):
self.show_back_button(False)
self.hide_page(self.choose_profile_page)
self.profile_list.hide()

@ui_transition(State.ASK_LOCATION, StateType.ENTER)
def enter_ChooseSecureInternetLocation(self, old_state, data):
def enter_ChooseSecureInternetLocation(self, _old_state, data):
self.show_back_button(True)
self.show_page(self.choose_location_page)
self.location_list.show()
Expand Down Expand Up @@ -979,7 +950,7 @@ def enter_ChooseSecureInternetLocation(self, old_state, data):
location_list_model.append([retrieve_country_name(location), flag, (setter, location)])

@ui_transition(State.ASK_LOCATION, StateType.LEAVE)
def exit_ChooseSecureInternetLocation(self, old_state, new_state):
def exit_ChooseSecureInternetLocation(self, _old_state, _data):
self.show_back_button(False)
self.hide_loading_page()
self.hide_page(self.choose_location_page)
Expand All @@ -990,7 +961,7 @@ def enter_GotConfig(self, old_state: str, server_info) -> None:
self.enter_connecting(old_state, server_info)

@ui_transition(State.DISCONNECTED, StateType.ENTER)
def enter_ConnectionStatus(self, old_state: str, server_info):
def enter_ConnectionStatus(self, _old_state: str, server_info):
self.show_back_button(True)
self.show_page(self.connection_page)
self.update_connection_status(False)
Expand All @@ -1005,12 +976,12 @@ def enter_ConnectionStatus(self, old_state: str, server_info):
self.renew_session_button.hide()

@ui_transition(State.DISCONNECTED, StateType.LEAVE)
def exit_ConnectionStatus(self, old_state, new_state):
def exit_ConnectionStatus(self, _old_state, _data):
self.show_back_button(False)
self.hide_page(self.connection_page)

@ui_transition(State.CONNECTED, StateType.LEAVE)
def leave_ConnectedState(self, old_state, server_info):
def leave_ConnectedState(self, _old_state, _server_info):
logger.debug("leave connected state")
self.reconnect_tcp_button.hide()
self.reconnect_tcp_text.hide()
Expand All @@ -1025,7 +996,7 @@ def leave_ConnectedState(self, old_state, server_info):
self.stop_connection_info()

@ui_transition(State.CONNECTED, StateType.ENTER)
def enter_ConnectedState(self, old_state, server_data):
def enter_ConnectedState(self, _old_state, server_data):
self.renew_session_button.hide()
server_info, validity = server_data
self.connection_info_expander.show()
Expand Down Expand Up @@ -1081,19 +1052,19 @@ def stop_validity_threads(self) -> None:
self.connection_validity_thread_cancel = None
self.connection_validity_timers.clean()

def on_info_delete(self, widget, event):
def on_info_delete(self, widget, _):
logger.debug("info dialog delete event")
return widget.hide_on_delete()

def on_info_button(self, widget: EventBox, event: EventButton) -> None:
def on_info_button(self, _box: EventBox, _button: EventButton) -> None:
logger.debug("clicked info button")
self.info_dialog.set_title(f"{self.app.variant.name} - Info")
self.info_dialog.show()
self.info_dialog.run()
self.info_dialog.hide()

@ui_transition(SERVER_LIST_REFRESH_STATE, StateType.ENTER) # type: ignore
def enter_server_list_refresh(self, old_state, servers) -> None:
def enter_server_list_refresh(self, _old_state, servers) -> None:
logger.debug("server list refresh")
if self.is_searching_server:
return
Expand Down Expand Up @@ -1233,7 +1204,7 @@ def on_change_location(self, combo):
# Set profile and connect
self.call_model("change_secure_location", location)

def on_search_changed(self, _: Optional[SearchEntry] = None) -> None:
def on_search_changed(self, _searchentry: Optional[SearchEntry] = None) -> None:
query = self.find_server_search_input.get_text()
if self.app.variant.use_predefined_servers and query.count(".") < 2:
results = self.app.model.search_predefined(query)
Expand Down Expand Up @@ -1455,7 +1426,7 @@ def on_renew(success: bool):
def on_reconnect_tcp_clicked(self, event):
logger.debug("clicked on reconnect TCP")

def on_reconnected(_: bool):
def on_reconnected(_success: bool):
logger.debug("done reconnecting with tcp")
self.reconnect_tcp_button.hide()
self.reconnect_tcp_text.hide()
Expand Down

0 comments on commit e2cc8ba

Please sign in to comment.