diff options
author | Gui Chen <gui.chen@intel.com> | 2014-04-26 00:23:30 -0400 |
---|---|---|
committer | admin <yuhuan.yang@samsung.com> | 2016-02-04 17:44:11 +0800 |
commit | 4ce5a8f124e164bfa56a41bb3ba4e3d36aaf7d91 (patch) | |
tree | 0b5412666dafce66f18e67d2eaa1ae0317667601 | |
parent | 85161a132a92a90ae3e87f1c5245af3f0c7bfc07 (diff) | |
download | mic-4ce5a8f124e164bfa56a41bb3ba4e3d36aaf7d91.tar.gz mic-4ce5a8f124e164bfa56a41bb3ba4e3d36aaf7d91.tar.bz2 mic-4ce5a8f124e164bfa56a41bb3ba4e3d36aaf7d91.zip |
archive.py: refine extract_archive to extract tarball file
Change-Id: I5af9f17de9d1ac5d12bf1706ce7609ea4c4e201f
Signed-off-by: Gui Chen <gui.chen@intel.com>
-rw-r--r-- | mic/archive.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/mic/archive.py b/mic/archive.py index a384b86..d506b92 100644 --- a/mic/archive.py +++ b/mic/archive.py @@ -294,7 +294,7 @@ def _imp_tarfile(archive_name, target_name): def _make_tarball(archive_name, target_name, compressor=None): """ Create a tarball from all the files under 'target_name' or itself. - @archive_name: the name of the archived file + @archive_name: the name of the archived file to create @target_name: the directory or the file name to archive @compressor: callback function to compress the tarball @retval: indicate the compressing result @@ -317,6 +317,18 @@ def _make_tarball(archive_name, target_name, compressor=None): return os.path.exists(archive_name) +def _extract_tarball(archive_name, target_dir, compressor=None): + """ Extract a tarball to a target directory + + @archive_name: the name of the archived file to extract + @target_dir: the directory of the extracted target + @retval: indicte the untar result + """ + + _do_untar(archive_name, target_dir) + + return not os.path.exists(archive_name) + def _make_zipfile(archive_name, target_name): """ Create a zip file from all the files under 'target_name' or itself. @@ -388,6 +400,7 @@ def make_archive(archive_name, target_name): @archive_name: the name of the archived file @target_name: the directory or the file to archive + @retval: the archiving result """ for aformat, suffixes in _ARCHIVE_SUFFIXES.iteritems(): if filter(archive_name.endswith, suffixes): @@ -403,10 +416,17 @@ def make_archive(archive_name, target_name): return func(archive_name, target_name, **kwargs) -def extract_archive(): +def extract_archive(archive_name, target_name): """ Extract the given file + + @archive_name: the name of the archived file to extract + @target_name: the directory name where the target locates + @retval: the extracting result """ - pass + if not os.path.exists(target_dir): + os.makedirs(target_dir) + + return _extract_tarball(archive_name, target_name) packing = make_archive compressing = compress |