60 lines
1.2 KiB
Python
60 lines
1.2 KiB
Python
import os
|
|
import cPickle as pickle
|
|
from library import Library
|
|
|
|
from song import Song
|
|
|
|
class SavedData:
|
|
def __init__(self,options):
|
|
path = os.path.join(options.user,".ocarina")
|
|
path = os.path.join(path,"ocarina-data.data")
|
|
self.size = (800,600)
|
|
self.divider = 150
|
|
self.library = Library()
|
|
self.curList = []
|
|
self.curSong = 0
|
|
self.colSizes = [110,110,110,110,110]
|
|
self.sortedCol = 3
|
|
self.updateList = False
|
|
self.path = path
|
|
self.song = None
|
|
self.random = False
|
|
|
|
if os.path.exists(path):
|
|
try:
|
|
self.load(path,options)
|
|
except:
|
|
if options.verbose == True:
|
|
print "Error loading user data"
|
|
|
|
|
|
# Dump user data to a file
|
|
def dump(self):
|
|
out = open(self.path,'w')
|
|
p = pickle.Pickler(out,1)
|
|
p.dump(self)
|
|
out.close()
|
|
|
|
|
|
def clearSong(self):
|
|
self.song.close()
|
|
self.song = None
|
|
return
|
|
|
|
|
|
# Read user data from the file
|
|
def load(self,path,options):
|
|
if options.verbose == True:
|
|
print "User data found, loading..."
|
|
p = pickle.Unpickler(open(path))
|
|
data = p.load()
|
|
self.size = data.size
|
|
self.divider = data.divider
|
|
self.library = data.library
|
|
self.curList = data.curList
|
|
self.curSong = 0
|
|
self.colSizes = data.colSizes
|
|
self.path = data.path
|
|
self.random = data.random
|
|
self.curSong = data.curSong
|