Fixup replace_files for Alchemical

This commit is contained in:
Keith Edmunds 2024-04-27 20:25:22 +01:00
parent 134961abfd
commit 189efb379f
2 changed files with 15 additions and 10 deletions

View File

@ -4,20 +4,25 @@
# the current directory contains a "better" version of the file than the # the current directory contains a "better" version of the file than the
# parent (eg, bettet bitrate). # parent (eg, bettet bitrate).
# Standard library imports
import os import os
import pydymenu # type: ignore
import shutil import shutil
import sys import sys
from typing import List
# PyQt imports
# Third party imports
import pydymenu # type: ignore
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.session import Session
# App imports
from helpers import ( from helpers import (
get_tags, get_tags,
set_track_metadata, set_track_metadata,
) )
from models import db, Tracks
from models import Tracks
from dbconfig import Session
from sqlalchemy.exc import IntegrityError
from typing import List
# ###################### SETTINGS ######################### # ###################### SETTINGS #########################
process_name_and_tags_matches = True process_name_and_tags_matches = True
@ -42,7 +47,7 @@ def main():
# We only want to run this against the production database because # We only want to run this against the production database because
# we will affect files in the common pool of tracks used by all # we will affect files in the common pool of tracks used by all
# databases # databases
if "musicmuster_prod" not in os.environ.get("MM_DB"): if "musicmuster_prod" not in os.environ.get("ALCHEMICAL_DATABASE_URI"):
response = input("Not on production database - c to continue: ") response = input("Not on production database - c to continue: ")
if response != "c": if response != "c":
sys.exit(0) sys.exit(0)
@ -51,7 +56,7 @@ def main():
assert source_dir != parent_dir assert source_dir != parent_dir
# Scan parent directory # Scan parent directory
with Session() as session: with db.Session() as session:
all_tracks = Tracks.get_all(session) all_tracks = Tracks.get_all(session)
parent_tracks = [a for a in all_tracks if parent_dir in a.path] parent_tracks = [a for a in all_tracks if parent_dir in a.path]
parent_fnames = [os.path.basename(a.path) for a in parent_tracks] parent_fnames = [os.path.basename(a.path) for a in parent_tracks]
@ -239,7 +244,7 @@ def process_track(src, dst, title, artist, bitrate):
if not do_processing: if not do_processing:
return return
with Session() as session: with db.Session() as session:
track = Tracks.get_by_path(session, dst) track = Tracks.get_by_path(session, dst)
if track: if track:
# Update path, but workaround MariaDB bug # Update path, but workaround MariaDB bug

View File

@ -59,7 +59,7 @@ explicit_package_bases = true
[tool.pytest.ini_options] [tool.pytest.ini_options]
addopts = "--exitfirst --showlocals --capture=no" addopts = "--exitfirst --showlocals --capture=no"
pythonpath = [".", "app"] pythonpath = [".", "app"]
filterwarnings = "ignore:'audioop' is deprecated" filterwarnings = ["ignore:'audioop' is deprecated", "ignore:pkg_resources"]
[tool.vulture] [tool.vulture]
exclude = ["migrations", "app/ui", "archive"] exclude = ["migrations", "app/ui", "archive"]