Made ocarina.buildLib() to make a library, save, and exit
git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@59 1daee41c-8060-4895-b1f0-2197c00d777a
This commit is contained in:
parent
a75984f950
commit
b9ccbf2012
|
@ -224,7 +224,7 @@ class ContentPane(gtk.HBox):
|
|||
if not (self.status == "pafter") and (loaded==True):
|
||||
self.plause(None,None)
|
||||
self.data.scrobbler.nowPlaying(self.data.song.info)
|
||||
self.gotoCurSong()
|
||||
#self.gotoCurSong()
|
||||
self.changeImg()
|
||||
self.status = ""
|
||||
self.data.dump()
|
||||
|
|
|
@ -8,6 +8,7 @@ class Data:
|
|||
path = os.path.join(options.user,".ocarina")
|
||||
#self.updateQ = False
|
||||
#self.updateList = False
|
||||
self.options = options
|
||||
self.path = path
|
||||
self.song = None
|
||||
self.quit = None
|
||||
|
@ -19,23 +20,23 @@ class Data:
|
|||
|
||||
|
||||
# Dump user data to a file
|
||||
def dump(self):
|
||||
def dump(self,all):
|
||||
# Have to clear library.libview before saving, otherwise there are problems
|
||||
libview = self.library.libview
|
||||
self.library.libview = None
|
||||
self.save(self.library,"library")
|
||||
self.library.libview = libview
|
||||
|
||||
self.save([self.curList,self.curSong],"playlist")
|
||||
self.save([self.curQ],"queue")
|
||||
self.save([self.size,self.divider,self.colSizes,self.sortedCol,self.random],"preferences")
|
||||
self.save([self.lfm,self.lfmuser,self.lfmpass],"last.fm")
|
||||
if all == True:
|
||||
self.save([self.curList,self.curSong],"playlist")
|
||||
self.save([self.curQ],"queue")
|
||||
self.save([self.size,self.divider,self.colSizes,self.sortedCol,self.random],"preferences")
|
||||
self.save([self.lfm,self.lfmuser,self.lfmpass],"last.fm")
|
||||
|
||||
|
||||
# Pickle out an object to file
|
||||
def save(self,obj,file):
|
||||
out = open(os.path.join(self.path,file),'w')
|
||||
p = pickle.Pickler(out,1)
|
||||
p = pickle.Pickler(out,0)
|
||||
p.dump(obj)
|
||||
out.close()
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class Library:
|
|||
self.reset()
|
||||
#self.scanning = False
|
||||
self.libview = None
|
||||
self.data = None
|
||||
#self.notAdded = open("/home/bjschuma/Desktop/notAdded.txt",'w')
|
||||
|
||||
|
||||
|
@ -20,14 +21,18 @@ class Library:
|
|||
def scan(self,thread,dir):
|
||||
#self.scanning = True
|
||||
self.reset()
|
||||
self.libview.updates()
|
||||
if self.libview:
|
||||
self.libview.updates()
|
||||
self.path = os.path.expanduser(dir)
|
||||
if os.path.exists(self.path) == False:
|
||||
#print "Directory not found: %s" % dir
|
||||
return
|
||||
self.traverse("")
|
||||
self.libview.stopUpdates()
|
||||
self.data.dump()
|
||||
if self.libview:
|
||||
self.libview.stopUpdates()
|
||||
if self.data.options.verbose == True:
|
||||
print "Found",self.count,"songs."
|
||||
self.data.dump(False)
|
||||
|
||||
|
||||
def reset(self):
|
||||
|
@ -65,12 +70,12 @@ class Library:
|
|||
|
||||
|
||||
# Hash a file and return list of words
|
||||
def hash(self,file):
|
||||
return
|
||||
file = file.lower()
|
||||
# Only keep letters and numbers
|
||||
words = re.sub('[^a-z0-9]',' ',file).split()
|
||||
return words
|
||||
#def hash(self,file):
|
||||
# return
|
||||
# file = file.lower()
|
||||
# # Only keep letters and numbers
|
||||
# words = re.sub('[^a-z0-9]',' ',file).split()
|
||||
# return words
|
||||
|
||||
|
||||
# Add song to library
|
||||
|
@ -139,20 +144,23 @@ class Library:
|
|||
#for i in range(len(album)-1):
|
||||
# str = album[i]+album[i+1]
|
||||
# info.double[str] = True
|
||||
self.libview.insert(info)
|
||||
if self.libview:
|
||||
self.libview.insert(info)
|
||||
if self.data.options.verbose == True:
|
||||
print info.filename
|
||||
|
||||
|
||||
# Return true if file is in the library
|
||||
def has(self,file):
|
||||
words = self.hash(file)
|
||||
if len(words) == 0:
|
||||
return -1
|
||||
if (words[0] in self.data.map.keys()) == False:
|
||||
return -1
|
||||
indices = set(self.data.map[words[0]])
|
||||
for word in words[1:]:
|
||||
indices = indices & set(self.data.map[word])
|
||||
# Return first instance
|
||||
if len(indices) > 0:
|
||||
return indices.pop()
|
||||
return -1
|
||||
#def has(self,file):
|
||||
# words = self.hash(file)
|
||||
# if len(words) == 0:
|
||||
# return -1
|
||||
# if (words[0] in self.data.map.keys()) == False:
|
||||
# return -1
|
||||
# indices = set(self.data.map[words[0]])
|
||||
# for word in words[1:]:
|
||||
# indices = indices & set(self.data.map[word])
|
||||
# # Return first instance
|
||||
# if len(indices) > 0:
|
||||
# return indices.pop()
|
||||
# return -1
|
||||
|
|
|
@ -77,20 +77,20 @@ class List(gtk.ScrolledWindow):
|
|||
# Select a song by double clicking on its row
|
||||
def selectSong(self,widgit,iter,path,data,list):
|
||||
self.loadSong(self.data.library.files[self.sort[iter][0]])
|
||||
#self.gotoCurSong()
|
||||
self.plause(None,None)
|
||||
self.data.scrobbler.nowPlaying(self.data.song.info)
|
||||
|
||||
|
||||
# Opens a menu on a right click
|
||||
def clicked(self,widgit,data):
|
||||
end = self.tree.get_path_at_pos(int(data.x),int(data.y))
|
||||
# end will be None if no rows are selected.
|
||||
if end != None:
|
||||
end = end[0][0]
|
||||
begin = self.sel.get_selected_rows()[1][0][0]
|
||||
# This function likes ints for some reason...
|
||||
self.sel.select_range(int(begin),int(end))
|
||||
if data.button == 3:
|
||||
end = self.tree.get_path_at_pos(int(data.x),int(data.y))
|
||||
# end will be None if no rows are selected.
|
||||
if end != None:
|
||||
end = end[0][0]
|
||||
begin = self.sel.get_selected_rows()[1][0][0]
|
||||
self.sel.select_range(int(begin),int(end))
|
||||
self.rcmenu.popup(None,None,None,data.button,data.time)
|
||||
|
||||
|
||||
|
@ -215,9 +215,10 @@ class List(gtk.ScrolledWindow):
|
|||
self.data.song.close()
|
||||
self.data.song = Song(file,self.next)
|
||||
self.data.curSong = file.id
|
||||
self.gotoCurSong()
|
||||
self.setAlbumArt(file.filename)
|
||||
self.labels()
|
||||
self.gotoCurSong()
|
||||
#self.gotoCurSong()
|
||||
|
||||
|
||||
# Scroll the window and select the row
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import sys
|
||||
import os
|
||||
import gtk
|
||||
import gobject
|
||||
|
||||
from options import Options
|
||||
from data import Data
|
||||
from library import Library
|
||||
|
||||
from window import Window
|
||||
|
||||
|
@ -16,8 +18,13 @@ class main:
|
|||
self.options = Options()
|
||||
if ("-v" in argv) == True:
|
||||
self.options.verbose = True
|
||||
# Load saved data (or create new data)
|
||||
|
||||
self.data = Data(self.options)
|
||||
|
||||
if ("-l" in argv) == True:
|
||||
self.buildLib()
|
||||
return
|
||||
# Load saved data (or create new data)
|
||||
#self.data.song = Song(self.quit)
|
||||
self.data.quit = None
|
||||
|
||||
|
@ -39,5 +46,27 @@ class main:
|
|||
return False
|
||||
|
||||
|
||||
def buildLib(self):
|
||||
path = ""
|
||||
validPath= False
|
||||
self.data.options.verbose = True
|
||||
self.data.library.data = self.data
|
||||
while validPath == False:
|
||||
path = raw_input("Input path to library: ")
|
||||
path = os.path.expanduser(path)
|
||||
if os.path.exists(path) == True:
|
||||
validPath = True
|
||||
else:
|
||||
print "Invalid path entered:",path
|
||||
actual = ""
|
||||
actual = raw_input("Input recorded library path (or none to use scan path): ")
|
||||
print actual
|
||||
print "Scanning: ",path
|
||||
self.data.library.scan(None,path)
|
||||
if actual != "":
|
||||
self.data.library.path = actual
|
||||
self.data.dump(False)
|
||||
print "Library saved to ~/.ocarina/library"
|
||||
|
||||
|
||||
if __name__=='__main__':main(sys.argv[1:])
|
||||
|
|
Loading…
Reference in New Issue