49 lines
906 B
Python
49 lines
906 B
Python
# Bryan Schumaker (8/7/2010)
|
|
|
|
from libsaria import path
|
|
import cPickle as pickle
|
|
#import pickle
|
|
plugin = None
|
|
|
|
PROTO = pickle.HIGHEST_PROTOCOL
|
|
|
|
def save(item, file, ext=".pickle"):
|
|
file = "%s%s" % (path.join(path.saria_dir(),file), ext)
|
|
savefile(item, file)
|
|
|
|
|
|
def savefile(item, file):
|
|
f = open(file, 'w')
|
|
p = pickle.Pickler(f, PROTO)
|
|
p.dump(item)
|
|
f.close()
|
|
|
|
|
|
def load(file, ext=".pickle"):
|
|
file = "%s%s" % (path.join(path.saria_dir(),file),ext)
|
|
print file
|
|
return loadfile(file)
|
|
|
|
|
|
def loadfile(file):
|
|
if path.exists(file) == False:
|
|
return
|
|
f = open(file)
|
|
p = pickle.Unpickler(f)
|
|
item = p.load()
|
|
f.close()
|
|
return item
|
|
|
|
|
|
def universal_open(file):
|
|
global plugin
|
|
split = file.rsplit('.', 1)
|
|
ext = split[len(split)-1]
|
|
if path.is_dir(file):
|
|
print "Is a dir! Scan it!"
|
|
# Install and start a plugin
|
|
if ext == "py":
|
|
if plugin == None:
|
|
from libsaria import plugin
|
|
plugin.install(file)
|