manuskript/manuskript/loadSave.py

52 lines
1 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-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
if version == 0:
v0.saveProject()
2015-06-17 23:25:46 +12:00
else:
v1.saveProject()
2016-03-04 06:48:53 +13:00
def loadProject(project):
2016-03-04 06:48:53 +13:00
# Detect version
2016-03-08 21:21:44 +13:00
# Is it a zip?
isZip = False
version = 0
2016-03-04 06:48:53 +13:00
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:
# FIXME
pass
print("Detected file format version:", version)
if version == 0:
v0.loadProject(project)
2015-06-17 23:25:46 +12:00
else:
v1.loadProject(project)