def delete_album(album) : #we handle cascading deletes ourselves for track and artist for t in album.tracks : artists = t.artists session.delete(t) for a in artists : a.update_trackcount() session.delete(album) commit()
def verify_delete(vals,msg) : print vals.count(),msg if vals.count()==0 : return for v in vals: print v if get_raw_yesno('Delete them?') : for v in vals : try : session.delete(v) session.flush() except : print 'Could not delete',v,'probably because there are artist_sims for this artist'
def delete_source(source) : """Deletes all tracks and albums for a given source. The source is stored in the Track. Must be run interactively because it runs gordon_validate which asks questions at the prompt""" #This woudl be the "right" way to do it but it's slow because #we update track count on every track #for t in Track.query.filter_by(source=source) : # print 'Deleting',t # delete_track(t) for t in Track.query.filter_by(source=source) : print 'Deleting',t session.delete(t) commit() gordon_validate()
def reassign_artist(oldid,newid) : """Reassigns all tracks and albums from oldid to newid then deletes old artist.""" oldartist = Artist.query.get(oldid) newartist = Artist.query.get(newid) if not oldartist : raise ValueError('Bad id for oldartist') if not newartist : raise ValueError('Bad id for newartist') print "Tracks" for t in oldartist.tracks : print t if len(t.artists)==0 : print 'Missing artist' elif len(t.artists)==1 : if t.artists[0]==oldartist : t.artists[0]=newartist t.artist=newartist.name print 'Reassigned',oldartist,'to',newartist else : print 'Mismatched artist' else : print 'Multiple artists' print "Albums" for r in oldartist.albums : print r for idx in range(len(r.artists)) : a = r.artists[idx] if a==oldartist : r.artists[idx]=newartist print "Replaced",oldartist,"with",newartist print "Updating trackcount" newartist.update_trackcount() session.delete(oldartist) commit()
def reassign_artist(oldid, newid): """Reassigns all tracks and albums from oldid to newid then deletes old artist.""" oldartist = Artist.query.get(oldid) newartist = Artist.query.get(newid) if not oldartist: raise ValueError('Bad id for oldartist') if not newartist: raise ValueError('Bad id for newartist') print "Tracks" for t in oldartist.tracks: print t if len(t.artists) == 0: print 'Missing artist' elif len(t.artists) == 1: if t.artists[0] == oldartist: t.artists[0] = newartist t.artist = newartist.name print 'Reassigned', oldartist, 'to', newartist else: print 'Mismatched artist' else: print 'Multiple artists' print "Albums" for r in oldartist.albums: print r for idx in range(len(r.artists)): a = r.artists[idx] if a == oldartist: r.artists[idx] = newartist print "Replaced", oldartist, "with", newartist print "Updating trackcount" newartist.update_trackcount() session.delete(oldartist) commit()
def delete_track(track) : session.delete(track) session.flush() #should this be a commit? # Updating albums and artists too for a in track.albums : a.update_trackcount() if a.trackcount==0 : session.delete(a) for a in track.artists : a.update_trackcount() if a.trackcount==0 : session.delete(a) commit()
def delete_track(track): session.delete(track) session.flush() #should this be a commit? # Updating albums and artists too for a in track.albums: a.update_trackcount() if a.trackcount == 0: session.delete(a) for a in track.artists: a.update_trackcount() if a.trackcount == 0: session.delete(a) commit()
def delete(rec) : session.delete(rec)
def delete(rec): session.delete(rec)