move to module imports

This commit is contained in:
AAGaming
2023-09-25 13:06:46 -04:00
committed by marios8543
parent a7c358844c
commit bf83eabe6b
15 changed files with 63 additions and 49 deletions
+2 -2
View File
@@ -43,10 +43,10 @@ jobs:
run: pnpm run build
- name: Build Python Backend 🛠️
run: pyinstaller --noconfirm --onefile --name "PluginLoader" --add-data "./backend/static;/static" --add-data "./backend/locales;/locales" --add-data "./backend/legacy;/legacy" --add-data "./plugin;/plugin" --hidden-import=sqlite3 ./backend/main.py
run: pyinstaller --noconfirm --onefile --name "PluginLoader" --add-data "./backend/static;/backend/static" --add-data "./backend/locales;/backend/locales" --add-data "./backend/legacy;/backend/legacy" --add-data "./plugin;/plugin" --hidden-import=sqlite3 ./main.py
- name: Build Python Backend (noconsole) 🛠️
run: pyinstaller --noconfirm --noconsole --onefile --name "PluginLoader_noconsole" --add-data "./backend/static;/static" --add-data "./backend/locales;/locales" --add-data "./backend/legacy;/legacy" --add-data "./plugin;/plugin" --hidden-import=sqlite3 ./backend/main.py
run: pyinstaller --noconfirm --noconsole --onefile --name "PluginLoader_noconsole" --add-data "./backend/static;/backend/static" --add-data "./backend/locales;/backend/locales" --add-data "./backend/legacy;/backend/legacy" --add-data "./plugin;/plugin" --hidden-import=sqlite3 ./main.py
- name: Upload package artifact ⬆️
uses: actions/upload-artifact@v3
+1 -1
View File
@@ -86,7 +86,7 @@ jobs:
run: pnpm run build
- name: Build Python Backend 🛠️
run: pyinstaller --noconfirm --onefile --name "PluginLoader" --add-data ./backend/static:/static --add-data ./backend/locales:/locales --add-data ./backend/legacy:/legacy --add-data ./plugin:/plugin --hidden-import=sqlite3 ./backend/*.py
run: pyinstaller --noconfirm --onefile --name "PluginLoader" --add-data ./backend/static:/backend/static --add-data ./backend/locales:/backend/locales --add-data ./backend/legacy:/backend/legacy --add-data ./plugin:/plugin --hidden-import=sqlite3 ./main.py
- name: Upload package artifact ⬆️
if: ${{ !env.ACT }}
+1 -1
View File
@@ -13,11 +13,11 @@ from os import R_OK, W_OK, path, listdir, access, mkdir
from shutil import rmtree
from time import time
from zipfile import ZipFile
from localplatform import chown, chmod
from enum import IntEnum
from typing import Dict, List, TypedDict
# Local modules
from .localplatform import chown, chmod
from .loader import Loader, Plugins
from .helpers import get_ssl_context, download_remote_binary_to_path
from .settings import SettingsManager
+2 -2
View File
@@ -10,8 +10,8 @@ import certifi
from aiohttp.web import Request, Response, middleware
from aiohttp.typedefs import Handler
from aiohttp import ClientSession
import localplatform
from customtypes import UserType
from . import localplatform
from .customtypes import UserType
from logging import getLogger
REMOTE_DEBUGGER_UNIT = "steam-web-debug-portforward.service"
+4 -2
View File
@@ -11,7 +11,9 @@ from os.path import exists
from watchdog.events import RegexMatchingEventHandler, DirCreatedEvent, DirModifiedEvent, FileCreatedEvent, FileModifiedEvent # type: ignore
from watchdog.observers import Observer # type: ignore
from backend.main import PluginManager # type: ignore
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .main import PluginManager
from .injector import get_tab, get_gamepadui_tab
from .plugin import PluginWrapper
@@ -63,7 +65,7 @@ class FileChangeHandler(RegexMatchingEventHandler):
self.maybe_reload(src_path)
class Loader:
def __init__(self, server_instance: PluginManager, plugin_path: str, loop: AbstractEventLoop, live_reload: bool =False) -> None:
def __init__(self, server_instance: 'PluginManager', plugin_path: str, loop: AbstractEventLoop, live_reload: bool = False) -> None:
self.loop = loop
self.logger = getLogger("Loader")
self.plugin_path = plugin_path
+4 -4
View File
@@ -4,11 +4,11 @@ ON_WINDOWS = platform.system() == "Windows"
ON_LINUX = not ON_WINDOWS
if ON_WINDOWS:
from localplatformwin import *
import localplatformwin as localplatform
from .localplatformwin import *
from . import localplatformwin as localplatform
else:
from localplatformlinux import *
import localplatformlinux as localplatform
from .localplatformlinux import *
from . import localplatformlinux as localplatform
def get_privileged_path() -> str:
'''Get path accessible by elevated user. Holds plugins, decky loader and decky loader configs'''
+1 -1
View File
@@ -1,6 +1,6 @@
import os, pwd, grp, sys, logging
from subprocess import call, run, DEVNULL, PIPE, STDOUT
from customtypes import UserType
from .customtypes import UserType
logger = logging.getLogger("localplatform")
+1 -1
View File
@@ -1,4 +1,4 @@
from customtypes import UserType
from .customtypes import UserType
import os, sys
def chown(path : str, user : UserType = UserType.HOST_USER, recursive : bool = True) -> bool:
+1 -1
View File
@@ -2,7 +2,7 @@ import asyncio, time
from typing import Awaitable, Callable
import random
from localplatform import ON_WINDOWS
from .localplatform import ON_WINDOWS
BUFFER_LIMIT = 2 ** 20 # 1 MiB
+10 -10
View File
@@ -1,7 +1,7 @@
# Change PyInstaller files permissions
import sys
from typing import Dict
from localplatform import (chmod, chown, service_stop, service_start,
from .localplatform import (chmod, chown, service_stop, service_start,
ON_WINDOWS, get_log_level, get_live_reload,
get_server_port, get_server_host, get_chown_plugin_path,
get_privileged_path)
@@ -21,16 +21,16 @@ from aiohttp.web import Application, Response, Request, get, run_app, static # t
from aiohttp_jinja2 import setup as jinja_setup
# local modules
from browser import PluginBrowser
from helpers import (REMOTE_DEBUGGER_UNIT, csrf_middleware, get_csrf_token,
from .browser import PluginBrowser
from .helpers import (REMOTE_DEBUGGER_UNIT, csrf_middleware, get_csrf_token,
mkdir_as_user, get_system_pythonpaths, get_effective_user_id)
from injector import get_gamepadui_tab, Tab, close_old_tabs
from loader import Loader
from settings import SettingsManager
from updater import Updater
from utilities import Utilities
from customtypes import UserType
from .injector import get_gamepadui_tab, Tab, close_old_tabs
from .loader import Loader
from .settings import SettingsManager
from .updater import Updater
from .utilities import Utilities
from .customtypes import UserType
basicConfig(
@@ -169,7 +169,7 @@ class PluginManager:
def run(self):
return run_app(self.web_app, host=get_server_host(), port=get_server_port(), loop=self.loop, access_log=None)
if __name__ == "__main__":
def main():
if ON_WINDOWS:
# Fix windows/flask not recognising that .js means 'application/javascript'
import mimetypes
+4 -4
View File
@@ -9,10 +9,10 @@ from os import path, environ
from signal import SIGINT, signal
from sys import exit, path as syspath
from typing import Any, Dict
from localsocket import LocalSocket
from localplatform import setgid, setuid, get_username, get_home_path
from customtypes import UserType
import helpers
from .localsocket import LocalSocket
from .localplatform import setgid, setuid, get_username, get_home_path
from .customtypes import UserType
from . import helpers
class PluginWrapper:
def __init__(self, file: str, plugin_directory: str, plugin_path: str) -> None:
+3 -3
View File
@@ -1,10 +1,10 @@
from json import dump, load
from os import mkdir, path, listdir, rename
from typing import Any, Dict
from localplatform import chown, folder_owner, get_chown_plugin_path
from customtypes import UserType
from .localplatform import chown, folder_owner, get_chown_plugin_path
from .customtypes import UserType
from helpers import get_homebrew_path
from .helpers import get_homebrew_path
class SettingsManager:
+14 -8
View File
@@ -4,15 +4,16 @@ from asyncio import sleep
from json.decoder import JSONDecodeError
from logging import getLogger
from os import getcwd, path, remove
from typing import List, TypedDict
from backend.main import PluginManager
from localplatform import chmod, service_restart, ON_LINUX, get_keep_systemd_service, get_selinux
from typing import TYPE_CHECKING, List, TypedDict
if TYPE_CHECKING:
from .main import PluginManager
from .localplatform import chmod, service_restart, ON_LINUX, get_keep_systemd_service, get_selinux
from aiohttp import ClientSession, web
import helpers
from injector import get_gamepadui_tab
from settings import SettingsManager
from .import helpers
from .injector import get_gamepadui_tab
from .settings import SettingsManager
logger = getLogger("Updater")
@@ -25,7 +26,7 @@ class RemoteVer(TypedDict):
assets: List[RemoteVerAsset]
class Updater:
def __init__(self, context: PluginManager) -> None:
def __init__(self, context: 'PluginManager') -> None:
self.context = context
self.settings = self.context.settings
# Exposes updater methods to frontend
@@ -150,7 +151,12 @@ class Updater:
async def do_update(self):
logger.debug("Starting update.")
assert self.remoteVer
try:
assert self.remoteVer
except AssertionError:
logger.error("Unable to update as remoteVer is missing")
return
version = self.remoteVer["tag_name"]
download_url = None
download_filename = "PluginLoader" if ON_LINUX else "PluginLoader.exe"
+11 -9
View File
@@ -8,16 +8,18 @@ from stat import FILE_ATTRIBUTE_HIDDEN # type: ignore
from asyncio import StreamReader, StreamWriter, start_server, gather, open_connection
from aiohttp import ClientSession, web
from typing import Callable, Coroutine, Dict, Any, List, TypedDict
from typing import TYPE_CHECKING, Callable, Coroutine, Dict, Any, List, TypedDict
from logging import getLogger
from backend.browser import PluginInstallRequest, PluginInstallType
from backend.main import PluginManager
from injector import inject_to_tab, get_gamepadui_tab, close_old_tabs, get_tab
from pathlib import Path
from localplatform import ON_WINDOWS
import helpers
from localplatform import service_stop, service_start, get_home_path, get_username
from .browser import PluginInstallRequest, PluginInstallType
if TYPE_CHECKING:
from .main import PluginManager
from .injector import inject_to_tab, get_gamepadui_tab, close_old_tabs, get_tab
from .localplatform import ON_WINDOWS
from .import helpers
from .localplatform import service_stop, service_start, get_home_path, get_username
class FilePickerObj(TypedDict):
file: Path
@@ -25,7 +27,7 @@ class FilePickerObj(TypedDict):
is_dir: bool
class Utilities:
def __init__(self, context: PluginManager) -> None:
def __init__(self, context: 'PluginManager') -> None:
self.context = context
self.util_methods: Dict[str, Callable[..., Coroutine[Any, Any, Any]]] = {
"ping": self.ping,
@@ -307,7 +309,7 @@ class Utilities:
self.rdt_proxy_task = self.context.loop.create_task(self.rdt_proxy_server)
def stop_rdt_proxy(self):
if self.rdt_proxy_server:
if self.rdt_proxy_server != None:
self.rdt_proxy_server.close()
if self.rdt_proxy_task:
self.rdt_proxy_task.cancel()
+4
View File
@@ -0,0 +1,4 @@
# This file is needed to make the relative imports in backend/ work properly.
if __name__ == "__main__":
from backend.main import main
main()