Commit 4f43d5f2 authored by Gerion Entrup's avatar Gerion Entrup
Browse files

try to fix database writing

parent 0aafc694
......@@ -15,8 +15,8 @@ class Collector:
Collects Tags and write them to the database.
"""
def __init__(self, Session):
self.session = Session()
def __init__(self, session):
self.session = session
self.fetcher = Fetcher()
def walk(self, path):
......@@ -122,6 +122,8 @@ class Collector:
def fetch_recording(self, mbid):
recording = self.session.query(Recording).filter_by(gid=mbid).first()
print(recording)
if recording is None:
result = self.fetcher.get_table_by_id(mbid, 'recording')
......
......@@ -32,8 +32,10 @@ class Fetcher:
except musicbrainzngs.WebServiceError as exc:
print("Could not connect to Musicbrainz. Request: {}".format(exc))
self.cache[tablename][mbid] = result
print("asked web for {}".format(tablename))
else:
result = self.cache[tablename][mbid]
print("asked fetcher")
#pp = pprint.PrettyPrinter(indent=4)
#pp.pprint(result)
......
......@@ -8,20 +8,19 @@ from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from collector import Collector
from translator import Translator
from mbdata.models import Base
from mbdata import patch_model_schemas, NO_SCHEMAS
class Main:
def init_database(self, dbfile):
#engine = create_engine('sqlite:///' + dbfile, echo=True)
engine = create_engine('sqlite://')#, echo=True)
engine = create_engine('sqlite:///' + dbfile, echo=True)
#engine = create_engine('sqlite://')#, echo=True)
patch_model_schemas(NO_SCHEMAS)
#if not os.path.isfile(dbfile):
# Base.metadata.create_all(engine)
Base.metadata.create_all(engine)
self.Session = sessionmaker(bind=engine)
Session = sessionmaker(bind=engine)
self.session = Session()
def main(self, args):
......@@ -35,10 +34,14 @@ class Main:
arg = parser.parse_args(args[1:])
self.init_database(arg.database);
self.init_database(arg.database)
collector = Collector(self.Session)
collector = Collector(self.session)
collector.walk(arg.sourcedir)
translator = Translator(self.session)
self.session.close()
if __name__ == "__main__":
Main().main(sys.argv)
class Translator:
import llfuse
class Translator(llfuse.Operations):
"""
Manages the mapping between filesystem and database.
"""
def __init__(self, session):
self.session = session
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