--- a/imms.py Mon Feb 09 23:29:08 2004 -0500
+++ b/imms.py Wed Feb 11 10:39:27 2004 -0500
@@ -138,6 +138,18 @@
def get_uid_by_path(self, path):
entries = self.get_library_entry(path = path)
return map(lambda x: x[1], entries)
+ def get_alike(self, uid):
+ self.cu.execute('SELECT sid FROM Library WHERE uid = %d;' % uid)
+ sids = self.cu.fetchall()
+ res = {}
+ for sid in sids:
+ sid = int(sid)
+ self.cu.execute("SELECT uid FROM Library "
+ "WHERE sid = %d;" % sid)
+ res[sid] = []
+ for uid in self.cu.fetchall():
+ res[sid].append(int(uid))
+ return res
def get_ratings_and_paths(self, uids = None):
qry = '''SELECT l.uid, r.rating, l.path, ls.last
FROM Library l, Rating r, Last ls
@@ -169,6 +181,34 @@
FROM Library l, Rating r, Info i
WHERE l.uid = r.uid AND l.sid = i.sid;''')
return self.cu.fetchall()
+ def clean_info(self):
+ self.cu.execute("""DELETE FROM Info
+ WHERE sid NOT IN
+ (SELECT sid FROM Library);""")
+ def clean_last(self):
+ self.cu.execute("""DELETE FROM Last
+ WHERE sid NOT IN
+ (SELECT sid FROM Library);""")
+ def clean_rating(self):
+ self.cu.execute("""DELETE FROM Rating
+ WHERE uid NOT IN
+ (SELECT uid FROM Library);""")
+ def clean_acoustic(self):
+ self.cu.execute("""DELETE FROM Acoustic
+ WHERE uid NOT IN
+ (SELECT uid FROM Library);""")
+ def clean_correlations(self):
+ self.cu.execute("""DELETE FROM Correlations
+ WHERE origin NOT IN (SELECT sid FROM Library)
+ OR destination NOT IN (SELECT sid FROM Library);""")
+ def clean_all(self):
+ self.cu.execute("BEGIN TRANSACTION;")
+ self.clean_info()
+ self.clean_last()
+ self.clean_rating()
+ self.clean_acoustic()
+ self.clean_correlations()
+ self.cu.execute("COMMIT;")
class IMMSCleaner:
def __init__(self, db):
@@ -226,27 +266,28 @@
self.db.update_filename(path, newfile)
map(self.check_uid, unique(deleted_uids))
map(self.check_sid, unique(deleted_sids))
- def clean_rating(self):
- print >> _log, "Clean Rating"
- rates = self.db.get_ratings()
- rates = unique(map(lambda x: x[0], rates))
- map(self.check_uid, rates)
- def clean_acoustic(self):
- print >> _log, "Clean Acoustic"
- uids = self.db.get_acoustics()
- uids = map(lambda x: x[0], uids )
- map(self.check_uid, uids)
- def clean_info(self):
- print >> _log, "Clean Info"
- sids = map(lambda x: x[0], self.db.get_infos())
- map(self.check_sid, sids)
- def clean_last(self):
- print >> _log, "Clean Last"
- sids = map(lambda x: x[0], self.db.get_last())
- map(self.check_sid, sids)
+## def clean_rating(self):
+## print >> _log, "Clean Rating"
+## rates = self.db.get_ratings()
+## rates = unique(map(lambda x: x[0], rates))
+## map(self.check_uid, rates)
+## def clean_acoustic(self):
+## print >> _log, "Clean Acoustic"
+## uids = self.db.get_acoustics()
+## uids = map(lambda x: x[0], uids )
+## map(self.check_uid, uids)
+## def clean_info(self):
+## print >> _log, "Clean Info"
+## sids = map(lambda x: x[0], self.db.get_infos())
+## map(self.check_sid, sids)
+## def clean_last(self):
+## print >> _log, "Clean Last"
+## sids = map(lambda x: x[0], self.db.get_last())
+## map(self.check_sid, sids)
def clean_all(self):
- self.clean_library()
- self.clean_rating()
- self.clean_acoustic()
- self.clean_info()
- self.clean_last()
+ self.db.clean_all()
+## self.clean_library()
+## self.clean_rating()
+## self.clean_acoustic()
+## self.clean_info()
+## self.clean_last()