Skip to content

Commit

Permalink
refactor: add type hints and comments
Browse files Browse the repository at this point in the history
Small handfull of comments on things I noticed while reading

No functional changes
  • Loading branch information
ctrlaltf24 authored and thw26 committed Oct 24, 2024
1 parent 0def2e5 commit 1770c8d
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 49 deletions.
2 changes: 1 addition & 1 deletion ou_dedetai/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class CLI:
def __init__(self):
self.running = True
self.running: bool = True
self.choice_q = queue.Queue()
self.input_q = queue.Queue()
self.input_event = threading.Event()
Expand Down
67 changes: 34 additions & 33 deletions ou_dedetai/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import tempfile
from datetime import datetime
from typing import Optional


# Define app name variables.
Expand Down Expand Up @@ -59,55 +60,55 @@
globals()[key] = os.getenv(key, default)

# Set other run-time variables not set in the env.
ACTION = 'app'
APPIMAGE_FILE_PATH = None
authenticated = False
BADPACKAGES = None
ACTION: str = 'app'
APPIMAGE_FILE_PATH: Optional[str] = None
authenticated = False # FIXME: no references
BADPACKAGES: Optional[str] = None # FIXME: no references
DEFAULT_CONFIG_PATH = os.path.expanduser(f"~/.config/FaithLife-Community/{name_binary}.json") # noqa: E501
FLPRODUCTi = None
GUI = None
INSTALL_STEP = 0
INSTALL_STEPS_COUNT = 0
FLPRODUCTi: Optional[str] = None
GUI = None # FIXME: no references
INSTALL_STEP: int = 0
INSTALL_STEPS_COUNT: int = 0
L9PACKAGES = None
LEGACY_CONFIG_FILE = os.path.expanduser("~/.config/Logos_on_Linux/Logos_on_Linux.conf") # noqa: E501
LLI_AUTHOR = "Ferion11, John Goodman, T. H. Wright, N. Marti"
LLI_CURRENT_VERSION = "4.0.0-beta.2"
LLI_LATEST_VERSION = None
LLI_LATEST_VERSION: Optional[str] = None
LLI_TITLE = name_app
LOG_LEVEL = logging.WARNING
LOGOS_BLUE = '#0082FF'
LOGOS_GRAY = '#E7E7E7'
LOGOS_WHITE = '#FCFCFC'
# LOGOS_WHITE = '#F7F7F7'
LOGOS_DIR = os.path.dirname(LOGOS_EXE) if LOGOS_EXE else None # noqa: F821
LOGOS_FORCE_ROOT = False
LOGOS_ICON_FILENAME = None
LOGOS_ICON_URL = None
LOGOS_FORCE_ROOT: bool = False
LOGOS_ICON_FILENAME: Optional[str] = None
LOGOS_ICON_URL: Optional[str] = None
LOGOS_LATEST_VERSION_FILENAME = name_binary
LOGOS_LATEST_VERSION_URL = None
LOGOS9_RELEASES = None # used to save downloaded releases list
LOGOS_LATEST_VERSION_URL: Optional[str] = None
LOGOS9_RELEASES = None # used to save downloaded releases list # FIXME: not set #noqa: E501
LOGOS9_WINE64_BOTTLE_TARGZ_NAME = "wine64_bottle.tar.gz"
LOGOS9_WINE64_BOTTLE_TARGZ_URL = f"https://github.com/ferion11/wine64_bottle_dotnet/releases/download/v5.11b/{LOGOS9_WINE64_BOTTLE_TARGZ_NAME}" # noqa: E501
LOGOS10_RELEASES = None # used to save downloaded releases list
MYDOWNLOADS = None
OS_NAME = None
OS_RELEASE = None
PACKAGE_MANAGER_COMMAND_INSTALL = None
PACKAGE_MANAGER_COMMAND_REMOVE = None
PACKAGE_MANAGER_COMMAND_QUERY = None
PACKAGES = None
PASSIVE = None
LOGOS10_RELEASES = None # used to save downloaded releases list # FIXME: not set #noqa: E501
MYDOWNLOADS: Optional[str] = None # FIXME: Should this use the tempfile module?
OS_NAME: Optional[str] = None
OS_RELEASE: Optional[str] = None
PACKAGE_MANAGER_COMMAND_INSTALL: Optional[list[str]] = None
PACKAGE_MANAGER_COMMAND_REMOVE: Optional[list[str]] = None
PACKAGE_MANAGER_COMMAND_QUERY: Optional[list[str]] = None
PACKAGES: Optional[str] = None
PASSIVE: Optional[bool] = None
pid_file = f'/tmp/{name_binary}.pid'
PRESENT_WORKING_DIRECTORY = os.getcwd()
QUERY_PREFIX = None
REBOOT_REQUIRED = None
RECOMMENDED_WINE64_APPIMAGE_FULL_FILENAME = None
RECOMMENDED_WINE64_APPIMAGE_FULL_VERSION = None
RECOMMENDED_WINE64_APPIMAGE_FILENAME = None
RECOMMENDED_WINE64_APPIMAGE_VERSION = None
RECOMMENDED_WINE64_APPIMAGE_BRANCH = None
SUPERUSER_COMMAND = None
VERBUM_PATH = None
PRESENT_WORKING_DIRECTORY: str = os.getcwd()
QUERY_PREFIX: Optional[str] = None
REBOOT_REQUIRED: Optional[str] = None
RECOMMENDED_WINE64_APPIMAGE_FULL_FILENAME: Optional[str] = None
RECOMMENDED_WINE64_APPIMAGE_FULL_VERSION: Optional[str] = None
RECOMMENDED_WINE64_APPIMAGE_FILENAME: Optional[str] = None
RECOMMENDED_WINE64_APPIMAGE_VERSION: Optional[str] = None
RECOMMENDED_WINE64_APPIMAGE_BRANCH: Optional[str] = None
SUPERUSER_COMMAND: Optional[str] = None
VERBUM_PATH: Optional[str] = None
WINETRICKS_URL = "https://raw.githubusercontent.com/Winetricks/winetricks/5904ee355e37dff4a3ab37e1573c56cffe6ce223/src/winetricks" # noqa: E501
WINETRICKS_VERSION = '20220411'
wine_user = None
Expand Down
8 changes: 5 additions & 3 deletions ou_dedetai/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def restore(app=None):
backup_and_restore(mode='restore', app=app)


# FIXME: consider moving this into it's own file/module.
def backup_and_restore(mode='backup', app=None):
data_dirs = ['Data', 'Documents', 'Users']
# Ensure BACKUPDIR is defined.
Expand Down Expand Up @@ -268,8 +269,8 @@ def set_winetricks():
# Check if local winetricks version is up-to-date; if so, offer to
# use it or to download; else, download it.
local_winetricks_version = subprocess.check_output(["winetricks", "--version"]).split()[0] # noqa: E501
if str(local_winetricks_version) >= "20220411":
if config.DIALOG == 'tk':
if str(local_winetricks_version) >= "20220411": #FIXME: consider using config.WINETRICKS_VERSION and != string comparision on versions is dodgy #noqa: E501
if config.DIALOG == 'tk': #FIXME: CLI client not considered
logging.info("Setting winetricks to the local binary…")
config.WINETRICKSBIN = local_winetricks_path
else:
Expand All @@ -296,6 +297,7 @@ def set_winetricks():
)
return 0
else:
# FIXME: Should this call a function on the app object?
msg.status("Installation canceled!")
sys.exit(0)
else:
Expand All @@ -319,7 +321,7 @@ def set_winetricks():
return 0


def download_winetricks():
def download_winetricks(): #FIXME: unused, logic moved to system.install_winetricks
msg.status("Downloading winetricks…")
appdir_bindir = f"{config.INSTALLDIR}/data/bin"
network.logos_reuse_download(
Expand Down
3 changes: 2 additions & 1 deletion ou_dedetai/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ def ensure_launcher_shortcuts(app=None):
ensure_launcher_executable(app=app)
config.INSTALL_STEP += 1
runmode = system.get_runmode()
# FIXME: why not do this all the time?
if runmode == 'binary':
update_install_feedback("Creating launcher shortcuts…", app=app)
create_launcher_shortcuts()
Expand Down Expand Up @@ -741,7 +742,7 @@ def create_wine_appimage_symlinks(app=None):
p.symlink_to(f"./{config.APPIMAGE_LINK_SELECTION_NAME}")


def get_flproducti_name(product_name):
def get_flproducti_name(product_name) -> str:
lname = product_name.lower()
if lname == 'logos':
return 'logos4'
Expand Down
6 changes: 4 additions & 2 deletions ou_dedetai/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import queue
from typing import Optional
import requests
import shutil
import sys
Expand Down Expand Up @@ -383,15 +384,16 @@ def get_latest_release_data(repository):
return None


def get_first_asset_url(json_data):
def get_first_asset_url(json_data) -> Optional[str]:
release_url = None
if json_data:
# FIXME: Portential KeyError
release_url = json_data.get('assets')[0].get('browser_download_url')
logging.info(f"Release URL: {release_url}")
return release_url


def get_tag_name(json_data):
def get_tag_name(json_data) -> Optional[str]:
tag_name = None
if json_data:
tag_name = json_data.get('tag_name')
Expand Down
11 changes: 8 additions & 3 deletions ou_dedetai/system.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
import distro
import logging
import os
Expand All @@ -16,7 +17,7 @@


# TODO: Replace functions in control.py and wine.py with Popen command.
def run_command(command, retries=1, delay=0, **kwargs):
def run_command(command, retries=1, delay=0, **kwargs) -> Optional[subprocess.CompletedProcess[any]]:
check = kwargs.get("check", True)
text = kwargs.get("text", True)
capture_output = kwargs.get("capture_output", True)
Expand Down Expand Up @@ -259,7 +260,7 @@ def reboot():
sys.exit(0)


def t(command):
def t(command): # FIXME: unused, have_dep does the same thing
if shutil.which(command) is not None:
return True
else:
Expand All @@ -275,6 +276,7 @@ def tl(library):


def get_dialog():
# FIXME: wouldn't the cli still work without a DISPLAY? What about wayland?
if not os.environ.get('DISPLAY'):
msg.logos_error("The installer does not work unless you are running a display") # noqa: E501

Expand Down Expand Up @@ -481,6 +483,9 @@ def check_dialog_version():
if have_dep("dialog"):
try:
result = run_command(["dialog", "--version"])
if result is None:
print("Failed to run the 'dialog' command.") # noqa: E501
return None
version_info = result.stdout.strip()
if version_info.startswith("Version: "):
version_info = version_info[len("Version: "):]
Expand All @@ -493,7 +498,7 @@ def check_dialog_version():


def test_dialog_version():
version = check_dialog_version()
version: Optional[str] = check_dialog_version()

def parse_date(version):
try:
Expand Down
8 changes: 4 additions & 4 deletions ou_dedetai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import tkinter as tk
from packaging import version
from pathlib import Path
from typing import List, Union
from typing import List, Optional, Union

from . import config
from . import msg
Expand Down Expand Up @@ -225,7 +225,7 @@ def delete_symlink(symlink_path):
logging.error(f"Error removing symlink: {e}")


def check_dependencies(app=None):
def check_dependencies(app=None): # FIXME: misnomer, isn't this an install_dependencies
if config.TARGETVERSION:
targetversion = int(config.TARGETVERSION)
else:
Expand Down Expand Up @@ -442,7 +442,7 @@ def get_winetricks_options():
# Check if local winetricks version is up-to-date.
cmd = ["winetricks", "--version"]
local_winetricks_version = subprocess.check_output(cmd).split()[0]
if str(local_winetricks_version) >= "20220411":
if str(local_winetricks_version) >= "20220411": #FIXME: consider using config.WINETRICKS_VERSION and != string comparision on versions is dodgy #noqa: E501
winetricks_options.insert(0, local_winetricks_path)
else:
logging.info("Local winetricks is too old.")
Expand Down Expand Up @@ -509,7 +509,7 @@ def app_is_installed():
return config.LOGOS_EXE is not None and os.access(config.LOGOS_EXE, os.X_OK) # noqa: E501


def find_installed_product():
def find_installed_product() -> Optional[str]:
if config.FLPRODUCT and config.WINEPREFIX:
drive_c = Path(f"{config.WINEPREFIX}/drive_c/")
name = config.FLPRODUCT
Expand Down
5 changes: 3 additions & 2 deletions ou_dedetai/wine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import signal
import subprocess
from pathlib import Path
from typing import Optional

from . import config
from . import msg
Expand All @@ -16,8 +17,8 @@


def get_wine_user():
path = config.LOGOS_EXE
normalized_path = os.path.normpath(path)
path: Optional[str] = config.LOGOS_EXE
normalized_path: str = os.path.normpath(path)
path_parts = normalized_path.split(os.sep)
config.wine_user = path_parts[path_parts.index('users') + 1]

Expand Down

0 comments on commit 1770c8d

Please sign in to comment.