summaryrefslogtreecommitdiff
path: root/ishtar_common/serializers.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-02 13:06:48 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-02 13:06:48 +0200
commit12be9b206762b6872c680e072b9a2509334b4652 (patch)
treee7d9c54b7e7f53e5cf23bb18a9e809f49c74c5f2 /ishtar_common/serializers.py
parent9d82b632716c190746623f851beed1a67e027abf (diff)
downloadIshtar-12be9b206762b6872c680e072b9a2509334b4652.tar.bz2
Ishtar-12be9b206762b6872c680e072b9a2509334b4652.zip
Serialization: manage importers
Diffstat (limited to 'ishtar_common/serializers.py')
-rw-r--r--ishtar_common/serializers.py35
1 files changed, 30 insertions, 5 deletions
diff --git a/ishtar_common/serializers.py b/ishtar_common/serializers.py
index e9b904d6f..4867b58f6 100644
--- a/ishtar_common/serializers.py
+++ b/ishtar_common/serializers.py
@@ -56,6 +56,8 @@ def archive_serialization(result, archive_dir=None, archive=False,
types (default False)
:param archive: if True return a zip file containing all the file serialized
(default False)
+ :param archive_name: path to the archive if not provided a new archive is
+ created
:return: string containing the json serialization of types unless
return_empty_types or archive is set to True
"""
@@ -172,7 +174,7 @@ def generic_get_results(model_list, dirname):
for idx in range(len(new_result)):
for excluded_field in model.SERIALIZATION_EXCLUDE:
new_result[idx]["fields"].pop(excluded_field)
- result[key] = json.dumps(new_result)
+ result[key] = json.dumps(new_result, indent=2)
return result
@@ -209,16 +211,38 @@ CONF_MODEL_LIST = [
def conf_serialization(archive=False, return_empty_types=False,
archive_name=None):
- media_archive = generic_archive_files(CONF_MODEL_LIST)
- result = generic_get_results(CONF_MODEL_LIST, "common_conf")
+ media_archive = None
+ if archive:
+ media_archive = generic_archive_files(CONF_MODEL_LIST)
+ result = generic_get_results(CONF_MODEL_LIST, "common_configuration")
full_archive = archive_serialization(
- result, archive_dir="common_conf", archive=archive,
+ result, archive_dir="common_configuration", archive=archive,
return_empty_types=return_empty_types, archive_name=archive_name)
+ if not media_archive:
+ return full_archive
with ZipFile(full_archive, 'a') as current_zip:
current_zip.write(media_archive, arcname="media.zip")
return full_archive
+IMPORT_MODEL_LIST = [
+ models.Regexp, models.ImporterModel, models.ImporterType,
+ models.ValueFormater, models.ImporterColumn,
+ models.FormaterType, models.ImporterDefault, models.ImporterDefaultValues,
+ models.ImportTarget, models.ImporterDefaultValues,
+ models.ImporterDuplicateField
+]
+
+
+def importer_serialization(archive=False, return_empty_types=False,
+ archive_name=None):
+ result = generic_get_results(IMPORT_MODEL_LIST, "common_imports")
+ full_archive = archive_serialization(
+ result, archive_dir="common_imports", archive=archive,
+ return_empty_types=return_empty_types, archive_name=archive_name)
+ return full_archive
+
+
def restore_serialized(archive_name, delete_existing=False):
with zipfile.ZipFile(archive_name, "r") as zip_file:
# check version
@@ -230,7 +254,8 @@ def restore_serialized(archive_name, delete_existing=False):
)
DIRS = (
- ("types", [None]), ("common_conf", CONF_MODEL_LIST)
+ ("types", [None]), ("common_configuration", CONF_MODEL_LIST),
+ ("common_imports", IMPORT_MODEL_LIST),
)
namelist = zip_file.namelist()
for current_dir, model_list in DIRS: