manuskript/manuskript/loadSave.py

61 lines
1.3 KiB
Python
Raw Normal View History

2015-05-31 16:03:07 +12:00
#!/usr/bin/env python
2016-03-04 06:48:53 +13:00
# --!-- coding: utf8 --!--
2015-05-31 16:03:07 +12:00
# The loadSave file calls the propper functions to load and save file
# trying to detect the proper file format if it comes from an older version
2016-03-10 04:02:22 +13:00
import os
2016-03-08 21:21:44 +13:00
import zipfile
2016-02-07 00:34:22 +13:00
import manuskript.load_save.version_0 as v0
import manuskript.load_save.version_1 as v1
2016-02-07 00:34:22 +13:00
2016-03-08 21:21:44 +13:00
def saveProject(version=None):
2016-02-07 00:34:22 +13:00
2016-03-10 23:45:40 +13:00
# While debugging, we don't save the project
2016-03-11 02:11:28 +13:00
# return
2016-03-10 23:45:40 +13:00
if version == 0:
v0.saveProject()
2015-06-17 23:25:46 +12:00
else:
2016-03-10 23:45:40 +13:00
v1.saveProject()
2016-03-04 06:48:53 +13:00
def clearSaveCache():
v1.cache = {}
def loadProject(project):
2016-03-04 06:48:53 +13:00
# Detect version
2016-03-08 21:21:44 +13:00
isZip = False
version = 0
2016-03-04 06:48:53 +13:00
2016-03-10 04:02:22 +13:00
# Is it a zip?
2016-03-08 21:21:44 +13:00
try:
zf = zipfile.ZipFile(project)
isZip = True
except zipfile.BadZipFile:
isZip = False
# Does it have a VERSION in zip root?
if isZip and "VERSION" in zf.namelist():
version = int(zf.read("VERSION"))
# Zip but no VERSION: oldest file format
elif isZip:
version = 0
# Not a zip
else:
2016-03-10 05:20:43 +13:00
with open(project, "r") as f:
version = int(f.read())
2016-03-08 21:21:44 +13:00
2016-03-10 23:45:40 +13:00
print("Loading:", project)
2016-03-11 02:15:03 +13:00
print("Detected file format version: {}. Zip: {}.".format(version, isZip))
2016-03-08 21:21:44 +13:00
2016-03-10 23:45:40 +13:00
if version == 0:
v0.loadProject(project)
2015-06-17 23:25:46 +12:00
else:
2016-03-10 23:45:40 +13:00
v1.loadProject(project, zip=isZip)