Commit 36ba0f3b authored by Gerion Entrup's avatar Gerion Entrup
Browse files

add artists directory

parent e8d0cf99
import hlfuse, os
import threading
from mbdata.models import Recording
from mbdata.models import Recording, Artist, ArtistCredit, ArtistCreditName
class Translator(threading.Thread):
"""
......@@ -17,8 +17,10 @@ class Translator(threading.Thread):
root = hlfuse.FuseDir(0o555, root=True)
artists = hlfuse.FuseDir(0o555)
recordings = RecordingDir(0o555, session)
artists = ArtistsDir(0o555, session)
root.add_file('Recordings', recordings)
root.add_file('Artists', artists)
return root
......@@ -26,11 +28,42 @@ class Translator(threading.Thread):
self.mount(self._mountpoint)
def mount(self, mountpoint):
#from utils import debug_breakpoint
#debug_breakpoint()
hlfuse.init(mountpoint, self._root)
#TODO fix
self._session.commit()
self._session.close()
class ArtistsDir(hlfuse.FuseDir):
def __init__(self, mode, session):
super().__init__(mode)
self._session = session
def get_files(self):
artists = self._session.query(Artist).all()
files = []
for artist in artists:
adir = ArtistDir(0o444, self._session, artist)
files.append((artist.name, adir))
return files
class ArtistDir(hlfuse.FuseDir):
def __init__(self, mode, session, artist):
super().__init__(mode)
self._session = session
self._artist = artist
def get_files(self):
#TODO fix, efficient query
recordings = self._session.query(Recording).join(ArtistCredit).join(ArtistCreditName).join(Artist).filter(Artist.gid == self._artist.gid).all()
files = []
for recording in recordings:
recfile = BrainzFile(0o444, recording.path)
filename = recording.artist_credit.name + " - " + recording.name + "." + recording.ftype
files.append((filename, recfile))
return files
class RecordingDir(hlfuse.FuseDir):
......
......@@ -3,3 +3,27 @@ def pairwise(iterable):
a = iter(iterable)
return zip(a, a)
def debug_breakpoint():
"""
Python debug breakpoint.
"""
from code import InteractiveConsole
from inspect import currentframe
try:
import readline # noqa
except ImportError:
pass
caller = currentframe().f_back
env = {}
env.update(caller.f_globals)
env.update(caller.f_locals)
shell = InteractiveConsole(env)
shell.interact(
'* Break: {} ::: Line {}\n'
'* Continue with Ctrl+D...'.format(
caller.f_code.co_filename, caller.f_lineno
)
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment