From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 0B313138720 for ; Mon, 28 Jan 2013 23:54:20 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 994DE21C0BF; Mon, 28 Jan 2013 23:54:16 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E218921C0BF for ; Mon, 28 Jan 2013 23:54:10 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BD98633DBBF for ; Mon, 28 Jan 2013 23:54:09 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 2D8BAE40A0 for ; Mon, 28 Jan 2013 23:54:06 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1359416224.e30e6406aacc718f49eaa58723465107afa39aa8.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/overlay/pkgdir/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/overlay/pkgdir/packagedir_portagemanifest.py X-VCS-Directories: roverlay/overlay/pkgdir/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: e30e6406aacc718f49eaa58723465107afa39aa8 X-VCS-Branch: master Date: Mon, 28 Jan 2013 23:54:06 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 09232272-d614-435f-b627-0f315b780c04 X-Archives-Hash: 81249ed2612ab2639b308c40a05865eb commit: e30e6406aacc718f49eaa58723465107afa39aa8 Author: André Erdmann mailerd de> AuthorDate: Mon Jan 28 22:43:37 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Mon Jan 28 23:37:04 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=e30e6406 roverlay/overlay/pkgdir: portagemanifest A Manifest file creation that uses the portage python libs directly. This has the following advantages over the "ebuild" implementation: * create more than one Manifest at once (thread safe) * faster file creation time (direct "create Manifest" function call instead of calling an external executable a few thousand times) The downsides are: * highly EXPERIMENTAL (currently) * less stable to changes in portage (written for portage version 2.1.11.31) --- .../overlay/pkgdir/packagedir_portagemanifest.py | 163 ++++++++++++++++++++ 1 files changed, 163 insertions(+), 0 deletions(-) diff --git a/roverlay/overlay/pkgdir/packagedir_portagemanifest.py b/roverlay/overlay/pkgdir/packagedir_portagemanifest.py new file mode 100644 index 0000000..bf9efee --- /dev/null +++ b/roverlay/overlay/pkgdir/packagedir_portagemanifest.py @@ -0,0 +1,163 @@ +__all__ = [ 'PackageDir', ] + +import os +import shlex + +import portage.manifest + +import logging +logging.getLogger ( __name__ ).warning ( "experimental code" ) +del logging + +import roverlay.config +import roverlay.strutil +import roverlay.packageinfo +import roverlay.overlay.pkgdir.packagedir_base +import roverlay.overlay.pkgdir.symlink.distroot + +class PackageDir ( roverlay.overlay.pkgdir.packagedir_base.PackageDirBase ): + + MANIFEST_THREADSAFE = True + + def _scan_add_package ( self, efile, pvr ): + """Called for each ebuild that is found during scan(). + Creates a PackageInfo for the ebuild and adds it to self._packages. + + arguments: + * efile -- full path to the ebuild file + * pvr -- version ($PVR) of the ebuild + """ + + # read SRC_URI from the ebuild file which is the only way to get + # the correct package name + src_uri = None + with open ( efile, 'r' ) as FH: + reader = shlex.shlex ( FH ) + reader.whitespace_split = False + reader.wordchars += ' ,./$()[]:+-@*~<>' + + # assumption: only one SRC_URI= statement per ebuild + # (true for roverlay ebuilds) + mode = 0 + token = reader.get_token() + while token: + if mode == 0 and token == 'SRC_URI': + mode = 1 + elif mode == 1 and token == '=': + mode = 2 + elif mode == 2: + mode = 3 + src_uri = tuple ( + roverlay.strutil.split_whitespace ( + roverlay.strutil.unquote ( token ) + ) + ) + + # break loop if SRC_URI parsed + token = reader.get_token() if mode < 3 else None + # --- while; + del token, reader, mode + # --- with; + + if src_uri: + # another assumption: src_uri [0] is the name of the R package + package_filename = src_uri [0].rpartition ( '/' ) [2] + + p = roverlay.packageinfo.PackageInfo ( + physical_only=True, pvr=pvr, ebuild_file=efile, + package_filename=package_filename + ) + else: + p = roverlay.packageinfo.PackageInfo ( + physical_only=True, pvr=pvr, ebuild_file=efile + ) + + self._packages [ p ['ebuild_verstr'] ] = p + # --- end of _scan_add_package (...) --- + + def write_manifest ( self, ignore_empty=False ): + """Generates and writes the Manifest file for this package. + + expects: called after writing metadata/ebuilds + + returns: success (True/False) + + raises: + * Exception if no ebuild exists + """ + + # the "package_filename" key is also required + pkgs_for_manifest = frozenset ( + p for p in self._packages.values() + if p.has ( 'ebuild_filename', 'package_file' ) + ) + + # TODO: this needs proper testing + # * the written Manifest file must not differ from the one generated by + # ebuild(1) (the order of the entries is not important, though) + # * safe for incremental usage? + # * correct usage of the portage libs (also see other comments below) + # * what happens if an ebuild has been removed? + # * ... + # + if pkgs_for_manifest: + symlink_distdir = roverlay.overlay.pkgdir.symlink.distroot.\ + SymlinkDistroot.get_configured().get ( self.name ) + + # allow_missing=True -- don't write empty Manifest files + manifest = portage.manifest.Manifest ( + self.physical_location, + str ( symlink_distdir ), + allow_missing=True, + ) + + # metadata.xml + # os.path.basename ( self._metadata.filepath ) + manifest.addFile ( 'MISC', 'metadata.xml' ) + + for p in pkgs_for_manifest: + ebuild_filename = p ['ebuild_filename'] + package_filename = p ['package_filename'] + + if not manifest.hasFile ( 'EBUILD', ebuild_filename ): + manifest.addFile ( 'EBUILD', ebuild_filename ) + + if not manifest.hasFile ( 'DIST', package_filename ): + symlink_distdir.add ( p ['package_file'], package_filename ) + manifest.addFile ( + 'DIST', + package_filename, + # TODO: + # ignoreMissing for DIST files, else addFile raises + # FileNotFound -- is this the correct way to add DIST files? + ignoreMissing=True + ) + + # ??? FIXME: (read) portage api docs + # + # manifest.create -- recreate from scratch (required?) + # -> assumeDistHashesSometimes: + # use existing checksums for non-existent DIST files (required?) + # + #manifest.create ( assumeDistHashesSometimes=True ) + #manifest.create ( assumeDistHashesSometimes=False ) + + manifest.write() + self._need_manifest = False + + return True + + elif ignore_empty: + + return True + + else: + raise Exception ( + 'In {mydir}: No ebuild written so far! ' + 'I really don\'t know what do to!'.format ( + mydir=self.physical_location + ) ) + + # @unreachable + return False + # --- end of write_manifest (...) ---