Example #1
0
	def create_filelist(self, datafile):
		filelist = self.mktemp()

		f = open(filelist, "w")

		if self.payload_compression == "xz":
			datafile = tar.InnerTarFileXz.open(datafile)
		else:
			datafile = tar.InnerTarFile.open(datafile)

		while True:
			m = datafile.next()
			if not m:
				break

			log.debug("  %s %-8s %-8s %s %6s %s" % \
				(tarfile.filemode(m.mode), m.uname, m.gname,
				"%d-%02d-%02d %02d:%02d:%02d" % time.localtime(m.mtime)[:6],
				util.format_size(m.size), m.name))

			f.write("%(type)1s %(size)-10d %(uname)-10s %(gname)-10s %(mode)-6d %(mtime)-12d" \
				% m.get_info(tarfile.ENCODING, "strict"))

			# Calculate SHA512 hash of regular files.
			if m.isreg():
				mobj = datafile.extractfile(m)
				h = hashlib.new("sha512")

				while True:
					buf = mobj.read(BUFFER_SIZE)
					if not buf:
						break
					h.update(buf)

				mobj.close()
				f.write(" %s" % h.hexdigest())
			else:
				f.write(" -")

			caps = m.pax_headers.get("PAKFIRE.capabilities", None)
			if caps:
				f.write(" %s" % caps)
			else:
				f.write(" -")

			# The file name must be the last argument to contain spaces.
			f.write(" %s" % m.name)

			f.write("\n")

		log.info("")

		datafile.close()
		f.close()

		return filelist
Example #2
0
	def dump(self, short=False, long=False, filelist=False):
		if short:
			return "%s.%s : %s" % (self.name, self.arch, self.summary)

		items = [
			(_("Name"), self.name),
		]

		# Show supported arches if available.
		if hasattr(self, "supported_arches") and not self.supported_arches == "all":
			arch = "%s (%s)" % (self.arch, self.supported_arches)
		else:
			arch = self.arch
		items.append((_("Arch"), arch))

		items += [
			(_("Version"), self.version),
			(_("Release"), self.release),
		]

		if self.size:
			items.append((_("Size"), util.format_size(self.size)))

		if self.inst_size:
			items.append(
				(_("Installed size"),
				util.format_size(self.inst_size))
			)

		# filter dummy repository
		if not self.repo == self.pakfire.repos.dummy:
			items.append((_("Repo"), self.repo.name))

		items += [
			(_("Summary"), self.summary),
			(_("Groups"), " ".join(self.groups)),
			(_("URL"), self.url),
			(_("License"), self.license),
		]

		caption = _("Description")
		for line in util.text_wrap(self.description):
			items.append((caption, line))
			caption = ""

		if long:
			if self.maintainer:
				items.append((_("Maintainer"), self.maintainer))

			items.append((_("Vendor"), self.vendor))

			items.append((_("UUID"), self.uuid))
			items.append((_("Build ID"), self.build_id))
			items.append((_("Build date"), self.build_date))
			items.append((_("Build host"), self.build_host))

			caption = _("Signatures")
			for sig in self.signatures:
				items.append((caption, sig))
				caption = ""

			caption = _("Provides")
			for prov in sorted(self.provides):
				items.append((caption, prov))
				caption = ""

			caption = _("Pre-requires")
			for req in sorted(self.prerequires):
				items.append((caption, req))
				caption = ""

			caption = _("Requires")
			for req in sorted(self.requires):
				items.append((caption, req))
				caption = ""

			caption = _("Conflicts")
			for req in sorted(self.conflicts):
				items.append((caption, req))
				caption = ""

			caption = _("Obsoletes")
			for req in sorted(self.obsoletes):
				items.append((caption, req))
				caption = ""

			caption = _("Recommends")
			for req in sorted(self.recommends):
				items.append((caption, req))
				caption = ""

			caption = _("Suggests")
			for req in sorted(self.suggests):
				items.append((caption, req))
				caption = ""

		# Append filelist if requested.
		if filelist:
			for file in self.filelist:
				items.append((_("File"), file))

		format = "%%-%ds : %%s" % (max([len(k) for k, v in items]))

		s = []
		for caption, value in items:
			s.append(format % (caption, value))

		s.append("") # New line at the end

		# XXX why do we need to decode this?
		return "\n".join([str.decode("utf-8") for str in s])