Commit 994326aa authored by Gerion Entrup's avatar Gerion Entrup
Browse files

plumber: implement a few methods more, still not usable

parent df989da0
......@@ -18,6 +18,7 @@ from fetcher import Fetcher
Paths = queue.Queue(maxsize=10)
NEW = 0; DEFECT = 1; UPDATE = 2
NewData = namedtuple('NewData', ['mbid', 'path'])
DefectData = namedtuple('DefectData', ['mbid', 'table'])
class Collector(threading.Thread):
"""
......
import os.path
from collector import Paths, DEFECT, UPDATE
from collector import Paths, DefectData, DEFECT, UPDATE
class Plumber(threading.Thread):
"""Check and find out how to repair the database."""
......@@ -12,48 +12,59 @@ class Plumber(threading.Thread):
def run(self):
check_recordings()
check_artists()
check_artist_credits()
check_artist_credit_names()
check_artists()
check_release_groups()
check_releases()
check_tracks()
check_mediums()
check_releases()
check_release_groups()
check_integrity_conditions()
def check_recordings()
recordings = session.query(Recording).all()
for recording in recordings:
#clean out orphaned recordings
if not os.path.isfile(recording.path):
delete_recording(recording)
#mbid is the fundamental identifier,
#without it, there is no way to recover
#so delete entity
if check_mbid(recording.gid)
delete_recording(recording)
#check recording
defect = recording.name is None or len(recording.name) == 0
defect |= recording.ftype is None or len(recording.name) == 0
if defect:
Paths.put((DEFECT, recording.gid))
def check_entitys(self, table, check_fail, check_defect=lambda x: False):
for entity in self._session.query(table).all()
#clean file if necessary
if check_fail(entity) or (hasattr(entity, 'gid') and check_mbid(entity.gid)):
self._session.delete(entity)
#check for defect
if check_defect(entity):
Paths.put((DEFECT, DefectData(mbid=entity.gid, table=table)))
check_update_time(recording)
#check foreign keys
def check_recordings(self):
check_entitys(Recording,
lambda x: not os.path.isfile(x.path),
check_defect=lambda x: x.artist_credit == None)
def check_artist_credits(self):
check_entitys(ArtistCredit,
lambda ac: self._session.query(Recording).filter(ac == Recording.artist_credit).first() == None)
def check_artist_credit_names(self):
pass
def check_artists(self):
pass
def check_release_groups(self):
pass
def check_releases(self):
pass
def check_tracks(self):
pass
def delete_recording(recording):
def check_mediums(self):
pass
def check_mbid(mbid):
return False
def check_update_time(entity)
print("last_updated:")
print(entity.last_updated)
print(type(entity.last_updated)
print(type(entity.last_updated))
......@@ -12,6 +12,11 @@ class SqliteSession():
ret = self._session.commit()
return ret
def delete(self, entry):
with lock:
ret = self._session.delete(entry)
return ret
def query(self, table):
return SqliteQuery(table, self._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