Replace the unar to more common archivers
Because some of distributions dont provide the unar (universal archiver), Using more common archivers to replace it. Signed-off-by: Lin Ma <lma@suse.com> (crobinso: adjust test suite)
This commit is contained in:
parent
9747cd5473
commit
21fd079eb1
|
@ -73,5 +73,5 @@
|
||||||
</domain>
|
</domain>
|
||||||
|
|
||||||
|
|
||||||
test-vmx-zip.zip appears to be an archive, running: unar -o /var/tmp/virt-convert-tmp test-vmx-zip.zip
|
test-vmx-zip.zip appears to be an archive, running: unzip -o -d /var/tmp/virt-convert-tmp /home/crobinso/src/virt-manager/tests/virtconv-files/vmx_input/test-vmx-zip.zip
|
||||||
Copying MS-DOS.vmdk to /var/lib/libvirt/images/MS-DOS
|
Copying MS-DOS.vmdk to /var/lib/libvirt/images/MS-DOS
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301 USA.
|
# MA 02110-1301 USA.
|
||||||
|
|
||||||
from distutils.spawn import find_executable
|
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import StringIO
|
import StringIO
|
||||||
|
@ -66,10 +65,6 @@ class TestVirtConv(unittest.TestCase):
|
||||||
if disk_format:
|
if disk_format:
|
||||||
out_path += ".disk_%s" % disk_format
|
out_path += ".disk_%s" % disk_format
|
||||||
|
|
||||||
if (os.path.splitext(in_path)[1] in [".zip"] and
|
|
||||||
not find_executable("unar")):
|
|
||||||
self.skipTest("Install 'unar' to run all tests.")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.chdir(os.path.dirname(in_path))
|
os.chdir(os.path.dirname(in_path))
|
||||||
self._convert_helper(in_path, out_path, in_type, disk_format)
|
self._convert_helper(in_path, out_path, in_type, disk_format)
|
||||||
|
|
|
@ -118,6 +118,8 @@ def _find_input(input_file, parser, print_cb):
|
||||||
try:
|
try:
|
||||||
ext = os.path.splitext(input_file)[1]
|
ext = os.path.splitext(input_file)[1]
|
||||||
tempdir = None
|
tempdir = None
|
||||||
|
binname = None
|
||||||
|
pkg = None
|
||||||
if ext and ext[1:] in ["zip", "gz", "ova",
|
if ext and ext[1:] in ["zip", "gz", "ova",
|
||||||
"tar", "bz2", "bzip2", "7z", "xz"]:
|
"tar", "bz2", "bzip2", "7z", "xz"]:
|
||||||
basedir = "/var/tmp"
|
basedir = "/var/tmp"
|
||||||
|
@ -129,19 +131,40 @@ def _find_input(input_file, parser, print_cb):
|
||||||
|
|
||||||
base = os.path.basename(input_file)
|
base = os.path.basename(input_file)
|
||||||
|
|
||||||
# check if 'unar' command existed.
|
if (ext[1:] == "zip"):
|
||||||
if not find_executable("unar"):
|
binname = "unzip"
|
||||||
|
pkg = "unzip"
|
||||||
|
cmd = ["unzip", "-o", "-d", tempdir, input_file]
|
||||||
|
elif (ext[1:] == "7z"):
|
||||||
|
binname = "7z"
|
||||||
|
pkg = "p7zip"
|
||||||
|
cmd = ["7z", "-o" + tempdir, "e", input_file]
|
||||||
|
elif (ext[1:] == "ova" or ext[1:] == "tar"):
|
||||||
|
binname = "tar"
|
||||||
|
pkg = "tar"
|
||||||
|
cmd = ["tar", "xf", input_file, "-C", tempdir]
|
||||||
|
elif (ext[1:] == "gz"):
|
||||||
|
binname = "gzip"
|
||||||
|
pkg = "gzip"
|
||||||
|
cmd = ["tar", "zxf", input_file, "-C", tempdir]
|
||||||
|
elif (ext[1:] == "bz2" or ext[1:] == "bzip2"):
|
||||||
|
binname = "bzip2"
|
||||||
|
pkg = "bzip2"
|
||||||
|
cmd = ["tar", "jxf", input_file, "-C", tempdir]
|
||||||
|
elif (ext[1:] == "xz"):
|
||||||
|
binname = "xz"
|
||||||
|
pkg = "xz"
|
||||||
|
cmd = ["tar", "Jxf", input_file, "-C", tempdir]
|
||||||
|
if not find_executable(binname):
|
||||||
raise RuntimeError(_("%s appears to be an archive, "
|
raise RuntimeError(_("%s appears to be an archive, "
|
||||||
"but 'unar' is not installed. "
|
"but '%s' is not installed. "
|
||||||
"Please either install 'unar', or extract the archive "
|
"Please either install '%s', or extract the archive "
|
||||||
"yourself and point virt-convert at "
|
"yourself and point virt-convert at "
|
||||||
"the extracted directory.") % base)
|
"the extracted directory.") % (base, pkg, pkg))
|
||||||
|
|
||||||
cmd = ["unar", "-o", tempdir, base]
|
|
||||||
print_cb(_("%s appears to be an archive, running: %s") %
|
print_cb(_("%s appears to be an archive, running: %s") %
|
||||||
(base, " ".join(cmd)))
|
(base, " ".join(cmd)))
|
||||||
|
|
||||||
cmd[-1] = input_file
|
|
||||||
_run_cmd(cmd)
|
_run_cmd(cmd)
|
||||||
force_clean.append(tempdir)
|
force_clean.append(tempdir)
|
||||||
input_file = tempdir
|
input_file = tempdir
|
||||||
|
|
Loading…
Reference in New Issue