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

View File

@ -13,10 +13,8 @@ from app.print_help import HELP_MESSAGE
from app.utils.wintools import is_windows from app.utils.wintools import is_windows
from app.utils.xdg_utils import get_xdg_config_dir from app.utils.xdg_utils import get_xdg_config_dir
# from app.api.imgserver import set_app_dir
config = ConfigParser() config = ConfigParser()
config.read("pyinstaller.config.ini") config.read("runtime.config.ini")
ALLARGS = settings.ALLARGS ALLARGS = settings.ALLARGS
ARGS = sys.argv[1:] ARGS = sys.argv[1:]
@ -40,9 +38,20 @@ class HandleArgs:
""" """
Runs Pyinstaller. 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: 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" config["DEFAULT"]["BUILD"] = "True"
# copy the api key to the config file
config["DEFAULT"]["LASTFM_API_KEY"] = last_fm_key
config.write(file) config.write(file)
_s = ";" if is_windows() else ":" _s = ";" if is_windows() else ":"
@ -56,13 +65,15 @@ class HandleArgs:
"--clean", "--clean",
f"--add-data=assets{_s}assets", f"--add-data=assets{_s}assets",
f"--add-data=client{_s}client", f"--add-data=client{_s}client",
f"--add-data=pyinstaller.config.ini{_s}.", f"--add-data=runtime.config.ini{_s}.",
"-y", "-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"]["BUILD"] = "False"
config["DEFAULT"]["LASTFM_API_KEY"] = ""
config.write(file) config.write(file)
sys.exit(0) sys.exit(0)

View File

@ -5,7 +5,6 @@ Contains methods relating to albums.
from dataclasses import asdict from dataclasses import asdict
from typing import Any from typing import Any
from alive_progress import alive_bar
from app.logger import log from app.logger import log
from app.models.track import Track from app.models.track import Track
@ -23,20 +22,19 @@ def validate_albums():
album_hashes = {t.albumhash for t in TrackStore.tracks} album_hashes = {t.albumhash for t in TrackStore.tracks}
albums = AlbumStore.albums albums = AlbumStore.albums
with alive_bar(len(albums)) as bar: for album in albums:
log.info("Validating albums") if album.albumhash not in album_hashes:
for album in albums: AlbumStore.remove_album(album)
if album.albumhash not in album_hashes:
AlbumStore.remove_album(album)
bar()
def remove_duplicate_on_merge_versions(tracks: list[Track]) -> list[Track]: def remove_duplicate_on_merge_versions(tracks: list[Track]) -> list[Track]:
""" """
Removes duplicate tracks when merging versions of the same album. Removes duplicate tracks when merging versions of the same album.
""" """
pass pass
def sort_by_track_no(tracks: list[Track]) -> list[dict[str, Any]]: def sort_by_track_no(tracks: list[Track]) -> list[dict[str, Any]]:
tracks = [asdict(t) for t in tracks] tracks = [asdict(t) for t in tracks]

View File

@ -5,19 +5,21 @@ create the config directory and copy the assets to the app directory.
import os import os
import shutil import shutil
import sys
from configparser import ConfigParser from configparser import ConfigParser
from app import settings from app import settings
from app.utils.filesystem import get_home_res_path from app.utils.filesystem import get_home_res_path
config = ConfigParser() config = ConfigParser()
config_path = get_home_res_path("pyinstaller.config.ini") config_path = get_home_res_path("runtime.config.ini")
config.read(config_path) config.read(config_path)
try: try:
IS_BUILD = config["DEFAULT"]["BUILD"] == "True" IS_BUILD = config["DEFAULT"]["BUILD"] == "True"
settings.Keys.LASTFM_API = config["DEFAULT"]["LASTFM_API_KEY"]
except KeyError: 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 IS_BUILD = False

View File

@ -1,12 +1,14 @@
import platform import platform
IS_WIN = platform.system() == "Windows"
# TODO: Check is_windows on app start in settings.py # TODO: Check is_windows on app start in settings.py
def is_windows(): def is_windows():
""" """
Returns True if the OS is Windows. Returns True if the OS is Windows.
""" """
return platform.system() == "Windows" return IS_WIN
def win_replace_slash(path: str): def win_replace_slash(path: str):

View File

@ -9,14 +9,13 @@ from flask import request
from app.api import create_api from app.api import create_api
from app.arg_handler import HandleArgs from app.arg_handler import HandleArgs
from app.periodic_scan import run_periodic_scans
from app.lib.watchdogg import Watcher as WatchDog from app.lib.watchdogg import Watcher as WatchDog
from app.periodic_scan import run_periodic_scans
from app.settings import FLASKVARS from app.settings import FLASKVARS
from app.setup import run_setup from app.setup import run_setup
from app.start_info_logger import log_startup_info from app.start_info_logger import log_startup_info
from app.utils.filesystem import get_home_res_path from app.utils.filesystem import get_home_res_path
from app.utils.threading import background from app.utils.threading import background
from alive_progress import config_handler
mimetypes.add_type("text/css", ".css") mimetypes.add_type("text/css", ".css")
mimetypes.add_type("text/javascript", ".js") mimetypes.add_type("text/javascript", ".js")
@ -77,15 +76,7 @@ def start_watchdog():
WatchDog().run() WatchDog().run()
def configure_alive_bar():
"""
Sets the default alive bar settings.
"""
config_handler.set_global(spinner="classic", bar="classic2", enrich_print=False)
if __name__ == "__main__": if __name__ == "__main__":
configure_alive_bar()
HandleArgs() HandleArgs()
log_startup_info() log_startup_info()
bg_run_setup() bg_run_setup()

41
poetry.lock generated
View File

@ -1,31 +1,5 @@
# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. # This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand.
[[package]]
name = "about-time"
version = "4.2.1"
description = "Easily measure timing and throughput of code blocks, with beautiful human friendly representations."
optional = false
python-versions = ">=3.7, <4"
files = [
{file = "about-time-4.2.1.tar.gz", hash = "sha256:6a538862d33ce67d997429d14998310e1dbfda6cb7d9bbfbf799c4709847fece"},
{file = "about_time-4.2.1-py3-none-any.whl", hash = "sha256:8bbf4c75fe13cbd3d72f49a03b02c5c7dca32169b6d49117c257e7eb3eaee341"},
]
[[package]]
name = "alive-progress"
version = "3.1.4"
description = "A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!"
optional = false
python-versions = ">=3.7, <4"
files = [
{file = "alive-progress-3.1.4.tar.gz", hash = "sha256:74a95d8d0d42bc99d3a3725dbd06ebb852245f1b64e301a7c375b92b22663f7b"},
{file = "alive_progress-3.1.4-py3-none-any.whl", hash = "sha256:c80ad87ce9c1054b01135a87fae69ecebbfc2107497ae87cbe6aec7e534903db"},
]
[package.dependencies]
about-time = "4.2.1"
grapheme = "0.6.0"
[[package]] [[package]]
name = "altgraph" name = "altgraph"
version = "0.17.3" version = "0.17.3"
@ -424,19 +398,6 @@ files = [
Flask = ">=0.9" Flask = ">=0.9"
Six = "*" Six = "*"
[[package]]
name = "grapheme"
version = "0.6.0"
description = "Unicode grapheme helpers"
optional = false
python-versions = "*"
files = [
{file = "grapheme-0.6.0.tar.gz", hash = "sha256:44c2b9f21bbe77cfb05835fec230bd435954275267fea1858013b102f8603cca"},
]
[package.extras]
test = ["pytest", "sphinx", "sphinx-autobuild", "twine", "wheel"]
[[package]] [[package]]
name = "gunicorn" name = "gunicorn"
version = "20.1.0" version = "20.1.0"
@ -1492,4 +1453,4 @@ files = [
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = ">=3.10,<3.12" python-versions = ">=3.10,<3.12"
content-hash = "15bc0dc4a39392445fe3fe8a9131090f697f80008a79f5d8d49668465acafcb3" content-hash = "0052648520a30e34301208917b639bcd2ca9a0a09a557537126d300aa5ffeeed"

View File

@ -20,7 +20,6 @@ Unidecode = "^1.3.6"
psutil = "^5.9.4" psutil = "^5.9.4"
show-in-file-manager = "^1.1.4" show-in-file-manager = "^1.1.4"
pendulum = "^2.1.2" pendulum = "^2.1.2"
alive-progress = "^3.1.4"
flask-compress = "^1.13" flask-compress = "^1.13"
tabulate = "^0.9.0" tabulate = "^0.9.0"

View File

@ -1,3 +1,4 @@
[DEFAULT] [DEFAULT]
build = False build = False
lastfm_api_key =

View File

@ -8,7 +8,7 @@ a = Analysis(
['manage.py'], ['manage.py'],
pathex=[], pathex=[],
binaries=[], binaries=[],
datas=[('assets', 'assets'), ('client', 'client'), ('pyinstaller.config.ini', '.')], datas=[('assets', 'assets'), ('client', 'client'), ('runtime.config.ini', '.')],
hiddenimports=[], hiddenimports=[],
hookspath=[], hookspath=[],
hooksconfig={}, hooksconfig={},