Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'io_blend_utils/utils/system.py')
-rw-r--r--io_blend_utils/utils/system.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/io_blend_utils/utils/system.py b/io_blend_utils/utils/system.py
index 970a6464..313173ee 100644
--- a/io_blend_utils/utils/system.py
+++ b/io_blend_utils/utils/system.py
@@ -72,6 +72,29 @@ def uuid_from_file(fn, block_size=1 << 20):
return hex(size)[2:] + sha1.hexdigest()
+def write_json_to_zip(zip_handle, path, data=None):
+ import json
+ zip_handle.writestr(
+ path,
+ json.dumps(
+ data,
+ check_circular=False,
+ # optional (pretty)
+ sort_keys=True, indent=4, separators=(',', ': '),
+ ).encode('utf-8'))
+
+
+def write_json_to_file(path, data):
+ import json
+ with open(path, 'w') as file_handle:
+ json.dump(
+ data, file_handle, ensure_ascii=False,
+ check_circular=False,
+ # optional (pretty)
+ sort_keys=True, indent=4, separators=(',', ': '),
+ )
+
+
def is_compressed_filetype(filepath):
"""
Use to check if we should compress files in a zip.
@@ -103,3 +126,18 @@ def is_compressed_filetype(filepath):
# '.zip',
}
+
+def is_subdir(path, directory):
+ """
+ Returns true if *path* in a subdirectory of *directory*.
+ """
+ import os
+ from os.path import normpath, normcase, sep
+ path = normpath(normcase(path))
+ directory = normpath(normcase(directory))
+ if len(path) > len(directory):
+ sep = sep.encode('ascii') if isinstance(directory, bytes) else sep
+ if path.startswith(directory.rstrip(sep) + sep):
+ return True
+ return False
+