diff --git a/app/helpers.py b/app/helpers.py index 0a019e5..78fb3c7 100644 --- a/app/helpers.py +++ b/app/helpers.py @@ -5,21 +5,17 @@ import smtplib import ssl import tempfile -from email.message import EmailMessage -from mutagen.flac import FLAC # type: ignore -from mutagen.mp3 import MP3 # type: ignore -from pydub import effects -from pydub.utils import mediainfo - from config import Config from datetime import datetime +from email.message import EmailMessage from log import log -from pydub import AudioSegment +from mutagen.flac import FLAC # type: ignore +from mutagen.mp3 import MP3 # type: ignore +from pydub import AudioSegment, effects +from pydub.utils import mediainfo from PyQt5.QtWidgets import QMessageBox from tinytag import TinyTag # type: ignore -from typing import Optional -# from typing import Dict, Optional, Union -from typing import Dict, Union +from typing import Any, Dict, Optional, Union def ask_yes_no(title: str, question: str) -> bool: @@ -82,7 +78,7 @@ def get_audio_segment(path: str) -> Optional[AudioSegment]: return None -def get_tags(path: str) -> Dict[str, Union[str, int]]: +def get_tags(path: str) -> Dict[str, Any]: """ Return a dictionary of title, artist, duration-in-milliseconds and path. """ diff --git a/app/models.py b/app/models.py index fdff803..f50f8e6 100644 --- a/app/models.py +++ b/app/models.py @@ -212,7 +212,7 @@ class Playlists(Base): def __init__(self, session: scoped_session, name: str): self.name = name session.add(self) - session.commit() + session.flush() def close(self, session: scoped_session) -> None: """Mark playlist as unloaded""" @@ -233,10 +233,15 @@ class Playlists(Base): session: scoped_session, template: "Playlists", playlist_name: str) \ - -> "Playlists": + -> Optional["Playlists"]: """Create a new playlist from template""" playlist = cls(session, playlist_name) + + # Sanity / mypy checks + if not playlist or not playlist.id or not template.id: + return None + PlaylistRows.copy_playlist(session, template.id, playlist.id) return playlist @@ -334,6 +339,9 @@ class Playlists(Base): """Save passed playlist as new template""" template = Playlists(session, template_name) + if not template or not template.id: + return + template.is_template = True session.commit() diff --git a/app/playlists.py b/app/playlists.py index 10a685e..6b22417 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -1360,7 +1360,7 @@ class PlaylistTab(QTableWidget): return playlistrow_id def _get_playlistrow_object(self, session: scoped_session, - row: int) -> int: + row: int) -> PlaylistRows: """Return the playlistrow object associated with this row""" playlistrow_id = (self.item(row, USERDATA).data(self.PLAYLISTROW_ID)) diff --git a/app/replace_files.py b/app/replace_files.py index dabf1b5..679b54c 100755 --- a/app/replace_files.py +++ b/app/replace_files.py @@ -35,9 +35,9 @@ parent_dir = os.path.dirname(source_dir) name_and_tags: List[str] = [] tags_not_name: List[str] = [] -multiple_similar: List[str] = [] +# multiple_similar: List[str] = [] no_match: List[str] = [] -possibles: List[str] = [] +# possibles: List[str] = [] no_match: int = 0 diff --git a/app/ui_helpers.py b/app/ui_helpers.py deleted file mode 100644 index 7e4520d..0000000 --- a/app/ui_helpers.py +++ /dev/null @@ -1,17 +0,0 @@ -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QFontMetrics, QPainter -from PyQt5.QtWidgets import QLabel - - -# class ElideLabel(QLabel): -# """ -# From https://stackoverflow.com/questions/11446478/ -# pyside-pyqt-truncate-text-in-qlabel-based-on-minimumsize -# """ -# -# def paintEvent(self, event): -# painter = QPainter(self) -# metrics = QFontMetrics(self.font()) -# elided = metrics.elidedText(self.text(), Qt.ElideRight, self.width()) -# -# painter.drawText(self.rect(), self.alignment(), elided) diff --git a/audacity_control.py b/audacity_control.py index 774ae5a..0a76005 100755 --- a/audacity_control.py +++ b/audacity_control.py @@ -70,11 +70,4 @@ def do_command(command): return response -def quick_test(): - """Example list of commands.""" - do_command('Help: Command=Help') - do_command('Help: Command="GetInfo"') - # do_command('SetPreference: Name=GUI/Theme Value=classic Reload=1') - - do_command('Import2: Filename=/home/kae/git/musicmuster/archive/boot.flac') diff --git a/pyproject.toml b/pyproject.toml index 8e1652d..128498b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,5 +45,6 @@ mypy_path = "/home/kae/.cache/pypoetry/virtualenvs/musicmuster-oWgGw1IG-py3.9:/h plugins = "sqlalchemy.ext.mypy.plugin" [tool.vulture] -exclude = ["migrations"] +exclude = ["migrations", "app/ui", "archive"] paths = ["app"] +make_whitelist = true diff --git a/test.py b/test.py index 5840871..1781c14 100755 --- a/test.py +++ b/test.py @@ -2,28 +2,28 @@ from PyQt5 import QtGui, QtWidgets -class TabBar(QtWidgets.QTabWidget): +class TabBar(QtWidgets.QTabBar): def paintEvent(self, event): - painter = QtGui.QStylePainter(self) - option = QtGui.QStyleOptionTab() + painter = QtWidgets.QStylePainter(self) + option = QtWidgets.QStyleOptionTab() for index in range(self.count()): self.initStyleOption(option, index) bgcolor = QtGui.QColor(self.tabText(index)) option.palette.setColor(QtGui.QPalette.Window, bgcolor) - painter.drawControl(QtGui.QStyle.CE_TabBarTabShape, option) - painter.drawControl(QtGui.QStyle.CE_TabBarTabLabel, option) + painter.drawControl(QtWidgets.QStyle.CE_TabBarTabShape, option) + painter.drawControl(QtWidgets.QStyle.CE_TabBarTabLabel, option) class Window(QtWidgets.QTabWidget): def __init__(self): - QtGui.QTabWidget.__init__(self) + QtWidgets.QTabWidget.__init__(self) self.setTabBar(TabBar(self)) for color in 'tomato orange yellow lightgreen skyblue plum'.split(): - self.addTab(QtGui.QWidget(self), color) + self.addTab(QtWidgets.QWidget(self), color) if __name__ == '__main__': import sys - app = QtGui.QApplication(sys.argv) + app = QtWidgets.QApplication(sys.argv) window = Window() window.resize(420, 200) window.show() diff --git a/test_models.py b/test_models.py index 6e63040..901f119 100644 --- a/test_models.py +++ b/test_models.py @@ -5,7 +5,6 @@ from app.models import ( Notes, Playdates, Playlists, - PlaylistTracks, Tracks, ) @@ -205,11 +204,11 @@ def test_playlist_notes(session): # We need two notes note1_text = "note1 text" note1_row = 11 - note1 = Notes(session, playlist.id, note1_row, note1_text) + _ = Notes(session, playlist.id, note1_row, note1_text) note2_text = "note2 text" note2_row = 19 - note2 = Notes(session, playlist.id, note2_row, note2_text) + _ = Notes(session, playlist.id, note2_row, note2_text) notes = playlist.notes assert note1_text in [n.note for n in notes]