Compare commits

..

No commits in common. "6a2bcfff195d13e20bad0ac1b0bd0e7aea80e4c1" and "0d4b306fc4e565896b21d88b62eaaf71e086b4b0" have entirely different histories.

6 changed files with 21 additions and 125 deletions

View File

@ -76,19 +76,3 @@ syslog.setFormatter(syslog_formatter)
# add the handlers to the log
log.addHandler(stderr)
log.addHandler(syslog)
def log_uncaught_exceptions(ex_cls, ex, tb):
from helpers import send_mail
print("\033[1;31;47m")
logging.critical(''.join(traceback.format_tb(tb)))
print("\033[1;37;40m")
stackprinter.show(style="lightbg")
msg = stackprinter.format(ex)
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
"Exception from musicmuster", msg)
sys.excepthook = log_uncaught_exceptions

View File

@ -251,7 +251,7 @@ class Playlists(Base):
id: int = Column(Integer, primary_key=True, autoincrement=True)
name: str = Column(String(32), nullable=False, unique=True)
last_used = Column(DateTime, default=None, nullable=True)
tab = Column(Integer, default=False, nullable=True, unique=True)
loaded = Column(Boolean, default=True, nullable=False)
is_template = Column(Boolean, default=False, nullable=False)
rows = relationship(
"PlaylistRows",
@ -287,7 +287,7 @@ class Playlists(Base):
def close(self, session: Session) -> None:
"""Mark playlist as unloaded"""
self.tab = None
self.loaded = False
@classmethod
def create_playlist_from_template(cls,
@ -310,7 +310,7 @@ class Playlists(Base):
session.execute(
select(cls)
.filter(cls.is_template.is_(False))
.order_by(cls.tab.desc(), cls.last_used.desc())
.order_by(cls.loaded.desc(), cls.last_used.desc())
)
.scalars()
.all()
@ -338,7 +338,7 @@ class Playlists(Base):
session.execute(
select(cls)
.filter(
cls.tab.is_(None),
cls.loaded.is_(False),
cls.is_template.is_(False)
)
.order_by(cls.last_used.desc())
@ -350,45 +350,25 @@ class Playlists(Base):
@classmethod
def get_open(cls, session: Session) -> List[Optional["Playlists"]]:
"""
Return a list of loaded playlists ordered by tab order.
Return a list of playlists marked "loaded", ordered by loaded date.
"""
return (
session.execute(
select(cls)
.where(cls.tab.is_not(None))
.order_by(cls.tab)
.where(cls.loaded.is_(True))
.order_by(cls.last_used.desc())
)
.scalars()
.all()
)
def mark_open(self, session: Session, tab_index: int) -> None:
def mark_open(self, session: Session) -> None:
"""Mark playlist as loaded and used now"""
self.tab = tab_index
self.loaded = True
self.last_used = datetime.now()
@staticmethod
def move_tab(session: Session, frm: int, to: int) -> None:
"""Move tabs"""
row_frm = session.execute(
select(Playlists)
.filter_by(tab=frm)
).scalar_one()
row_to = session.execute(
select(Playlists)
.filter_by(tab=to)
).scalar_one()
row_frm.tab = None
row_to.tab = None
session.commit()
row_to.tab = frm
row_frm.tab = to
@staticmethod
def save_as_template(session: Session,
playlist_id: int, template_name: str) -> None:

View File

@ -343,11 +343,6 @@ class Window(QMainWindow, Ui_MainWindow):
if record.f_int != splitter_bottom:
record.update(session, {'f_int': splitter_bottom})
# Save current tab
record = Settings.get_int_settings(session, "active_tab")
record.update(session,
{'f_int': self.tabPlaylist.currentIndex()})
event.accept()
def close_playlist_tab(self) -> None:
@ -424,8 +419,6 @@ class Window(QMainWindow, Ui_MainWindow):
self.tabPlaylist.currentChanged.connect(
lambda: self.tabPlaylist.currentWidget().tab_visible())
self.tabPlaylist.tabCloseRequested.connect(self.close_tab)
self.tabBar = self.tabPlaylist.tabBar()
self.tabBar.tabMoved.connect(self.move_tab)
self.txtSearch.returnPressed.connect(self.search_playlist_return)
self.timer.timeout.connect(self.tick)
@ -449,10 +442,10 @@ class Window(QMainWindow, Ui_MainWindow):
self.create_playlist_tab(session, playlist)
def create_playlist_tab(self, session: Session,
playlist: Playlists) -> int:
playlist: Playlists) -> None:
"""
Take the passed playlist database object, create a playlist tab and
add tab to display. Return index number of tab.
add tab to display.
"""
playlist_tab = PlaylistTab(
@ -460,8 +453,6 @@ class Window(QMainWindow, Ui_MainWindow):
idx = self.tabPlaylist.addTab(playlist_tab, playlist.name)
self.tabPlaylist.setCurrentIndex(idx)
return idx
def cut_rows(self) -> None:
"""
Cut rows ready for pasting.
@ -768,11 +759,8 @@ class Window(QMainWindow, Ui_MainWindow):
with Session() as session:
for playlist in Playlists.get_open(session):
_ = self.create_playlist_tab(session, playlist)
# Set active tab
record = Settings.get_int_settings(session, "active_tab")
if record and record.f_int is not None:
self.tabPlaylist.setCurrentIndex(record.f_int)
self.create_playlist_tab(session, playlist)
playlist.mark_open(session)
def move_playlist_rows(self, session: Session,
playlistrows: List[PlaylistRows]) -> None:
@ -844,12 +832,6 @@ class Window(QMainWindow, Ui_MainWindow):
self.visible_playlist_tab().get_selected_playlistrows(session)
)
def move_tab(self, frm: int, to: int) -> None:
"""Handle tabs being moved"""
with Session() as session:
Playlists.move_tab(session, frm, to)
def move_unplayed(self) -> None:
"""
Move unplayed rows to another playlist
@ -880,8 +862,8 @@ class Window(QMainWindow, Ui_MainWindow):
return
playlist = Playlists.create_playlist_from_template(
session, template, playlist_name)
tab_index = self.create_playlist_tab(session, playlist)
playlist.mark_open(session, tab_index)
playlist.mark_open(session)
self.create_playlist_tab(session, playlist)
def open_playlist(self):
"""Open existing playlist"""
@ -893,8 +875,8 @@ class Window(QMainWindow, Ui_MainWindow):
dlg.exec()
playlist = dlg.playlist
if playlist:
tab_index = self.create_playlist_tab(session, playlist)
playlist.mark_open(session, tab_index)
playlist.mark_open(session)
self.create_playlist_tab(session, playlist)
def paste_rows(self) -> None:
"""
@ -932,6 +914,8 @@ class Window(QMainWindow, Ui_MainWindow):
plr.playlist_id = dst_playlist_id
plr.row_number = row
row += 1
# Need to commit each row individually else only one row
# gets updated (don't know why)
session.commit()
@ -1661,7 +1645,7 @@ if __name__ == "__main__":
msg = stackprinter.format(exc)
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
"Exception from musicmuster", msg)
"Exception from musicmuster", msg)
print("\033[1;31;47mUnhandled exception starts\033[1;37;40m")
stackprinter.show(style="darkbg2")

View File

@ -1,32 +0,0 @@
"""Record tab number for open playlists
Revision ID: 4a7b4ab3354f
Revises: 6730f03317df
Create Date: 2022-12-20 15:38:28.318280
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '4a7b4ab3354f'
down_revision = '6730f03317df'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('playlists', sa.Column('tab', sa.Integer(), nullable=True))
op.create_unique_constraint(None, 'playlists', ['tab'])
op.drop_column('playlists', 'loaded')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('playlists', sa.Column('loaded', mysql.TINYINT(display_width=1), autoincrement=False, nullable=False))
op.drop_constraint(None, 'playlists', type_='unique')
op.drop_column('playlists', 'tab')
# ### end Alembic commands ###

21
poetry.lock generated
View File

@ -182,24 +182,6 @@ parso = ">=0.8.0,<0.9.0"
qa = ["flake8 (==3.8.3)", "mypy (==0.782)"]
testing = ["Django (<3.1)", "colorama", "docopt", "pytest (<7.0.0)"]
[[package]]
name = "line-profiler"
version = "4.0.2"
description = "Line-by-line profiler"
category = "dev"
optional = false
python-versions = ">=3.6"
[package.extras]
all = ["pytest", "pytest-cov", "coverage", "ubelt", "cython", "scikit-build", "cmake", "ninja", "cibuildwheel", "cibuildwheel", "cibuildwheel", "cibuildwheel", "cibuildwheel", "cibuildwheel", "ipython", "ipython"]
all-strict = ["pytest (==4.6.11)", "pytest-cov (==2.10.1)", "coverage[toml] (==5.3)", "ubelt (==1.0.1)", "Cython (==3.0.0a11)", "scikit-build (==0.11.1)", "cmake (==3.21.2)", "ninja (==1.10.2)", "cibuildwheel (==2.11.2)", "cibuildwheel (==2.11.2)", "cibuildwheel (==2.8.1)", "cibuildwheel (==2.11.2)", "cibuildwheel (==2.11.2)", "cibuildwheel (==2.11.2)", "IPython (==0.13)", "IPython (==0.13)"]
build = ["cython", "scikit-build", "cmake", "ninja", "cibuildwheel", "cibuildwheel", "cibuildwheel", "cibuildwheel", "cibuildwheel", "cibuildwheel"]
build-strict = ["Cython (==3.0.0a11)", "scikit-build (==0.11.1)", "cmake (==3.21.2)", "ninja (==1.10.2)", "cibuildwheel (==2.11.2)", "cibuildwheel (==2.11.2)", "cibuildwheel (==2.8.1)", "cibuildwheel (==2.11.2)", "cibuildwheel (==2.11.2)", "cibuildwheel (==2.11.2)"]
ipython-strict = ["IPython (==0.13)", "IPython (==0.13)"]
ipython = ["ipython", "ipython"]
tests = ["pytest", "pytest-cov", "coverage", "ubelt", "ipython", "ipython"]
tests-strict = ["pytest (==4.6.11)", "pytest-cov (==2.10.1)", "coverage[toml] (==5.3)", "ubelt (==1.0.1)", "IPython (==0.13)", "IPython (==0.13)"]
[[package]]
name = "mako"
version = "1.2.0"
@ -734,7 +716,7 @@ python-versions = "*"
[metadata]
lock-version = "1.1"
python-versions = "^3.9"
content-hash = "8a7dd5f873d901ffbe422d010464bcc8bb2acfa79329a95e4f18f213e120b5a7"
content-hash = "0fdda77377246e18b5e85459fa2c26173f14467f32e71c576b30fa0899ced8b0"
[metadata.files]
alembic = [
@ -846,7 +828,6 @@ jedi = [
{file = "jedi-0.18.1-py2.py3-none-any.whl", hash = "sha256:637c9635fcf47945ceb91cd7f320234a7be540ded6f3e99a50cb6febdfd1ba8d"},
{file = "jedi-0.18.1.tar.gz", hash = "sha256:74137626a64a99c8eb6ae5832d99b3bdd7d29a3850fe2aa80a4126b2a7d949ab"},
]
line-profiler = []
mako = [
{file = "Mako-1.2.0-py3-none-any.whl", hash = "sha256:23aab11fdbbb0f1051b93793a58323ff937e98e34aece1c4219675122e57e4ba"},
{file = "Mako-1.2.0.tar.gz", hash = "sha256:9a7c7e922b87db3686210cf49d5d767033a41d4010b284e747682c92bddd8b39"},

View File

@ -33,7 +33,6 @@ mypy = "^0.931"
pytest = "^7.0.1"
pytest-qt = "^4.0.2"
pydub-stubs = "^0.25.1"
line-profiler = "^4.0.2"
[build-system]
requires = ["poetry-core>=1.0.0"]