mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-07-11 06:21:58 +00:00
Give SettingsManager a default directory
This commit is contained in:
+19
-5
@@ -1,13 +1,12 @@
|
|||||||
import certifi
|
|
||||||
import ssl
|
|
||||||
import uuid
|
|
||||||
import re
|
import re
|
||||||
|
import ssl
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import uuid
|
||||||
from aiohttp.web import middleware, Response
|
|
||||||
from subprocess import check_output
|
from subprocess import check_output
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
import certifi
|
||||||
|
from aiohttp.web import Response, middleware
|
||||||
|
|
||||||
REMOTE_DEBUGGER_UNIT = "steam-web-debug-portforward.service"
|
REMOTE_DEBUGGER_UNIT = "steam-web-debug-portforward.service"
|
||||||
|
|
||||||
@@ -69,6 +68,21 @@ def get_user_group() -> str:
|
|||||||
raise ValueError("helpers.get_user_group method called before group variable was set. Run helpers.set_user_group first.")
|
raise ValueError("helpers.get_user_group method called before group variable was set. Run helpers.set_user_group first.")
|
||||||
return group
|
return group
|
||||||
|
|
||||||
|
# Get the default home path unless a user is specified
|
||||||
|
def get_home_path(username = None) -> str:
|
||||||
|
if username == None:
|
||||||
|
raise ValueError("Username not defined, no home path can be found.")
|
||||||
|
else:
|
||||||
|
return str("/home/"+username)
|
||||||
|
|
||||||
|
# Get the default homebrew path unless a user is specified
|
||||||
|
def get_homebrew_path(home_path = None) -> str:
|
||||||
|
if home_path == None:
|
||||||
|
raise ValueError("Home path not defined, homebrew dir cannot be determined.")
|
||||||
|
else:
|
||||||
|
return str(home_path+"/homebrew")
|
||||||
|
# return str(home_path+"/homebrew")
|
||||||
|
|
||||||
async def is_systemd_unit_active(unit_name: str) -> bool:
|
async def is_systemd_unit_active(unit_name: str) -> bool:
|
||||||
res = subprocess.run(["systemctl", "is-active", unit_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
res = subprocess.run(["systemctl", "is-active", unit_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
return res.returncode == 0
|
return res.returncode == 0
|
||||||
|
|||||||
+11
-8
@@ -1,24 +1,27 @@
|
|||||||
# Full imports
|
# Full imports
|
||||||
import aiohttp_cors
|
|
||||||
|
|
||||||
# Partial imports
|
|
||||||
from aiohttp import ClientSession
|
|
||||||
from aiohttp.web import Application, run_app, static, get, Response
|
|
||||||
from aiohttp_jinja2 import setup as jinja_setup
|
|
||||||
from asyncio import get_event_loop, sleep
|
from asyncio import get_event_loop, sleep
|
||||||
from json import dumps, loads
|
from json import dumps, loads
|
||||||
from logging import DEBUG, INFO, basicConfig, getLogger
|
from logging import DEBUG, INFO, basicConfig, getLogger
|
||||||
from os import getenv, path
|
from os import getenv, path
|
||||||
from subprocess import call
|
from subprocess import call
|
||||||
|
|
||||||
|
import aiohttp_cors
|
||||||
|
# Partial imports
|
||||||
|
from aiohttp import ClientSession
|
||||||
|
from aiohttp.web import Application, Response, get, run_app, static
|
||||||
|
from aiohttp_jinja2 import setup as jinja_setup
|
||||||
|
|
||||||
# local modules
|
# local modules
|
||||||
from browser import PluginBrowser
|
from browser import PluginBrowser
|
||||||
from helpers import csrf_middleware, get_csrf_token, get_user, get_user_group, set_user, set_user_group, stop_systemd_unit, REMOTE_DEBUGGER_UNIT
|
from helpers import (REMOTE_DEBUGGER_UNIT, csrf_middleware, get_csrf_token,
|
||||||
|
get_home_path, get_homebrew_path, get_user,
|
||||||
|
get_user_group, set_user, set_user_group,
|
||||||
|
stop_systemd_unit)
|
||||||
from injector import inject_to_tab, tab_has_global_var
|
from injector import inject_to_tab, tab_has_global_var
|
||||||
from loader import Loader
|
from loader import Loader
|
||||||
|
from settings import SettingsManager
|
||||||
from updater import Updater
|
from updater import Updater
|
||||||
from utilities import Utilities
|
from utilities import Utilities
|
||||||
from settings import SettingsManager
|
|
||||||
|
|
||||||
# Ensure USER and GROUP vars are set first.
|
# Ensure USER and GROUP vars are set first.
|
||||||
# TODO: This isn't the best way to do this but supports the current
|
# TODO: This isn't the best way to do this but supports the current
|
||||||
|
|||||||
+12
-4
@@ -1,8 +1,16 @@
|
|||||||
from os import path, mkdir
|
import imp
|
||||||
from json import load, dump
|
from json import dump, load
|
||||||
|
from os import mkdir, path
|
||||||
|
|
||||||
|
from helpers import get_home_path, get_homebrew_path, get_user, set_user
|
||||||
|
|
||||||
|
|
||||||
class SettingsManager:
|
class SettingsManager:
|
||||||
def __init__(self, name, settings_directory) -> None:
|
def __init__(self, name, settings_directory = None) -> None:
|
||||||
|
set_user()
|
||||||
|
USER = get_user()
|
||||||
|
if settings_directory == None:
|
||||||
|
settings_directory = get_homebrew_path(get_home_path(USER))
|
||||||
self.path = path.join(settings_directory, name + ".json")
|
self.path = path.join(settings_directory, name + ".json")
|
||||||
|
|
||||||
if not path.exists(settings_directory):
|
if not path.exists(settings_directory):
|
||||||
@@ -33,4 +41,4 @@ class SettingsManager:
|
|||||||
|
|
||||||
def setSetting(self, key, value):
|
def setSetting(self, key, value):
|
||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
self.commit()
|
self.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user