write LASTFM_API_KEY to config file

+ remove alive bar
This commit is contained in:
mungai-njoroge
2023-08-31 21:36:34 +03:00
parent 4271a6f4a0
commit da88bbd9cc
9 changed files with 34 additions and 69 deletions
+17 -6
View File
@@ -13,10 +13,8 @@ from app.print_help import HELP_MESSAGE
from app.utils.wintools import is_windows
from app.utils.xdg_utils import get_xdg_config_dir
# from app.api.imgserver import set_app_dir
config = ConfigParser()
config.read("pyinstaller.config.ini")
config.read("runtime.config.ini")
ALLARGS = settings.ALLARGS
ARGS = sys.argv[1:]
@@ -40,9 +38,20 @@ class HandleArgs:
"""
Runs Pyinstaller.
"""
# get last.fm api key from env
last_fm_key = os.environ.get("LASTFM_API_KEY")
# if the key is not in env, exit
if not last_fm_key:
log.error("ERROR: LASTFM_API_KEY not set in environment")
sys.exit(0)
if ALLARGS.build in ARGS:
with open("pyinstaller.config.ini", "w", encoding="utf-8") as file:
with open("runtime.config.ini", "w", encoding="utf-8") as file:
config["DEFAULT"]["BUILD"] = "True"
# copy the api key to the config file
config["DEFAULT"]["LASTFM_API_KEY"] = last_fm_key
config.write(file)
_s = ";" if is_windows() else ":"
@@ -56,13 +65,15 @@ class HandleArgs:
"--clean",
f"--add-data=assets{_s}assets",
f"--add-data=client{_s}client",
f"--add-data=pyinstaller.config.ini{_s}.",
f"--add-data=runtime.config.ini{_s}.",
"-y",
]
)
with open("pyinstaller.config.ini", "w", encoding="utf-8") as file:
# revert build to False and remove the api key for dev mode
with open("runtime.config.ini", "w", encoding="utf-8") as file:
config["DEFAULT"]["BUILD"] = "False"
config["DEFAULT"]["LASTFM_API_KEY"] = ""
config.write(file)
sys.exit(0)
+6 -8
View File
@@ -5,7 +5,6 @@ Contains methods relating to albums.
from dataclasses import asdict
from typing import Any
from alive_progress import alive_bar
from app.logger import log
from app.models.track import Track
@@ -23,20 +22,19 @@ def validate_albums():
album_hashes = {t.albumhash for t in TrackStore.tracks}
albums = AlbumStore.albums
with alive_bar(len(albums)) as bar:
log.info("Validating albums")
for album in albums:
if album.albumhash not in album_hashes:
AlbumStore.remove_album(album)
bar()
for album in albums:
if album.albumhash not in album_hashes:
AlbumStore.remove_album(album)
def remove_duplicate_on_merge_versions(tracks: list[Track]) -> list[Track]:
"""
Removes duplicate tracks when merging versions of the same album.
"""
pass
def sort_by_track_no(tracks: list[Track]) -> list[dict[str, Any]]:
tracks = [asdict(t) for t in tracks]
+4 -2
View File
@@ -5,19 +5,21 @@ create the config directory and copy the assets to the app directory.
import os
import shutil
import sys
from configparser import ConfigParser
from app import settings
from app.utils.filesystem import get_home_res_path
config = ConfigParser()
config_path = get_home_res_path("pyinstaller.config.ini")
config_path = get_home_res_path("runtime.config.ini")
config.read(config_path)
try:
IS_BUILD = config["DEFAULT"]["BUILD"] == "True"
settings.Keys.LASTFM_API = config["DEFAULT"]["LASTFM_API_KEY"]
except KeyError:
# If the key doesn't exist, it means that the app is being executed in dev mode.
# If the key doesn't exist, the app is in dev mode.
IS_BUILD = False
+3 -1
View File
@@ -1,12 +1,14 @@
import platform
IS_WIN = platform.system() == "Windows"
# TODO: Check is_windows on app start in settings.py
def is_windows():
"""
Returns True if the OS is Windows.
"""
return platform.system() == "Windows"
return IS_WIN
def win_replace_slash(path: str):