~hristoast/mousikofidi

9c3746abf3598e03e829b8ba49c59ab03c397209 — Hristos N. Triantafillou 9 months ago 1ff1a1f
Don't crash when there's no CFG, write a default instead (#102)
1 files changed, 25 insertions(+), 9 deletions(-)

M mousikofidi/mousikofidi.py
M mousikofidi/mousikofidi.py => mousikofidi/mousikofidi.py +25 -9
@@ 350,15 350,31 @@ def init(
    if fidi_config:
        c = yaml.load(config_to_string(fidi_config), Loader=yaml.BaseLoader)
    else:
        err("")
        err("No valid configuration file was provided!")
        err("Please see this URL for how to get setup with a config file:")
        err("")
        err("https://man.sr.ht/~hristoast/mousikofidi/setup.md#configuring-mousikfdi")
        err("")
        err("MousikóFídi will not work without a valid config file!")
        err("")
        return abort(500)
        wrn("No CFG found or given, creating a default for use.")
        cfg = """config:
  cover_art: true
  favicon_path: /fidi.png
  holidays: true
  icons: false
  logo_path: /fidi.png
  music_dirs:
    - {home}/music
    - {home}/video
  playlist:
    dir: {home}/music/playlists
    save: true
  preload_audio: false
  preload_video: false
  secret_key: {secret}
  site_name: MousikóFídi - Your Music Cloud
  theme: light""".format(
            home=os.getenv("HOME"), secret=os.urandom(24)
        )
        with open(user_config_file, "w") as f:
            for line in cfg.split("\n"):
                f.write(line + "\n")

        c = yaml.load(config_to_string(user_config_file), Loader=yaml.BaseLoader)

    # TODO: A more DRY way to handle checking for configs
    try: