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>
This commit is contained in:
parent
e7fa35baa2
commit
ab622b4881
1 changed files with 10 additions and 4 deletions
|
@ -98,7 +98,12 @@ class pmpkg(object):
|
||||||
filename, extra = filename.split("|")
|
filename, extra = filename.split("|")
|
||||||
return filename
|
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.
|
"""Creates an Arch Linux package archive.
|
||||||
|
|
||||||
A package archive is generated in the location 'path', based on the data
|
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()):
|
if any(self.install.values()):
|
||||||
archive_files.append((".INSTALL", self.installfile()))
|
archive_files.append((".INSTALL", self.installfile()))
|
||||||
|
|
||||||
self.path = os.path.join(path, self.filename())
|
if path:
|
||||||
util.mkdir(os.path.dirname(self.path))
|
self.path = os.path.join(path, self.filename())
|
||||||
|
util.mkdir(os.path.dirname(self.path))
|
||||||
|
|
||||||
# Generate package metadata
|
# 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:
|
for name, data in archive_files:
|
||||||
info = tarfile.TarInfo(name)
|
info = tarfile.TarInfo(name)
|
||||||
info.size = len(data)
|
info.size = len(data)
|
||||||
|
|
Loading…
Add table
Reference in a new issue