Skip to content

Commit

Permalink
Loading settings file
Browse files Browse the repository at this point in the history
  • Loading branch information
faermanj committed Nov 16, 2023
1 parent 61c68bc commit 84119e8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
2 changes: 2 additions & 0 deletions upcli/up/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ def cli_main():
uplib.up_main(context, prompt)
except Exception as e:
log.error(e)
# print stack trace
raise e
exit_cli("UP_ERROR")

6 changes: 3 additions & 3 deletions uplib/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions uplib/uplib/config.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
from dynaconf import Dynaconf
import pkgutil
import logging

from dynaconf import Dynaconf
from dynaconf.loaders import yaml_loader
from enum import Enum

class Config(Enum):
default_image = "default_image"
welcome_message = "welcome_message"
log_level = "log_level"

def get(self):
key = self.value
return settings().get(key)

_settings = None
def settings():
global _settings
if not _settings:
_settings = Dynaconf(
envvar_prefix="UP",
load_dotenv=True,)
environments=False,
envvar_prefix="UP")
up_yaml = pkgutil.get_data(__name__, "up.yaml")
if up_yaml:
up_yaml = up_yaml.decode("utf-8")
yaml_loader.load(_settings, filename=up_yaml)
return _settings

def get_log_level():
level_name = settings().get("log_level", "INFO")
level = logging.getLevelName(level_name)
return level


10 changes: 7 additions & 3 deletions uplib/uplib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
from .containers import Containers, ContainerRun
from .plugins import load_plugins
from .logging import log
from .config import Config

def up_main(context: Context, prompt: Prompt):

def up_main(context: Context, prompt: Prompt):
log.info("*** %s", Config.welcome_message.get() + " ***")
containers = Containers()
if not prompt:
log.error("No prompts found")
Expand All @@ -21,11 +24,13 @@ def up_main(context: Context, prompt: Prompt):
for container in container_runs:
containers.run(container)


def default_container(prompt):
return ContainerRun(
image="fedora",
image=settings().get("default_image", "fedora"),
command=prompt)


def containers_for_prompt(prompt) -> list[ContainerRun]:
from_plugins = containers_from_plugins(prompt)
from_configs = containers_from_dynaconf(prompt)
Expand All @@ -43,4 +48,3 @@ def containers_from_plugins(prompt: list[str]) -> list[ContainerRun]:
if not result:
result = []
return result

Empty file removed uplib/uplib/settings.toml
Empty file.
2 changes: 2 additions & 0 deletions uplib/uplib/up.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default_image: fedora
welcome_message: Thank you for running up!

0 comments on commit 84119e8

Please sign in to comment.