diff options
author | Malik Talha <talhamalik727x@gmail.com> | 2023-10-22 21:06:23 +0500 |
---|---|---|
committer | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2023-10-23 14:38:13 +0000 |
commit | 697a1adce1e463079e640b55d6386cf82d7bd6bc (patch) | |
tree | 86e299cc7fe12b10c2e549f640924b61c7d07a95 /snips_inference_agl/common/io_utils.py | |
parent | 97029ab8141e654a170a2282106f854037da294f (diff) |
Add Snips Inference Module
Add slightly modified version of the original Snips NLU
library. This module adds support for Python upto version
3.10.
Bug-AGL: SPEC-4856
Signed-off-by: Malik Talha <talhamalik727x@gmail.com>
Change-Id: I6d7e9eb181e6ff4aed9b6291027877ccb9f0d846
Diffstat (limited to 'snips_inference_agl/common/io_utils.py')
-rw-r--r-- | snips_inference_agl/common/io_utils.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/snips_inference_agl/common/io_utils.py b/snips_inference_agl/common/io_utils.py new file mode 100644 index 0000000..f4407a3 --- /dev/null +++ b/snips_inference_agl/common/io_utils.py @@ -0,0 +1,36 @@ +import errno +import os +import shutil +from contextlib import contextmanager +from pathlib import Path +from tempfile import mkdtemp +from zipfile import ZipFile, ZIP_DEFLATED + + +def mkdir_p(path): + """Reproduces the 'mkdir -p shell' command + + See + http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python + """ + try: + os.makedirs(str(path)) + except OSError as exc: # Python >2.5 + if exc.errno == errno.EEXIST and path.is_dir(): + pass + else: + raise + + +@contextmanager +def temp_dir(): + tmp_dir = mkdtemp() + try: + yield Path(tmp_dir) + finally: + shutil.rmtree(tmp_dir) + + +def unzip_archive(archive_file, destination_dir): + with ZipFile(archive_file, "r", ZIP_DEFLATED) as zipf: + zipf.extractall(str(destination_dir)) |