Skip to content

Commit

Permalink
move log config to main init
Browse files Browse the repository at this point in the history
  • Loading branch information
jardon committed Oct 19, 2024
1 parent 141ee12 commit 662f113
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
32 changes: 25 additions & 7 deletions vanilla_first_setup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,41 @@
import os
import sys
import logging
import json
from gettext import gettext as _
from vanilla_first_setup.window import VanillaWindow
from vanilla_first_setup.utils.recipe import RecipeLoader
from vanilla_first_setup.utils.recipe import recipe_path
import subprocess


logging.basicConfig(level=logging.INFO,
filename=RecipeLoader().raw.get("log_file"),
filemode='a',
)
logger = logging.getLogger("FirstSetup::Main")


class FirstSetupApplication(Adw.Application):
"""The main application singleton class."""

def __init__(self):
# here we create a temporary file to store the output of the commands
# the log path is defined in the recipe
with open(recipe_path, 'r') as file:
recipe = json.load(file)

if "log_file" not in recipe:
logger.critical("Missing 'log_file' in the recipe.")
sys.exit(1)

log_path = recipe["log_file"]

if not os.path.exists(log_path):
try:
open(log_path, "a").close()
logging.basicConfig(level=logging.INFO,
filename=log_path,
filemode='a',
)
except OSError as e:
logger.warning(f"failed to create log file: {log_path}: {e}")
logging.warning("No log will be stored.")


super().__init__(
application_id="org.vanillaos.FirstSetup",
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
Expand Down
15 changes: 0 additions & 15 deletions vanilla_first_setup/utils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,6 @@ def __init__(self, window, new_user: bool = False):
self.__load()

def __load(self):
# here we create a temporary file to store the output of the commands
# the log path is defined in the recipe
if "log_file" not in self.__recipe.raw:
logger.critical("Missing 'log_file' in the recipe.")
sys.exit(1)

log_path = self.__recipe.raw["log_file"]

if not os.path.exists(log_path):
try:
open(log_path, "a").close()
except OSError as e:
logger.warning(f"failed to create log file: {log_path}: {e}")
logging.warning("No log will be stored.")

for i, (key, step) in enumerate(self.__recipe.raw["steps"].items()):
_status = True
_protected = False
Expand Down
3 changes: 1 addition & 2 deletions vanilla_first_setup/utils/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

logger = logging.getLogger("FirstSetup::RecipeLoader")

recipe_path = "/usr/share/org.vanillaos.FirstSetup/recipe.json"

class RecipeLoader:
recipe_path = "/usr/share/org.vanillaos.FirstSetup/recipe.json"

def __init__(self):
self.__recipe = {}
self.__load()
Expand Down

0 comments on commit 662f113

Please sign in to comment.