mirror of https://github.com/fmartingr/iosfu.git
Backup data: Fixed not caching exception for Python2.X, data default settings are now stored in a configuration variable.
Fixed serializer for py2/3 compatibility
This commit is contained in:
parent
dac7e1fa74
commit
577b10273a
|
@ -1,10 +1,12 @@
|
|||
from __future__ import with_statement
|
||||
|
||||
from os import listdir
|
||||
from os.path import join as join_paths, basename, isdir, isfile
|
||||
from plistlib import readPlist
|
||||
|
||||
from biplist import readPlist as readBinaryPlist
|
||||
|
||||
from .conf import BACKUPS_PATH
|
||||
from .conf import BACKUPS_PATH, BACKUP_DEFAULT_SETTINGS
|
||||
from iosfu import utils
|
||||
|
||||
|
||||
|
@ -84,14 +86,10 @@ class Backup(object):
|
|||
def read_data_file(self):
|
||||
try:
|
||||
handler = open(self._data_file)
|
||||
except FileNotFoundError:
|
||||
except (OSError, IOError):
|
||||
# Create default config file if non-existant
|
||||
handler = open(self._data_file, 'w+')
|
||||
# Initial data
|
||||
data = {
|
||||
"id": self.id,
|
||||
"cache": {}
|
||||
}
|
||||
handler.write(utils.serialize(data))
|
||||
handler.write(utils.serialize(BACKUP_DEFAULT_SETTINGS))
|
||||
handler.seek(0)
|
||||
finally:
|
||||
with handler as f:
|
||||
|
|
|
@ -7,3 +7,9 @@ ROOT_PATH = getcwd()
|
|||
|
||||
# Backups folder name
|
||||
BACKUPS_PATH = join_paths(ROOT_PATH, '_backups')
|
||||
|
||||
# Backup default settings
|
||||
BACKUP_DEFAULT_SETTINGS = {
|
||||
"cache.enabled": False,
|
||||
"cache": {}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,8 @@ import json
|
|||
|
||||
class IOSFUEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
|
||||
# DATETIME -> TIMESTAMP
|
||||
if isinstance(obj, datetime.datetime):
|
||||
if isinstance(obj, datetime):
|
||||
return "timestamp:{}".format(obj.timestamp())
|
||||
|
||||
# Let the base class default method raise the TypeError
|
||||
|
@ -41,7 +40,7 @@ def slugify(string):
|
|||
|
||||
|
||||
def serialize(dictionary):
|
||||
return json.dumps(dictionary, indent=4 * ' ', cls=IOSFUEncoder)
|
||||
return json.dumps(dictionary, indent=4, cls=IOSFUEncoder)
|
||||
|
||||
|
||||
def deserialize(string):
|
||||
|
|
Loading…
Reference in New Issue