From 9bc7d881d85f4691774dac67b768ebc1614471ab Mon Sep 17 00:00:00 2001 From: krateng Date: Fri, 20 Oct 2023 00:11:06 +0200 Subject: [PATCH] Some fixes --- maloja/__main__.py | 4 ++-- maloja/apis/native_v1.py | 4 ++-- maloja/database/sqldb.py | 5 +++-- maloja/malojatime.py | 13 +++++++++++-- maloja/server.py | 2 -- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/maloja/__main__.py b/maloja/__main__.py index 5e35b29..7a26a47 100644 --- a/maloja/__main__.py +++ b/maloja/__main__.py @@ -130,7 +130,7 @@ def run_supervisor(): def debug(): os.environ["MALOJA_DEV_MODE"] = 'true' conf.malojaconfig.load_environment() - direct() + run_server() def print_info(): print_header_info() @@ -172,7 +172,7 @@ def main(*args,**kwargs): } if "version" in kwargs: - print(info.VERSION) + print(pkginfo.VERSION) return True else: try: diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index c51c367..0cab1b5 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -2,10 +2,10 @@ import os import math import traceback -from bottle import response, static_file, request, FormsDict +from bottle import response, static_file, FormsDict from doreah.logging import log -from doreah.auth import authenticated_api, authenticated_api_with_alternate, authenticated_function +from doreah.auth import authenticated_function # nimrodel API from nimrodel import EAPI as API diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index 6704b9a..e94246d 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -399,7 +399,7 @@ def add_tracks_to_albums(track_to_album_id_dict,replace=False,dbconn=None): @connection_provider def remove_album(*track_ids,dbconn=None): - + DB['tracks'].update().where( DB['tracks'].c.track_id.in_(track_ids) ).values( @@ -439,10 +439,11 @@ def get_track_id(trackdict,create_new=True,update_album=False,dbconn=None): if trackdict.get('album') and create_new: # if we don't supply create_new, it means we just want to get info about a track # which means no need to write album info, even if it was new + # if we havent set update_album, we only want to assign the album in case the track # has no album yet. this means we also only want to create a potentially new album in that case album_id = get_album_id(trackdict['album'],create_new=(update_album or not row.album_id),dbconn=dbconn) - add_track_to_album(row.id,album_id,replace=(update_album or not row.album_id),dbconn=dbconn) + add_track_to_album(row.id,album_id,replace=update_album,dbconn=dbconn) return row.id diff --git a/maloja/malojatime.py b/maloja/malojatime.py index b383a27..a808d9b 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -1,7 +1,7 @@ from datetime import timezone, timedelta, date, time, datetime from calendar import monthrange -from os.path import commonprefix import math +from abc import ABC, abstractmethod from .pkg_global.conf import malojaconfig @@ -28,7 +28,7 @@ def register_scrobbletime(timestamp): # Generic Time Range -class MTRangeGeneric: +class MTRangeGeneric(ABC): # despite the above, ranges that refer to the exact same real time range should evaluate as equal def __eq__(self,other): @@ -68,6 +68,15 @@ class MTRangeGeneric: def __contains__(self,timestamp): return timestamp >= self.first_stamp() and timestamp <= self.last_stamp() + @abstractmethod + def first_stamp(self): + pass + + @abstractmethod + def last_stamp(self): + pass + + # Any range that has one defining base unit, whether week, year, etc. class MTRangeSingular(MTRangeGeneric): def fromstr(self): diff --git a/maloja/server.py b/maloja/server.py index 540f65c..e8f6288 100644 --- a/maloja/server.py +++ b/maloja/server.py @@ -1,9 +1,7 @@ # technical -import sys import os from threading import Thread from importlib import resources -import datauri import time