Compare commits
2 Commits
6a2bcfff19
...
be4f19757c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be4f19757c | ||
|
|
784d036bb7 |
27
app/log.py
27
app/log.py
@ -55,25 +55,14 @@ syslog.addFilter(local_filter)
|
||||
stderr.addFilter(local_filter)
|
||||
stderr.addFilter(debug_filter)
|
||||
|
||||
stderr_fmt = logging.Formatter('[%(asctime)s] %(leveltag)s: %(message)s',
|
||||
datefmt='%H:%M:%S')
|
||||
syslog_fmt = logging.Formatter(
|
||||
'[%(name)s] %(module)s.%(funcName)s - %(leveltag)s: %(message)s'
|
||||
)
|
||||
stderr.setFormatter(stderr_fmt)
|
||||
syslog.setFormatter(syslog_fmt)
|
||||
|
||||
class VerboseExceptionFormatter(logging.Formatter):
|
||||
def formatException(self, exc_info):
|
||||
msg = stackprinter.format(exc_info)
|
||||
lines = msg.split('\n')
|
||||
lines_indented = [" ┆ " + line + "\n" for line in lines]
|
||||
msg_indented = "".join(lines_indented)
|
||||
return msg_indented
|
||||
|
||||
|
||||
stderr_fmt = '[%(asctime)s] %(leveltag)s: %(message)s'
|
||||
stderr_formatter = VerboseExceptionFormatter(stderr_fmt, datefmt='%H:%M:%S')
|
||||
stderr.setFormatter(stderr_formatter)
|
||||
|
||||
syslog_fmt = '[%(name)s] %(module)s.%(funcName)s - %(leveltag)s: %(message)s'
|
||||
syslog_formatter = VerboseExceptionFormatter(syslog_fmt)
|
||||
syslog.setFormatter(syslog_formatter)
|
||||
|
||||
# add the handlers to the log
|
||||
log.addHandler(stderr)
|
||||
log.addHandler(syslog)
|
||||
|
||||
@ -85,7 +74,7 @@ def log_uncaught_exceptions(ex_cls, ex, tb):
|
||||
print("\033[1;31;47m")
|
||||
logging.critical(''.join(traceback.format_tb(tb)))
|
||||
print("\033[1;37;40m")
|
||||
stackprinter.show(style="lightbg")
|
||||
print(stackprinter.format(ex, style="darkbg2", add_summary=True))
|
||||
msg = stackprinter.format(ex)
|
||||
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
|
||||
"Exception from musicmuster", msg)
|
||||
|
||||
@ -593,6 +593,27 @@ class PlaylistRows(Base):
|
||||
.values(row_number=PlaylistRows.row_number + move_by)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def indexed_by_row(session: Session, playlist_id: int) -> dict:
|
||||
"""
|
||||
Return a dictionary of playlist_rows indexed by row number for
|
||||
the passed playlist_id.
|
||||
"""
|
||||
|
||||
plrs = session.execute(
|
||||
select(PlaylistRows)
|
||||
.where(
|
||||
PlaylistRows.playlist_id == playlist_id,
|
||||
)
|
||||
.order_by(PlaylistRows.row_number)
|
||||
).scalars().all()
|
||||
|
||||
result = {}
|
||||
for plr in plrs:
|
||||
result[plr.row_number] = plr
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class Settings(Base):
|
||||
"""Manage settings"""
|
||||
|
||||
@ -1663,6 +1663,6 @@ if __name__ == "__main__":
|
||||
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
|
||||
"Exception from musicmuster", msg)
|
||||
|
||||
print("\033[1;31;47mUnhandled exception starts\033[1;37;40m")
|
||||
stackprinter.show(style="darkbg2")
|
||||
print("\033[1;31;47mUnhandled exception ends\033[1;37;40m")
|
||||
print("\033[1;31;47mUnhandled exception starts")
|
||||
stackprinter.show(style="darkbg")
|
||||
print("Unhandled exception ends\033[1;37;40m")
|
||||
|
||||
@ -827,11 +827,11 @@ class PlaylistTab(QTableWidget):
|
||||
the row number is correct (in case tracks have been reordered).
|
||||
"""
|
||||
|
||||
plr_dict = PlaylistRows.indexed_by_row(session, self.playlist_id)
|
||||
for row in range(self.rowCount()):
|
||||
plr = session.get(PlaylistRows, self._get_playlistrow_id(row))
|
||||
# Set the row number and playlist id (even if correct)
|
||||
plr.row_number = row
|
||||
plr.playlist_id = self.playlist_id
|
||||
plr_dict[row].row_number = row
|
||||
plr_dict[row].playlist_id = self.playlist_id
|
||||
|
||||
# Any rows in the database with a row_number higher that the
|
||||
# current value of 'row' should not be there. Commit session
|
||||
|
||||
Loading…
Reference in New Issue
Block a user