From d00d1e594189b846020d14651ef21a4a665225df Mon Sep 17 00:00:00 2001 From: blissful Date: Sat, 21 Oct 2023 14:59:05 -0400 Subject: [PATCH] replace [NEW] with {NEW} for better sort order in LC_COLLATE=C --- conftest.py | 2 +- rose/cache.py | 2 +- rose/cache_test.py | 2 +- rose/releases_test.py | 4 ++-- rose/virtualfs.py | 6 +++--- rose/virtualfs_test.py | 14 +++++++------- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/conftest.py b/conftest.py index 8dc2b28..af201c2 100644 --- a/conftest.py +++ b/conftest.py @@ -88,7 +88,7 @@ def seeded_cache(config: Config) -> None: (id , source_path , cover_image_path , datafile_mtime, virtual_dirname, title , release_type, release_year, multidisc, new , formatted_artists) VALUES ('r1', '{dirpaths[0]}', null , '999' , 'r1' , 'Release 1', 'album' , 2023 , false , false, 'Techno Man;Bass Man') , ('r2', '{dirpaths[1]}', '{imagepaths[0]}', '999' , 'r2' , 'Release 2', 'album' , 2021 , false , false, 'Violin Woman feat. Conductor Woman') - , ('r3', '{dirpaths[2]}', null , '999' , '[NEW] r3' , 'Release 3', 'album' , 2021 , false , true , ''); + , ('r3', '{dirpaths[2]}', null , '999' , '{NEW} r3' , 'Release 3', 'album' , 2021 , false , true , ''); INSERT INTO releases_genres (release_id, genre , genre_sanitized) diff --git a/rose/cache.py b/rose/cache.py index 2baa586..d031a87 100644 --- a/rose/cache.py +++ b/rose/cache.py @@ -586,7 +586,7 @@ def update_cache_for_releases( if release.labels: release_virtual_dirname += " {" + ";".join(release.labels) + "}" if release.new: - release_virtual_dirname = "[NEW] " + release_virtual_dirname + release_virtual_dirname = "{NEW} " + release_virtual_dirname release_virtual_dirname = sanitize_filename(release_virtual_dirname) # And in case of a name collision, add an extra number at the end. Iterate to # find the first unused number. diff --git a/rose/cache_test.py b/rose/cache_test.py index e4ed486..797fb8b 100644 --- a/rose/cache_test.py +++ b/rose/cache_test.py @@ -412,7 +412,7 @@ def test_list_releases(config: Config) -> None: id="r3", source_path=Path(config.music_source_dir / "r3"), cover_image_path=None, - virtual_dirname="[NEW] r3", + virtual_dirname="{NEW} r3", title="Release 3", type="album", year=2021, diff --git a/rose/releases_test.py b/rose/releases_test.py index 5e76cb5..cd9d089 100644 --- a/rose/releases_test.py +++ b/rose/releases_test.py @@ -47,7 +47,7 @@ def test_toggle_release_new(config: Config) -> None: assert data["new"] is False with connect(config) as conn: cursor = conn.execute("SELECT virtual_dirname FROM releases") - assert not cursor.fetchone()["virtual_dirname"].startswith("[NEW] ") + assert not cursor.fetchone()["virtual_dirname"].startswith("{NEW} ") # Set new. toggle_release_new(config, release_id) @@ -56,7 +56,7 @@ def test_toggle_release_new(config: Config) -> None: assert data["new"] is True with connect(config) as conn: cursor = conn.execute("SELECT virtual_dirname FROM releases") - assert cursor.fetchone()["virtual_dirname"].startswith("[NEW] ") + assert cursor.fetchone()["virtual_dirname"].startswith("{NEW} ") def test_resolve_release_ids(config: Config) -> None: diff --git a/rose/virtualfs.py b/rose/virtualfs.py index 42894eb..561b158 100644 --- a/rose/virtualfs.py +++ b/rose/virtualfs.py @@ -78,7 +78,7 @@ def getattr(self, path: str, fh: int) -> dict[str, Any]: # Some early guards just in case. if p.release and p.collage and not collage_has_release(self.config, p.collage, p.release): raise fuse.FuseOSError(errno.ENOENT) - if p.release and p.view == "New" and not p.release.startswith("[NEW] "): + if p.release and p.view == "New" and not p.release.startswith("{NEW} "): raise fuse.FuseOSError(errno.ENOENT) if p.release and p.file: @@ -292,10 +292,10 @@ def rename(self, old: str, new: str) -> None: # 2. Toggle a release's new status. if ( (op.release and np.release) - and op.release.removeprefix("[NEW] ") == np.release.removeprefix("[NEW] ") + and op.release.removeprefix("{NEW} ") == np.release.removeprefix("{NEW} ") and (not op.file and not np.file) ): - if op.release.startswith("[NEW] ") != np.release.startswith("[NEW] "): + if op.release.startswith("{NEW} ") != np.release.startswith("{NEW} "): toggle_release_new(self.config, op.release) else: raise fuse.FuseOSError(errno.EACCES) diff --git a/rose/virtualfs_test.py b/rose/virtualfs_test.py index 6027e1e..68982ef 100644 --- a/rose/virtualfs_test.py +++ b/rose/virtualfs_test.py @@ -86,10 +86,10 @@ def can_read(p: Path) -> bool: assert can_read(root / "Collages" / "Rose Gold" / "1. r1" / "01.m4a") assert (root / "New").is_dir() - assert (root / "New" / "[NEW] r3").is_dir() + assert (root / "New" / "{NEW} r3").is_dir() assert not (root / "New" / "r2").exists() - assert (root / "New" / "[NEW] r3" / "01.m4a").is_file() - assert not (root / "New" / "[NEW] r3" / "lalala").exists() + assert (root / "New" / "{NEW} r3" / "01.m4a").is_file() + assert not (root / "New" / "{NEW} r3" / "lalala").exists() @pytest.mark.usefixtures("seeded_cache") @@ -137,12 +137,12 @@ def test_virtual_filesystem_toggle_new(config: Config, source_dir: Path) -> None dirname = "NewJeans - 1990. I Love NewJeans [K-Pop;R&B] {A Cool Label}" root = config.fuse_mount_dir with startfs(config): - (root / "Releases" / dirname).rename(root / "Releases" / f"[NEW] {dirname}") - assert (root / "Releases" / f"[NEW] {dirname}").is_dir() + (root / "Releases" / dirname).rename(root / "Releases" / f"{NEW} {dirname}") + assert (root / "Releases" / f"{NEW} {dirname}").is_dir() assert not (root / "Releases" / dirname).exists() - (root / "Releases" / f"[NEW] {dirname}").rename(root / "Releases" / dirname) + (root / "Releases" / f"{NEW} {dirname}").rename(root / "Releases" / dirname) assert (root / "Releases" / dirname).is_dir() - assert not (root / "Releases" / f"[NEW] {dirname}").exists() + assert not (root / "Releases" / f"{NEW} {dirname}").exists() with pytest.raises(OSError): # noqa: PT011 (root / "Releases" / dirname).rename(root / "Releases" / "lalala")