From 1921e78e55233c2c99e3b18d3ccc9772d108751c Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Thu, 28 Apr 2011 08:27:51 -0400 Subject: [PATCH] libsaria: Comment out most code, begin new preferences I commented out most of the code in libsaria/__init__.py to make it easier to clean up. I also began work on libsaria/prefs.py for managing preferences. NOTE: For the next several commits, the best way to test changes is by importing libsaria through the python interpreter. Trying to run ocarina will probably fail. --- libsaria/__init__.py | 104 ++++++++++++++++++----------------- libsaria/prefs.py | 6 ++ libsaria/storage/__init__.py | 24 ++++++++ 3 files changed, 83 insertions(+), 51 deletions(-) create mode 100644 libsaria/prefs.py create mode 100644 libsaria/storage/__init__.py diff --git a/libsaria/__init__.py b/libsaria/__init__.py index 87b361e4..7b48c6db 100644 --- a/libsaria/__init__.py +++ b/libsaria/__init__.py @@ -15,70 +15,72 @@ if __dev__ == True: __vstr__ += "-dev" __vers__ = "Libsaria %s" % __vstr__ -import event -import path -from trees import Tree, PersPrefTree -from path.cache import Cache +import prefs -# The cache is also saved across sessions -prefs = None -cache = Cache() +#import event +#import path +#from trees import Tree, PersPrefTree +#from path.cache import Cache -#plugin = None -audio = None -lastfm = None -controls = None +## The cache is also saved across sessions +#prefs = None +#cache = Cache() -init_pref = None +##plugin = None +#audio = None +#lastfm = None +#controls = None + +#init_pref = None -# Initialize helpful variables -def init(): - global prefs - global init_pref - global audio - global lastfm - global controls +## Initialize helpful variables +#def init(): + #global prefs + #global init_pref + #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) + #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) - 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") -# import plugin -# plugin.quit() - event.start("POSTQUIT") +#def shutdown(): + #event.start("PREQUIT") +## import plugin +## plugin.quit() + #event.start("POSTQUIT") -def parse_user_input(): - import sys - for item in sys.argv[1:]: - path.files.universal_open(item) +#def parse_user_input(): + #import sys + #for item in sys.argv[1:]: + #path.files.universal_open(item) -init() +#init() diff --git a/libsaria/prefs.py b/libsaria/prefs.py new file mode 100644 index 00000000..e04bb23a --- /dev/null +++ b/libsaria/prefs.py @@ -0,0 +1,6 @@ +# Bryan Schumaker (4 / 28 / 2011) + +import storage + +prefs = storage.load_file("preferences", dict) + diff --git a/libsaria/storage/__init__.py b/libsaria/storage/__init__.py new file mode 100644 index 00000000..6fcebdec --- /dev/null +++ b/libsaria/storage/__init__.py @@ -0,0 +1,24 @@ +# Bryan Schumaker (4 / 28 / 2011) + +import os +from os import path +import cPickle as pickle +import libsaria + +USER_DIR = path.expanduser("~") + +saria = ".saria" +if libsaria.__dev__ == True: + saria = ".saria-dev" +SARIA_DIR = path.join(USER_DIR, saria) +if path.exists(SARIA_DIR) == False: + os.mkdir(SARIA_DIR) + +def load_file(filename, default): + file = path.join(SARIA_DIR, filename) + if path.exists(file) == False: + return default() + f = open(file) + item = pickle.loads(f.read()) + f.close() + return item