Skip to content

Commit

Permalink
more grug brained code
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 10, 2023
1 parent 0ed4ce7 commit dfa6861
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions rose/virtualfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,47 +38,49 @@ def get_mode_type(path: str) -> Literal["dir", "file", "missing"]:
if path == "/":
return "dir"

parts = path.split("/")

if path.startswith("/albums"):
if path.count("/") == 1:
if len(parts) == 1:
return "dir"
if path.count("/") == 2:
exists = release_exists(self.config, path.split("/")[2])
if len(parts) == 2:
exists = release_exists(self.config, parts[2])
return "dir" if exists else "missing"
return "missing"

if path.startswith("/artists"):
if path.count("/") == 1:
if len(parts) == 1:
return "dir"
if path.count("/") == 2:
exists = artist_exists(self.config, path.split("/")[2])
if len(parts) == 2:
exists = artist_exists(self.config, parts[2])
return "dir" if exists else "missing"
if path.count("/") == 3:
exists = artist_exists(self.config, path.split("/")[2])
exists = exists and release_exists(self.config, path.split("/")[3])
if len(parts) == 3:
exists = artist_exists(self.config, parts[2])
exists = exists and release_exists(self.config, parts[3])
return "dir" if exists else "missing"
return "missing"

if path.startswith("/genres"):
if path.count("/") == 1:
if len(parts) == 1:
return "dir"
if path.count("/") == 2:
exists = genre_exists(self.config, path.split("/")[2])
if len(parts) == 2:
exists = genre_exists(self.config, parts[2])
return "dir" if exists else "missing"
if path.count("/") == 3:
exists = genre_exists(self.config, path.split("/")[2])
exists = exists and release_exists(self.config, path.split("/")[3])
if len(parts) == 3:
exists = genre_exists(self.config, parts[2])
exists = exists and release_exists(self.config, parts[3])
return "dir" if exists else "missing"
return "missing"

if path.startswith("/labels"):
if path.count("/") == 1:
if len(parts) == 1:
return "dir"
if path.count("/") == 2:
exists = label_exists(self.config, path.split("/")[2])
if len(parts) == 2:
exists = label_exists(self.config, parts[2])
return "dir" if exists else "missing"
if path.count("/") == 3:
exists = label_exists(self.config, path.split("/")[2])
exists = exists and release_exists(self.config, path.split("/")[3])
if len(parts) == 3:
exists = label_exists(self.config, parts[2])
exists = exists and release_exists(self.config, parts[3])
return "dir" if exists else "missing"
return "missing"

Expand Down Expand Up @@ -108,49 +110,51 @@ def readdir(self, path: str, _: Any) -> Iterator[fuse.Direntry]:
]
return

parts = path.split("/")

if path.startswith("/albums"):
if path.count("/") == 1:
if len(parts) == 1:
yield from [fuse.Direntry("."), fuse.Direntry("..")]
for album in list_releases(self.config):
yield fuse.Direntry(album.virtual_dirname)
return
return

if path.startswith("/artists"):
if path.count("/") == 1:
if len(parts) == 1:
yield from [fuse.Direntry("."), fuse.Direntry("..")]
for artist in list_artists(self.config):
yield fuse.Direntry(sanitize_filename(artist))
return
if path.count("/") == 2:
if len(parts) == 2:
yield from [fuse.Direntry("."), fuse.Direntry("..")]
for album in list_releases(self.config, sanitized_artist_filter=path.split("/")[2]):
for album in list_releases(self.config, sanitized_artist_filter=parts[2]):
yield fuse.Direntry(album.virtual_dirname)
return
return

if path.startswith("/genres"):
if path.count("/") == 1:
if len(parts) == 1:
yield from [fuse.Direntry("."), fuse.Direntry("..")]
for genre in list_genres(self.config):
yield fuse.Direntry(sanitize_filename(genre))
return
if path.count("/") == 2:
if len(parts) == 2:
yield from [fuse.Direntry("."), fuse.Direntry("..")]
for album in list_releases(self.config, sanitized_genre_filter=path.split("/")[2]):
for album in list_releases(self.config, sanitized_genre_filter=parts[2]):
yield fuse.Direntry(album.virtual_dirname)
return
return

if path.startswith("/labels"):
if path.count("/") == 1:
if len(parts) == 1:
yield from [fuse.Direntry("."), fuse.Direntry("..")]
for label in list_labels(self.config):
yield fuse.Direntry(sanitize_filename(label))
return
if path.count("/") == 2:
if len(parts) == 2:
yield from [fuse.Direntry("."), fuse.Direntry("..")]
for album in list_releases(self.config, sanitized_label_filter=path.split("/")[2]):
for album in list_releases(self.config, sanitized_label_filter=parts[2]):
yield fuse.Direntry(album.virtual_dirname)
return
return
Expand Down

0 comments on commit dfa6861

Please sign in to comment.