qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 5/6] tests/boot_linux_console: add extract_from_rpm method


From: Liam Merwick
Subject: Re: [PATCH 5/6] tests/boot_linux_console: add extract_from_rpm method
Date: Tue, 4 Feb 2020 13:31:40 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0

On 31/01/2020 15:02, Liam Merwick wrote:

[... deleted ...]



+        :returns: path of the extracted file
+        """
+        cwd = os.getcwd()
+        os.chdir(self.workdir)
+        process.run("rpm2cpio %s | cpio -id %s" % (rpm, path), shell=True)
+        os.chdir(cwd)
+        return self.workdir + '/' + path
                                   ^
     Is the extra slash needed? (just because the extract_from_deb()
     doesn't put it)



Yes, I needed to put it in there because the 'path' passed in for
processing by cpio is a relative patch unlike the deb arg so it
couldn't be just appended to 'self.workdir' which doesn't end in a '/'.


It is a good practice use the `os.path` module methods when dealing with filesystem paths. So that can be replaced with:

 >>> os.path.normpath(os.path.join('/path/to/workdir', './file/in/rpm'))
'/path/to/workdir/file/in/rpm'



Will do.  I'll add a patch to fix extract_from_deb() too.

Using the exact same code didn't work with extract_from_deb() because the callers set 'path' to an absolute path (so os.path.join() drops the self.workdir part). I'll include a patch with the following change and it can be dropped if people think using os.path.relpath() is too much of a hack.

--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -49,7 +49,12 @@ class BootLinuxConsole(Test):
         process.run("ar x %s %s" % (deb, file_path))
         archive.extract(file_path, self.workdir)
         os.chdir(cwd)
-        return self.workdir + path
+        # Return complete path to extracted file.  We need to use
+        # os.path.relpath() because callers specify 'path' with a leading
+        # slash which causes os.path.join() to interpret it as an absolute
+        # path and to drop self.workdir part.
+        return os.path.normpath(os.path.join(self.workdir,
+                                             os.path.relpath(path, '/')))

     def extract_from_rpm(self, rpm, path):
         """

Regards,
Liam



reply via email to

[Prev in Thread] Current Thread [Next in Thread]