summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2021-04-27 04:32:57 +0200
committerAllan McRae <allan@archlinux.org>2021-05-01 04:08:14 +0200
commitab622b4881e6b971c62de4323c72c87a6da51323 (patch)
tree1c8fd43a0d5391a129572bf9ceb61232ba8533b8
parente7fa35baa22bf6710a904815456d3ff679005fc7 (diff)
downloadpacman-ab622b4881e6b971c62de4323c72c87a6da51323.tar.gz
pacman-ab622b4881e6b971c62de4323c72c87a6da51323.tar.xz
pmpkg: add makepkg_bytes
Builds the package file in memory. Useful with the built-in server. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
-rw-r--r--test/pacman/pmpkg.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py
index 8ff1ec1e..01ed4e0a 100644
--- a/test/pacman/pmpkg.py
+++ b/test/pacman/pmpkg.py
@@ -98,7 +98,12 @@ class pmpkg(object):
filename, extra = filename.split("|")
return filename
- def makepkg(self, path):
+ def makepkg_bytes(self):
+ buf = BytesIO();
+ self.makepkg(fileobj=buf)
+ return buf.getvalue()
+
+ def makepkg(self, path=None, fileobj=None):
"""Creates an Arch Linux package archive.
A package archive is generated in the location 'path', based on the data
@@ -138,11 +143,12 @@ class pmpkg(object):
if any(self.install.values()):
archive_files.append((".INSTALL", self.installfile()))
- self.path = os.path.join(path, self.filename())
- util.mkdir(os.path.dirname(self.path))
+ if path:
+ self.path = os.path.join(path, self.filename())
+ util.mkdir(os.path.dirname(self.path))
# Generate package metadata
- tar = tarfile.open(self.path, "w:gz", format=tarfile.GNU_FORMAT)
+ tar = tarfile.open(name=self.path, fileobj=fileobj, mode="w:gz", format=tarfile.GNU_FORMAT)
for name, data in archive_files:
info = tarfile.TarInfo(name)
info.size = len(data)