summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGui Chen <gui.chen@intel.com>2014-04-23 04:43:41 -0400
committeradmin <yuhuan.yang@samsung.com>2016-02-04 00:46:00 +0800
commit78946b98c92445b39841b5910650aa6155708594 (patch)
treed8ec4a4d3e659ea029e51658781995e818bf5365
parent5b9d9c272b87ca95dd11a09e19972622f9f2e209 (diff)
downloadmic-78946b98c92445b39841b5910650aa6155708594.tar.gz
mic-78946b98c92445b39841b5910650aa6155708594.tar.bz2
mic-78946b98c92445b39841b5910650aa6155708594.zip
clean up unused code
Change-Id: I483e4253437a3fa9905ff354f7739b15f71ec2c2 Signed-off-by: Gui Chen <gui.chen@intel.com> Conflicts: mic/utils/misc.py
-rw-r--r--mic/utils/misc.py85
1 files changed, 0 insertions, 85 deletions
diff --git a/mic/utils/misc.py b/mic/utils/misc.py
index 243051e..81e969c 100644
--- a/mic/utils/misc.py
+++ b/mic/utils/misc.py
@@ -187,91 +187,6 @@ def extract_rpm(rpmfile, targetdir):
os.chdir(olddir)
-def compressing(fpath, method):
- comp_map = {
- "gz": ["pgzip", "pigz", "gzip"],
- "bz2": ["pbzip2", "bzip2"],
- }
- if method not in comp_map:
- raise CreatorError("Unsupport compress format: %s, valid values: %s"
- % (method, ','.join(comp_map.keys())))
- cmd = None
- for cmdname in comp_map[method]:
- try:
- cmd = find_binary_path(cmdname)
- break
- except CreatorError as err:
- pass
- if not cmd:
- raise CreatorError("Command %s not available" % cmdname)
- rc = runner.show([cmd, "-f", fpath])
- if rc:
- raise CreatorError("Failed to %s file: %s" % (comp_map[method], fpath))
-
-def taring(dstfile, target):
- import tarfile
- basen, ext = os.path.splitext(dstfile)
- comp = {".tar": None,
- ".gz": "gz", # for .tar.gz
- ".bz2": "bz2", # for .tar.bz2
- ".tgz": "gz",
- ".tbz": "bz2"}[ext]
-
- # specify tarball file path
- if not comp:
- tarpath = dstfile
- elif basen.endswith(".tar"):
- tarpath = basen
- else:
- tarpath = basen + ".tar"
- wf = tarfile.open(tarpath, 'w')
-
- if os.path.isdir(target):
- for item in os.listdir(target):
- wf.add(os.path.join(target, item), item)
- else:
- wf.add(target, os.path.basename(target))
- wf.close()
-
- if comp:
- compressing(tarpath, comp)
- # when dstfile ext is ".tgz" and ".tbz", should rename
- if not basen.endswith(".tar"):
- shutil.move("%s.%s" % (tarpath, comp), dstfile)
-
-def ziping(dstfile, target):
- import zipfile
- wf = zipfile.ZipFile(dstfile, 'w', compression=zipfile.ZIP_DEFLATED)
- if os.path.isdir(target):
- for item in os.listdir(target):
- fpath = os.path.join(target, item)
- if not os.path.isfile(fpath):
- continue
- wf.write(fpath, item, zipfile.ZIP_DEFLATED)
- else:
- wf.write(target, os.path.basename(target), zipfile.ZIP_DEFLATED)
- wf.close()
-
-pack_formats = {
- ".tar": taring,
- ".tar.gz": taring,
- ".tar.bz2": taring,
- ".tgz": taring,
- ".tbz": taring,
- ".zip": ziping,
-}
-
-def packing(dstfile, target):
- (base, ext) = os.path.splitext(dstfile)
- if ext in (".gz", ".bz2") and base.endswith(".tar"):
- ext = ".tar" + ext
- if ext not in pack_formats:
- raise CreatorError("Unsupport pack format: %s, valid values: %s"
- % (ext, ','.join(pack_formats.keys())))
- func = pack_formats[ext]
- # func should be callable
- func(dstfile, target)
-
def human_size(size):
"""Return human readable string for Bytes size
"""