libsaria: Integrate new preferences and storage code

This patch re-enables most of the libsaria startup procedures.  To allow
this, I had to switch over to the new preferences and object storage
code I recently came up with.
This commit is contained in:
Bryan Schumaker 2011-04-30 10:48:59 -04:00
parent 063869c7ca
commit 3dc0b208cf
6 changed files with 62 additions and 68 deletions

View File

@ -16,71 +16,61 @@ if __dev__ == True:
__vers__ = "Libsaria %s" % __vstr__
import prefs
import event
#import event
#import path
#from trees import Tree, PersPrefTree
#from path.cache import Cache
import path
from path.cache import Cache
## The cache is also saved across sessions
#prefs = None
#cache = Cache()
# The cache is also saved across sessions
cache = Cache()
##plugin = None
#audio = None
#lastfm = None
#controls = None
#init_pref = None
#plugin = None
audio = None
lastfm = None
controls = None
## Initialize helpful variables
#def init():
#global prefs
#global init_pref
#global audio
#global lastfm
#global controls
# Initialize helpful variables
def init():
global audio
global lastfm
global controls
#prefs = trees.get_pref_tree("preferences")
#init_pref = prefs.init_pref
#import audio
#import controls
#import sources
#from path import lastfm
#event.invite("POSTLIBLOAD", parse_user_input)
import audio
import controls
import sources
from path import lastfm
event.invite("POSTLIBLOAD", parse_user_input)
#sources.library.init_bg()
#sources.playlist.init_bg()
#sources.queue.init_bg()
#controls.init()
#event.start("POSTINIT")
sources.library.init_bg()
sources.playlist.init_bg()
sources.queue.init_bg()
controls.init()
event.start("POSTINIT")
#def startup():
## global plugin
## import plugin
def startup():
# global plugin
# import plugin
#event.start("PRESTART")
#audio.init()
#controls.init2()
## plugin.load_all()
#prefs.enable_save()
#event.start("POSTSTART")
#sources.playlist.startup()
event.start("PRESTART")
audio.init()
controls.init2()
# plugin.load_all()
prefs.enable_save()
event.start("POSTSTART")
sources.playlist.startup()
#def shutdown():
#event.start("PREQUIT")
def shutdown():
event.start("PREQUIT")
## import plugin
## plugin.quit()
#event.start("POSTQUIT")
event.start("POSTQUIT")
#def parse_user_input():
#import sys
#for item in sys.argv[1:]:
#path.files.universal_open(item)
#init()
def parse_user_input():
import sys
for item in sys.argv[1:]:
path.files.universal_open(item)
init()

View File

@ -4,15 +4,14 @@ __all__ = ['audio']
import gst
import libsaria
from libsaria import prefs
call = libsaria.event.call
expand = libsaria.path.expand
exists = libsaria.path.exists
audio = None
tdelta = None
def ls_init():
libsaria.init_pref("libsaria.audio.volume", 1.0)
libsaria.event.invite("POSTINIT", ls_init)
prefs.init("libsaria.audio.volume", 1.0)
def init():
global tdelta

View File

@ -21,7 +21,7 @@ def init():
lock.acquire()
player = gst.element_factory_make("playbin2", "player")
set_volume_locked(libsaria.prefs.get_pref("libsaria.audio.volume"))
set_volume_locked(libsaria.prefs.get("libsaria.audio.volume"))
time = gst.Format(gst.FORMAT_TIME)
bus = player.get_bus()
bus.add_signal_watch()
@ -184,7 +184,7 @@ def seek(prcnt):
def set_volume_locked(prcnt):
global player
player.set_property("volume", prcnt)
libsaria.prefs.set_pref("libsaria.audio.volume", prcnt)
libsaria.prefs.set("libsaria.audio.volume", prcnt)
return prcnt
def set_volume(prcnt):

View File

@ -1,5 +1,6 @@
# Bryan Schumaker (11/23/2010)
import prefs
libsaria = None
sources = None
library = None
@ -9,19 +10,15 @@ queue = None
audio = None
call = None
invite = None
prefs = None
expand = None
exists = None
pause_after = False
prefs.init("libsaria.random", False)
def init():
global libsaria
global prefs
import libsaria
prefs = libsaria.prefs
libsaria.init_pref("libsaria.random", False)
def init2():
global call
@ -98,7 +95,7 @@ def set_volume(prcnt):
return call("SETVOLUME", audio.set_volume, prcnt)
def set_rand(rand):
prefs.set_pref("libsaria.random", rand)
prefs.set("libsaria.random", rand)
def set_like(like=None):
return call("SETLIKE", sources.set_attr, "like", like)

View File

@ -6,6 +6,9 @@ import libsaria.path.files
from libsaria import threads
splitext = libsaria.path.splitext
from libsaria.trees import *
from index import Index
os = None
tagpy = None
Track = None
@ -63,6 +66,9 @@ def reset():
size = 0
visible = set()
def default_objects():
return ([], dict(), DLFSTree(), DLValTree(), Index())
def load():
global fs_tree
global tag_tree
@ -72,7 +78,7 @@ def load():
global lib_lock
global loaded
objects = libsaria.path.files.load("library", ".lib")
objects = libsaria.storage.load_obj("library", default_objects)
if objects == None or len(objects) != 5:
reset()
else:
@ -95,8 +101,7 @@ def init_bg():
def save():
global sources
libsaria.path.files.save( (locations, tracks, fs_tree, tag_tree, index),
"library", ".lib")
libsaria.storage.save_obj("library", (locations, tracks, fs_tree, tag_tree, index))
def walk():
for tag in tag_tree.walk():

View File

@ -62,13 +62,16 @@ def reset():
song_set = set()
cur_index = -1
def default_objects():
return ([], [], -1)
def load():
global song_list
global song_set
global recent
global visible
global cur_index
objects = libsaria.path.files.load("playlist", ".list")
objects = libsaria.storage.load_obj("playlist", default_objects)
if objects == None or len(objects) != 3:
reset()
else:
@ -88,7 +91,7 @@ def startup():
load_id(song_list[cur_index])
def save():
libsaria.path.files.save( (song_list, recent, cur_index), "playlist", ".list")
libsaria.storage.save_obj("playlist", (song_list, recent, cur_index))
def walk():
global song_list