2010-08-07 12:55:23 -04:00
|
|
|
# Bryan Schumaker (8/7/2010)
|
|
|
|
|
2010-10-08 13:09:42 -04:00
|
|
|
import libsaria
|
2010-08-07 12:55:23 -04:00
|
|
|
from libsaria import path
|
|
|
|
import cPickle as pickle
|
2010-08-15 01:05:37 -04:00
|
|
|
plugin = None
|
2010-08-07 12:55:23 -04:00
|
|
|
|
2010-11-01 08:22:38 -04:00
|
|
|
dev = ""
|
|
|
|
if libsaria.__dev__ == True:
|
|
|
|
dev = "-dev"
|
|
|
|
|
2010-08-07 12:55:23 -04:00
|
|
|
PROTO = pickle.HIGHEST_PROTOCOL
|
|
|
|
|
2010-08-19 23:02:30 -04:00
|
|
|
def save(item, file, ext=".pickle"):
|
2010-11-01 08:22:38 -04:00
|
|
|
file = "%s%s%s" % (path.join(path.saria_dir(),file), dev, ext)
|
2010-08-07 12:55:23 -04:00
|
|
|
savefile(item, file)
|
|
|
|
|
|
|
|
|
|
|
|
def savefile(item, file):
|
|
|
|
f = open(file, 'w')
|
|
|
|
p = pickle.Pickler(f, PROTO)
|
|
|
|
p.dump(item)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
2010-08-19 23:02:30 -04:00
|
|
|
def load(file, ext=".pickle"):
|
2010-11-01 08:22:38 -04:00
|
|
|
file = "%s%s%s" % (path.join(path.saria_dir(),file), dev, ext)
|
2010-08-07 12:55:23 -04:00
|
|
|
return loadfile(file)
|
|
|
|
|
|
|
|
|
|
|
|
def loadfile(file):
|
|
|
|
if path.exists(file) == False:
|
|
|
|
return
|
|
|
|
f = open(file)
|
2010-12-16 09:29:06 -05:00
|
|
|
data = f.read()
|
|
|
|
item = pickle.loads(data)
|
2010-08-07 12:55:23 -04:00
|
|
|
f.close()
|
|
|
|
return item
|
|
|
|
|
|
|
|
|
2010-08-15 01:05:37 -04:00
|
|
|
def universal_open(file):
|
|
|
|
global plugin
|
2010-11-09 13:55:14 -05:00
|
|
|
file = file.replace("%20", " ")
|
|
|
|
file = file.replace("%22", "\"")
|
2010-09-13 19:32:13 -04:00
|
|
|
if path.is_dir(file):
|
2010-11-14 13:50:35 -05:00
|
|
|
libsaria.sources.new_source(file)
|
2010-10-21 07:55:21 -04:00
|
|
|
return
|
2010-10-08 13:09:42 -04:00
|
|
|
split = path.splitext(file)
|
|
|
|
ext = split[1]
|
2010-08-15 01:05:37 -04:00
|
|
|
# Install and start a plugin
|
2010-10-08 13:09:42 -04:00
|
|
|
if ext == ".py":
|
2010-08-15 01:05:37 -04:00
|
|
|
if plugin == None:
|
|
|
|
from libsaria import plugin
|
|
|
|
plugin.install(file)
|
2010-10-24 17:12:01 -04:00
|
|
|
return
|
2010-11-27 23:11:16 -05:00
|
|
|
if ext == ".xml":
|
2010-12-18 14:52:31 -05:00
|
|
|
import export
|
|
|
|
export.import_xml(file)
|
2010-11-27 23:11:16 -05:00
|
|
|
return
|
2010-10-08 13:09:42 -04:00
|
|
|
try:
|
2010-12-07 20:47:32 -05:00
|
|
|
from libsaria.sources import file as file_source
|
|
|
|
file_source.load_file(file)
|
2010-10-08 13:09:42 -04:00
|
|
|
except Exception,e:
|
|
|
|
print e
|
|
|
|
pass
|