added logging
This commit is contained in:
@@ -2,11 +2,15 @@ import os
|
||||
import json
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
from gentooimgr import LOG
|
||||
import gentooimgr.configs
|
||||
import multiprocessing
|
||||
|
||||
# A day in seconds:
|
||||
DAY_IN_SECONDS = 60*60*24
|
||||
# days until the iso is old
|
||||
DAYS = 1
|
||||
# Define threads to compile packages with
|
||||
THREADS = multiprocessing.cpu_count()
|
||||
# URL to latest image text file, defaults to amd64. This is parsed to find latest iso to download
|
||||
@@ -37,9 +41,14 @@ CLOUD_MODULES = [
|
||||
]
|
||||
|
||||
def load_config(path):
|
||||
assert path, "load config called with nothing"
|
||||
if os.path.exists(path):
|
||||
with open(path, 'r') as f:
|
||||
return json.loads(f.read())
|
||||
try:
|
||||
return json.loads(f.read())
|
||||
except Exception as e:
|
||||
LOG.error(f"ERROR loading {path}")
|
||||
raise
|
||||
return {}
|
||||
|
||||
def load_default_config(config_name):
|
||||
@@ -51,9 +60,14 @@ def load_default_config(config_name):
|
||||
if not name in gentooimgr.configs.KNOWN_CONFIGS:
|
||||
return {}
|
||||
|
||||
with open(os.path.join(gentooimgr.configs.CONFIG_DIR, config_name), 'r') as f:
|
||||
return json.loads(f.read())
|
||||
|
||||
json_file = os.path.join(gentooimgr.configs.CONFIG_DIR, config_name)
|
||||
ret = {}
|
||||
with open(json_file, 'r') as f:
|
||||
try:
|
||||
ret = json.loads(f.read())
|
||||
except Exception as e:
|
||||
LOG.error(f"loading {json_file} {e}")
|
||||
return ret
|
||||
|
||||
def inherit_config(config: dict) -> dict:
|
||||
"""Returns the json file that the inherit key specifies; will recursively update if inherit values are set.
|
||||
@@ -95,10 +109,10 @@ def determine_config(args: argparse.Namespace) -> dict:
|
||||
|
||||
# Check custom configuration
|
||||
configuration = load_default_config(args.config or 'base.json')
|
||||
if not configuration:
|
||||
if not configuration and args.config:
|
||||
configuration = load_config(args.config)
|
||||
if not configuration:
|
||||
sys.stderr.write(f"\tWW: Warning: Configuration {args.config} is empty\n")
|
||||
LOG.error(f"\tWW: Warning: Configuration {args.config} is empty\n")
|
||||
else:
|
||||
if configuration.get("inherit"):
|
||||
# newpkgs = configuration.get("packages", {})
|
||||
|
||||
Reference in New Issue
Block a user