diff --git a/Dockerfile b/Dockerfile index 50bc63f..dce7623 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,8 @@ -FROM node:latest AS CLIENT +FROM ubuntu:latest -RUN git clone https://github.com/swing-opensource/swingmusic-client.git client +WORKDIR / -WORKDIR /client - -RUN git checkout $(git describe --tags $(git rev-list --tags --max-count=1)) - -RUN yarn install - -RUN yarn build - -FROM python:latest - -WORKDIR /app/swingmusic - -COPY . . - -COPY --from=CLIENT /client/dist/ client +COPY ./dist/swingmusic /swingmusic EXPOSE 1970/tcp @@ -24,10 +10,4 @@ VOLUME /music VOLUME /config -RUN pip install poetry - -RUN poetry config virtualenvs.create false - -RUN poetry install - -ENTRYPOINT ["poetry", "run", "python", "manage.py", "--host", "0.0.0.0", "--config", "/config"] +ENTRYPOINT ["/swingmusic", "--host", "0.0.0.0", "--config", "/config"] diff --git a/Dockerfile.og b/Dockerfile.og new file mode 100644 index 0000000..23c27c2 --- /dev/null +++ b/Dockerfile.og @@ -0,0 +1,35 @@ +FROM node:latest AS CLIENT + +RUN git clone https://github.com/swing-opensource/swingmusic-client.git client + +WORKDIR /client + +RUN git checkout $(git describe --tags $(git rev-list --tags --max-count=1)) + +RUN yarn install + +RUN yarn build + +FROM python:latest + +WORKDIR /app/swingmusic + +COPY . . + +COPY --from=CLIENT /client/dist/ client + +EXPOSE 1970/tcp + +VOLUME /music + +VOLUME /config + +RUN pip install poetry + +RUN poetry config virtualenvs.create false + +RUN poetry install + +ENV LASTFM_API_KEY="45c6776a1029a280fabd6a2c8158023d" + +ENTRYPOINT ["poetry", "run", "python", "manage.py", "--host", "0.0.0.0", "--config", "/config"] diff --git a/app/arg_handler.py b/app/arg_handler.py index 1e1c00a..4416aa6 100644 --- a/app/arg_handler.py +++ b/app/arg_handler.py @@ -39,7 +39,7 @@ class HandleArgs: Runs Pyinstaller. """ # get last.fm api key from env - last_fm_key = os.environ.get("LASTFM_API_KEY") + last_fm_key = settings.Keys.LASTFM_API # if the key is not in env, exit if not last_fm_key: diff --git a/app/db/sqlite/tracks.py b/app/db/sqlite/tracks.py index ddd4523..99f0ffe 100644 --- a/app/db/sqlite/tracks.py +++ b/app/db/sqlite/tracks.py @@ -4,11 +4,14 @@ interacting with the tracks table. """ from collections import OrderedDict +import random from sqlite3 import Cursor from app.db.sqlite.utils import tuple_to_track, tuples_to_tracks from .utils import SQLiteManager +from app.logger import log +from pprint import pprint class SQLiteTrackMethods: @@ -44,12 +47,21 @@ class SQLiteTrackMethods: track = OrderedDict(sorted(track.items())) - def force_surrogatepass(string: str): - return string.encode("utf-16", "surrogatepass").decode("utf-16") + # def should_fail(): + # """ + # Return true randomly. + # """ + # return random.randint(0, 1) == 1 - for key, value in track.items(): - if isinstance(value, str): - track[key] = force_surrogatepass(value) + # if should_fail(): + # raise Exception("Failed to insert track") + + # def force_surrogatepass(string: str): + # return string.encode("utf-16", "surrogatepass").decode("utf-16") + + # for key, value in track.items(): + # if isinstance(value, str): + # track[key] = force_surrogatepass(value) track["artist"] = track["artists"] track["albumartist"] = track["albumartists"] @@ -64,9 +76,16 @@ class SQLiteTrackMethods: """ Inserts a list of tracks into the database. """ + + log.info("Send me the JSON below for debugging.") + with SQLiteManager() as cur: for track in tracks: - cls.insert_one_track(track, cur) + try: + cls.insert_one_track(track, cur) + except Exception: + pprint(track, indent=4) + log.error("Send me the JSON above for debugging. Use https://pastebin.com and share the link.") @staticmethod def get_all_tracks(): diff --git a/app/lib/populate.py b/app/lib/populate.py index 9f96427..0b525fc 100644 --- a/app/lib/populate.py +++ b/app/lib/populate.py @@ -334,4 +334,4 @@ class FetchSimilarArtistsLastFM: # any exception that can be raised by the pool except Exception as e: log.warn(e) - pass + return diff --git a/app/setup/files.py b/app/setup/files.py index 0fc2741..5af78f4 100644 --- a/app/setup/files.py +++ b/app/setup/files.py @@ -5,7 +5,6 @@ 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 @@ -21,6 +20,7 @@ IS_BUILD = config["DEFAULT"]["BUILD"] == "True" if IS_BUILD: settings.Keys.LASTFM_API = config["DEFAULT"]["LASTFM_API_KEY"] + class CopyFiles: """Copies assets to the app directory."""