return filename
+class MakeVirtualPackage(VirtualPackage):
+ """
+ A simple package that always overwrites the file_patterns.
+ """
+ @property
+ def file_patterns(self):
+ """
+ All files that belong into a source package are located in /build.
+ """
+ return ["/",]
+
class Makefile(Package):
def __init__(self, pakfire, filename):
Package.__init__(self, pakfire)
We assume that all requires files are in /build.
"""
- basedir = env.chrootPath("build")
-
- files = {
- "data.img" : env.chrootPath("tmp/data.img"),
- "signature" : env.chrootPath("tmp/signature"),
- "info" : env.chrootPath("tmp/info"),
- }
-
- # Package all files.
- a = tarfile.open(files["data.img"], "w")
- for dir, subdirs, _files in os.walk(basedir):
- for file in _files:
- file = os.path.join(dir, file)
-
- a.add(file, arcname=file[len(basedir):])
- a.close()
-
- # XXX add compression for the sources
-
- # Create an empty signature.
- f = open(files["signature"], "w")
- f.close()
-
- pkg = VirtualPackage(self.pakfire, env.make_info)
-
- # Save meta information.
- f = open(files["info"], "w")
- f.write(SOURCE_PACKAGE_META % {
- "PKG_NAME" : pkg.name,
- })
- f.close()
-
- result = env.chrootPath("result", "src", pkg.filename)
- resultdir = os.path.dirname(result)
- if not os.path.exists(resultdir):
- os.makedirs(resultdir)
-
- f = tarfile.open(result, "w")
- for arcname, name in files.items():
- f.add(name, arcname=arcname, recursive=False)
+ pkg = MakeVirtualPackage(self.pakfire, env.make_info)
- f.close()
+ p = packager.SourcePackager(self.pakfire, pkg, env)
+ p()
from file import InnerTarFile
-# XXX this is totally ugly and needs to be done right!
-
class Packager(object):
ARCHIVE_FILES = ("info", "filelist", "data.img")
self.tarball = None
+ self.cleanup = True
+
# Store meta information
self.info = {
"package_format" : PACKAGE_FORMAT,
- "package_type" : "binary",
+ "package_type" : self.type,
"package_uuid" : uuid.uuid4(),
"payload_comp" : None,
+
+ "requires" : "",
+ "provides" : "",
}
self.info.update(self.pkg.info)
self.info.update(self.pakfire.distro.info)
# Create the tarball and add all data to it.
self.create_tarball()
- e = self.env.do("/usr/lib/buildsystem-tools/dependency-tracker %s" % \
- self.tempdir[len(self.env.chrootPath()):], returnOutput=True,
- env=self.pkg.env)
+ if self.type == "binary":
+ e = self.env.do("/usr/lib/buildsystem-tools/dependency-tracker %s" % \
+ self.tempdir[len(self.env.chrootPath()):], returnOutput=True,
+ env=self.pkg.env)
- for line in e.splitlines():
- m = re.match(r"^(\w+)=(.*)$", line)
- if m is None:
- continue
+ for line in e.splitlines():
+ m = re.match(r"^(\w+)=(.*)$", line)
+ if m is None:
+ continue
- key, val = m.groups()
+ key, val = m.groups()
- if not key in ("requires", "provides"):
- continue
+ if not key in ("requires", "provides"):
+ continue
- val = val.strip("\"")
- val = val.split()
+ val = val.strip("\"")
+ val = val.split()
- self.info[key] = " ".join(sorted(val))
+ self.info[key] = " ".join(sorted(val))
self.create_info()
tar.close()
- def create_tarball(self, compress="xz"):
+ def create_tarball(self, compress=None):
tar = InnerTarFile(self.archive_files["data.img"], mode="w")
+ prefix = self.env.buildroot
+ if self.type == "source":
+ prefix = "build"
+
+ if not compress and self.type == "binary":
+ compress = "xz"
+
includes = []
excludes = []
if pattern.startswith("/"):
pattern = pattern[1:]
- pattern = self.env.chrootPath(self.env.buildroot, pattern)
+ pattern = self.env.chrootPath(prefix, pattern)
# Recognize the type of the pattern. Patterns could be a glob
# pattern that is expanded here or just a directory which will
filelist = open(self.archive_files["filelist"], mode="w")
for file_real in files:
- file_tar = file_real[len(self.env.chrootPath(self.env.buildroot)) + 1:]
+ file_tar = file_real[len(self.env.chrootPath(prefix)) + 1:]
file_tmp = os.path.join(self.tempdir, file_tar)
if file_tar in ORPHAN_DIRECTORIES and not os.listdir(file_real):
shutil.copy2(file_real, file_tmp)
# Unlink the file and remove empty directories.
- if not os.path.isdir(file_real):
- os.unlink(file_real)
+ if self.cleanup:
+ if not os.path.isdir(file_real):
+ os.unlink(file_real)
- elif os.path.isdir(file_real) and not os.listdir(file_real):
- os.rmdir(file_real)
+ elif os.path.isdir(file_real) and not os.listdir(file_real):
+ os.rmdir(file_real)
# Dump all files that are in the archive.
tar.list()
f = open(self.archive_files["info"], "w")
f.write(BINARY_PACKAGE_META % self.info)
f.close()
+
+ @property
+ def type(self):
+ raise NotImplementedError
+
+
+class BinaryPackager(Packager):
+ @property
+ def type(self):
+ return "binary"
+
+
+class SourcePackager(Packager):
+ def __init__(self, *args, **kwargs):
+ Packager.__init__(self, *args, **kwargs)
+
+ self.cleanup = False
+
+ @property
+ def type(self):
+ return "source"