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
|
|
|
|
2016-03-05 09:57:38 +13: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
|
|
|
|
2016-03-05 09:57:38 +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
|
|
|
|
2016-03-05 09:57:38 +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
|
|
|
|
2016-03-05 09:57:38 +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
|
|
|
|
2016-03-12 03:45:51 +13:00
|
|
|
def clearSaveCache():
|
|
|
|
v1.cache = {}
|
|
|
|
|
|
|
|
|
2016-03-05 09:57:38 +13:00
|
|
|
def loadProject(project):
|
2016-03-04 06:48:53 +13:00
|
|
|
|
2016-03-05 09:57:38 +13:00
|
|
|
# Detect version
|
2016-03-08 21:21:44 +13:00
|
|
|
isZip = False
|
2016-03-05 09:57:38 +13:00
|
|
|
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?
|
2016-03-31 21:45:58 +13:00
|
|
|
# Was used in transition between 0.2.0 and 0.3.0
|
|
|
|
# So VERSION part can be deleted for manuskript 0.4.0
|
2016-03-08 21:21:44 +13:00
|
|
|
if isZip and "VERSION" in zf.namelist():
|
|
|
|
version = int(zf.read("VERSION"))
|
|
|
|
|
2016-03-31 21:45:58 +13:00
|
|
|
# Does it have a MANUSKRIPT in zip root?
|
|
|
|
elif isZip and "MANUSKRIPT" in zf.namelist():
|
|
|
|
version = int(zf.read("MANUSKRIPT"))
|
|
|
|
|
|
|
|
# Zip but no VERSION/MANUSKRIPT: oldest file format
|
2016-03-08 21:21:44 +13:00
|
|
|
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:
|
2016-03-05 09:57:38 +13:00
|
|
|
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)
|