From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1NwZQ0-0008V5-2c for garchives@archives.gentoo.org; Tue, 30 Mar 2010 11:15:37 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6D092E0BE6; Tue, 30 Mar 2010 11:15:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id EBCDEE0BE6 for ; Tue, 30 Mar 2010 11:15:34 +0000 (UTC) Received: from stork.gentoo.org (stork.gentoo.org [64.127.104.133]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTP id 81C391B405F for ; Tue, 30 Mar 2010 11:15:34 +0000 (UTC) Received: from idl0r by stork.gentoo.org with local (Exim 4.69) (envelope-from ) id 1NwZPy-0006st-1w for gentoo-commits@lists.gentoo.org; Tue, 30 Mar 2010 11:15:34 +0000 To: gentoo-commits@lists.gentoo.org From: "Christian Ruppert (idl0r)" Subject: [gentoo-commits] gentoolkit r761 - in tags: . gentoolkit-dev-0.2.6.14/src/imlate X-VCS-Repository: gentoolkit X-VCS-Revision: 761 X-VCS-Files: tags/gentoolkit-dev-0.2.6.14/ tags/gentoolkit-dev-0.2.6.14/src/imlate/imlate tags/gentoolkit-dev-0.2.6.14/src/imlate/imlate X-VCS-Directories: . gentoolkit-dev-0.2.6.14/src/imlate X-VCS-Committer: idl0r X-VCS-Committer-Name: Christian Ruppert Content-Type: text/plain; charset=UTF-8 Message-Id: Sender: Christian Ruppert Date: Tue, 30 Mar 2010 11:15:34 +0000 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 47a2c22b-5bc9-45e8-9e5f-c301ba52272b X-Archives-Hash: a03c3c586300f06e6db1bef324dbb79d Author: idl0r Date: 2010-03-30 11:15:33 +0000 (Tue, 30 Mar 2010) New Revision: 761 Added: tags/gentoolkit-dev-0.2.6.14/ tags/gentoolkit-dev-0.2.6.14/src/imlate/imlate Removed: tags/gentoolkit-dev-0.2.6.14/src/imlate/imlate Log: Tagging the gentoolkit-dev-0.2.6.14 release Deleted: tags/gentoolkit-dev-0.2.6.14/src/imlate/imlate =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/gentoolkit-dev/src/imlate/imlate 2010-03-28 21:45:22 UTC (rev 7= 59) +++ tags/gentoolkit-dev-0.2.6.14/src/imlate/imlate 2010-03-30 11:15:33 UT= C (rev 761) @@ -1,477 +0,0 @@ -#!/usr/bin/python -# Copyright 1999-2010 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# $Id: $ -# Author: Christian Ruppert - -# Python 2.6 compatibility -from __future__ import print_function - -VERSION =3D "1.0.0" - -# works just with stable keywords! -MAIN_ARCH =3D "auto" # can be overridden by -m ARCH -TARGET_ARCH =3D "auto" # can be overridden by -t ARCH -# auto means e.g.: -# MAIN_ARCH =3D amd64 -# TARGET_ARCH =3D ~amd64 -# That will show you general stable candidates for amd64. -# The arch will be taken from your portage settings (e.g. make.conf). - -################################ -# do not change anything below # -################################ - -from os.path import join, basename -from sys import stderr, stdout -from os import stat -from time import time -from xml.dom import minidom, NotFoundErr -from xml.parsers.expat import ExpatError -# TODO: just import needed stuff to safe memory/time and maybe use "as f= oo" -import portage -import portage.versions - -if __name__ =3D=3D "__main__": - from optparse import OptionParser - from time import gmtime, strftime - -# override/change portage module settings -def _portage_settings( var, value, settings =3D None ): - if not settings: - settings =3D portage.settings - - settings.unlock() - settings[var] =3D value - # backup_changes is very important since it can cause trouble, - # if we do not backup our changes! - settings.backup_changes( var ) - settings.lock() - -# add stuff to our imlate dict -def _add_ent( imlate, cat, pkg, ver, our_ver ): - if not cat in list(imlate.keys()): - imlate[cat] =3D {} - if not pkg in list(imlate[cat].keys()): - imlate[cat][pkg] =3D [] - - imlate[cat][pkg].append( ver ) - imlate[cat][pkg].append( our_ver ) - - return imlate - -def _fill( width, line, fill =3D " " ): - while len( line ) < width: - line =3D "%s%s" % ( str( line ), str( fill ) ) - return line - -# create a hopefully pretty result -def show_result( conf, pkgs ): - # X - len(colX) =3D space to fill - col1 =3D 40 - col2 =3D 20 - - _header =3D "%s candidates for 'gentoo' on '%s'" - _helper =3D "category/package[:SLOT] our version = best version" - _cand =3D "" - header =3D "" - - if conf["FILE"] =3D=3D "stdout": - out =3D stdout - elif conf["FILE"] =3D=3D "stderr": - out =3D stderr - else: - out =3D open( conf["FILE"], "w" ) - - if conf["STABLE"] and conf["KEYWORD"]: - _cand =3D "%i Stable and %i Keyword(~)" % ( conf["STABLE_SUM"], - conf["KEYWORD_SUM"] ) - elif conf["STABLE"]: - _cand =3D "%i Stable" % conf["STABLE_SUM"] - elif conf["KEYWORD"]: - _cand =3D "%i Keyword(~)" % conf["KEYWORD_SUM"] - - header =3D _header % ( _cand, conf["MAIN_ARCH"] ) - - print("Generated on: %s" % conf["TIME"], file=3Dout) - print(_fill( len( header ), "", "=3D" ), file=3Dout) - print(header, file=3Dout) - print(_fill( len( header ), "", "=3D" ), file=3Dout) - print(file=3Dout) - - print(_helper, file=3Dout) - print(_fill( len( _helper ), "", "-" ), file=3Dout) - - for cat in sorted( pkgs.keys() ): - print("%s/" % cat, file=3Dout) - for pkg in sorted( pkgs[cat].keys() ): - print("%s%s%s" % ( _fill( col1, ( " %s" % pkg ) ), - _fill( col2, pkgs[cat][pkg][1] ), - pkgs[cat][pkg][0] ), file=3Dout) - - if conf["FILE"] !=3D "stdout": - out.close() - -def _get_metadata(metadata, element, tag): - values =3D [] - - try: - metadatadom =3D minidom.parse(metadata) - except ExpatError as e: - raise ExpatError("%s: %s" % (metadata, e,)) - - try: - elements =3D metadatadom.getElementsByTagName(element) - if not elements: - return values - except NotFoundErr: - return values - - try: - for _element in elements: - node =3D _element.getElementsByTagName(tag) - - if tag =3D=3D "herd" and (not node or not node[0].childNodes): -# print >> stderr, "'%s' is missing a tag or it is empty," % m= etadata -# print >> stderr, "please file a bug at https://bugs.gentoo.org and = refer to http://www.gentoo.org/proj/en/devrel/handbook/handbook.xml?part=3D= 2&chap=3D4" - values.append("no-herd") - continue - - values.append(node[0].childNodes[0].data) - except NotFoundErr: - raise NotFoundErr("%s: Malformed input: missing 'flag' tag(s)" % (meta= data)) - - metadatadom.unlink() - return values - -def is_maintainer(maintainer, metadata): - data =3D [] - - if maintainer =3D=3D None: - return True - - mtainer =3D maintainer.split(",") - - data =3D _get_metadata(metadata, "maintainer", "email") - - if not data and len(maintainer) =3D=3D 0: - return True - elif not data and len(maintainer) > 0: - return False - else: - for addy in data: - for contact in mtainer: - if addy =3D=3D contact: - return True - if addy.startswith(contact): - return True - return False - -def is_herd(herd, metadata): - data =3D [] - - if herd =3D=3D None: - return True - - hrd =3D herd.split(",") - data =3D _get_metadata(metadata, "pkgmetadata", "herd") - - if not data and len(herd) =3D=3D 0: - return True - elif not data and len(herd) > 0: - return False - else: - for hd in data: - for hd2 in hrd: - if hd =3D=3D hd2: - return True - if hd.startswith(hd2): - return True -=09 - return False - - -# fetch a list of arch (just stable) packages -# -* is important to be sure that just arch is used -def get_packages( conf ): - _pkgs =3D {} - - _portage_settings( "ACCEPT_KEYWORDS", ( "-* %s" % str( conf["TARGET_ARC= H"] ) ), - conf["portdb"].settings ) - - for cp in conf["portdb"].dbapi.cp_all(): - cpvrs =3D [] - slots =3D {} - - if conf["USER_PKGS"]: - if not cp in conf["USER_PKGS"]: - continue - - # None is important to match also on empty string - if conf["MAINTAINER"] !=3D None: - if not is_maintainer(conf["MAINTAINER"], join(conf["PORTDIR"], cp, "m= etadata.xml")): - continue - if conf["HERD"] !=3D None: - if not is_herd(conf["HERD"], join(conf["PORTDIR"], cp, "metadata.xml"= )): - continue - - cpvrs =3D conf["portdb"].dbapi.match( cp ) - - for cpvr in cpvrs: - slot =3D conf["portdb"].dbapi.aux_get( cpvr, ["SLOT"] )[0] - if not slot in slots: - slots[slot] =3D [] - slots[slot].append(cpvr) - =09 - for slot in sorted(slots): - cpvr =3D portage.versions.best( slots[slot] ) - - if cpvr: - ( cat, pkg, ver, rev ) =3D portage.versions.catpkgsplit( cpvr ) - - if not cat in list(_pkgs.keys()): - _pkgs[cat] =3D {} - if not pkg in list(_pkgs[cat].keys()): - _pkgs[cat][pkg] =3D [] - - if rev !=3D "r0": - ver =3D "%s-%s" % ( ver, rev ) - - _pkgs[cat][pkg].append( ver ) - - return _pkgs - -# compare get_packages() against MAIN_ARCH -def get_imlate( conf, pkgs ): - _portage_settings( "ACCEPT_KEYWORDS", ( "-* %s" % str( conf["MAIN_ARCH"= ] ) ), - conf["portdb"].settings ) - - stable =3D str( conf["MAIN_ARCH"].lstrip("~") ) - testing =3D "~%s" % stable - exclude =3D "-%s" % stable - exclude_all =3D "-*" - - imlate =3D {} - - for cat in sorted( pkgs.keys() ): - for pkg in sorted( pkgs[cat].keys() ): - for vr in pkgs[cat][pkg]: - cpvr =3D "" - abs_pkg =3D "" - kwds =3D "" - our =3D "" - our_ver =3D "" - mtime =3D 0 - slot =3D 0 -=09 - # 0 =3D none(default), 1 =3D testing(~arch), 2 =3D stable(arch), - # 3 =3D exclude(-arch), 4 =3D exclude_all(-*) - # -* would be overridden by ~arch or arch - kwd_type =3D 0 - - cpvr =3D "%s/%s-%s" % ( cat, pkg, vr ) -=09 - # absolute ebuild path for mtime check - abs_pkg =3D join( conf["PORTDIR"], cat, pkg, basename( cpvr ) ) - abs_pkg =3D "%s.ebuild" % str( abs_pkg ) -=09 - kwds =3D conf["portdb"].dbapi.aux_get( cpvr, ["KEYWORDS"] )[0] -=09 - # FIXME: %s is bad.. maybe even cast it, else there are issues becau= se its unicode - slot =3D ":%s" % conf["portdb"].dbapi.aux_get( cpvr, ["SLOT"] )[0] - if slot =3D=3D ":0": - slot =3D "" -=09 - # sorted() to keep the right order - # e.g. -* first, -arch second, arch third and ~arch fourth - # -* -foo ~arch - # example: -* would be overridden by ~arch - for kwd in sorted( kwds.split() ): - if kwd =3D=3D stable: - kwd_type =3D 2 - break - elif kwd =3D=3D exclude: - kwd_type =3D 3 - break - elif kwd =3D=3D exclude_all: - kwd_type =3D 4 - elif kwd =3D=3D testing: - kwd_type =3D 1 - break -=09 - # ignore -arch and already stabilized packages - if kwd_type =3D=3D 3 or kwd_type =3D=3D 2: - continue - # drop packages with -* and without ~arch or arch - # even if there is another version which includes arch or ~arch - if kwd_type =3D=3D 4: - continue - # drop "stable candidates" with mtime < 30 days - # Shall we use gmtime/UTC here? - if kwd_type =3D=3D 1: - mtime =3D int( ( time() - stat( abs_pkg ).st_mtime ) / 60 / 60 / 24= ) - if mtime < conf["MTIME"]: - continue -=09 - # look for an existing stable version - our =3D portage.versions.best( conf["portdb"].dbapi.match( "%s/%s%s"= % ( cat, pkg, slot ) ) ) - if our: - _foo =3D portage.versions.pkgsplit( our ) - our_ver =3D _foo[1] - if _foo[2] !=3D "r0": - our_ver =3D "%s-%s" % ( our_ver, _foo[2] ) - else: - our_ver =3D "" -=09 - # we just need the version if > our_ver - if our_ver: - if portage.versions.vercmp( our_ver, vr ) >=3D 0: - continue -=09 - if kwd_type =3D=3D 1 and conf["STABLE"]: - imlate =3D _add_ent( imlate, cat, ("%s%s" % (pkg, slot)), vr, our_v= er ) - conf["STABLE_SUM"] +=3D 1 - elif kwd_type =3D=3D 0 and conf["KEYWORD"]: - conf["KEYWORD_SUM"] +=3D 1 - imlate =3D _add_ent( imlate, cat, ( "~%s%s" % (pkg, slot) ), - vr, our_ver ) - - return imlate - -# fetch portage related settings -def get_settings( conf =3D None ): - if not isinstance( conf, dict ) and conf: - raise TypeError("conf must be dict() or None") - if not conf: - conf =3D {} - - # TODO: maybe we should improve it a bit ;) - mysettings =3D portage.config( config_incrementals =3D portage.const.IN= CREMENTALS, local_config =3D False ) - - if conf["MAIN_ARCH"] =3D=3D "auto": - conf["MAIN_ARCH"] =3D "%s" % mysettings["ACCEPT_KEYWORDS"].split(" ")[= 0].lstrip("~") - if conf["TARGET_ARCH"] =3D=3D "auto": - conf["TARGET_ARCH"] =3D "~%s" % mysettings["ACCEPT_KEYWORDS"].split(" = ")[0].lstrip("~") - - # TODO: exclude overlay categories from check - if conf["CATEGORIES"]: - _mycats =3D [] - for _cat in conf["CATEGORIES"].split(","): - _cat =3D _cat.strip() - _mycats.append(_cat ) - if _cat not in mysettings.categories: - raise ValueError("invalid category for -C switch '%s'" % _cat) - mysettings.categories =3D _mycats - - # maybe thats not necessary because we override porttrees below.. - _portage_settings( "PORTDIR_OVERLAY", "", mysettings ) - trees =3D portage.create_trees() - trees["/"]["porttree"].settings =3D mysettings - portdb =3D trees["/"]["porttree"] - portdb.dbapi.settings =3D mysettings - portdb.dbapi.porttrees =3D [portage.portdb.porttree_root] - # does it make sense to remove _all_ useless stuff or just leave it as = it is? - #portdb.dbapi._aux_cache_keys.clear() - #portdb.dbapi._aux_cache_keys.update(["EAPI", "KEYWORDS", "SLOT"]) - - conf["PORTDIR"] =3D portage.settings["PORTDIR"] - conf["portdb"] =3D portdb - - return conf - - -# just for standalone -def main(): - conf =3D {} - pkgs =3D {} - - parser =3D OptionParser( version =3D "%prog " + VERSION ) - parser.usage =3D "%prog [options] [category/package] ..." - parser.disable_interspersed_args() - - parser.add_option( "-f", "--file", dest =3D "filename", action =3D "sto= re", type =3D "string", - help =3D "write result into FILE [default: %default]", metavar =3D "F= ILE", default =3D "stdout" ) - parser.add_option( "-m", "--main", dest =3D "main_arch", action =3D "st= ore", type =3D "string", - help =3D "set main ARCH (e.g. your arch) [default: %default]", metava= r =3D "ARCH", default =3D MAIN_ARCH ) - parser.add_option( "-t", "--target", dest =3D "target_arch", action =3D= "store", type =3D "string", - help =3D "set target ARCH (e.g. x86) [default: %default]", metavar =3D= "ARCH", default =3D TARGET_ARCH ) - parser.add_option( "--mtime", dest =3D "mtime", action =3D "store", typ= e =3D "int", - help =3D "set minimum MTIME in days [default: %default]", metavar =3D= "MTIME", default =3D 30 ) - - # TODO: leave a good comment here (about True/False) :) - parser.add_option( "-s", "--stable", dest =3D "stable", action =3D "sto= re_true", default =3D False, - help =3D "just show stable candidates (e.g. -s and -k is the default = result) [default: True]" ) - parser.add_option( "-k", "--keyword", dest =3D "keyword", action =3D "s= tore_true", default =3D False, - help =3D "just show keyword candidates (e.g. -s and -k is the default= result) [default: True]" ) - - parser.add_option( "-M", "--maintainer", dest =3D "maintainer", action = =3D "store", type =3D "string", - help =3D "Show only packages from the specified maintainer", metavar = =3D "MAINTAINER", default =3D None) - - parser.add_option( "-H", "--herd", dest =3D "herd", action =3D "store",= type =3D "string", - help =3D "Show only packages from the specified herd", metavar =3D "H= ERD", default =3D None) - -# # EXPERIMENTAL -# parser.add_option( "-e", "--experimental", dest =3D "experimental", ac= tion =3D "store_true", default =3D False, -# help =3D "enables experimental functions/features (have a look for #= EXPERIMENTAL comments in the source) [default: %default]" ) - - parser.add_option( "-C", "--category", "--categories", dest =3D "catego= ries", action =3D "store", default =3D None, - metavar =3D "CATEGORIES", - help =3D "just check in the specified category/categories (comma sepa= rated) [default: %default]") - - ( options, args ) =3D parser.parse_args() - - if len( args ) > 0: - conf["USER_PKGS"] =3D args - else: - conf["USER_PKGS"] =3D [] - - # cleanup optparse - try: - parser.destroy() - except AttributeError: - # to be at least python 2.4 compatible - del parser._short_opt - del parser._long_opt - del parser.defaults - - # generated timestamp (UTC) - conf["TIME"] =3D strftime( "%a %b %d %H:%M:%S %Z %Y", gmtime() ) - - # package counter - conf["KEYWORD_SUM"] =3D 0 - conf["STABLE_SUM"] =3D 0 - - if not options.main_arch in portage.archlist and options.main_arch !=3D= "auto": - raise ValueError("invalid MAIN ARCH defined!") - if not options.target_arch in portage.archlist and options.target_arch = !=3D "auto": - raise ValueError("invalid TARGET ARCH defined!") - - conf["MAIN_ARCH"] =3D options.main_arch - conf["TARGET_ARCH"] =3D options.target_arch - - conf["FILE"] =3D options.filename - conf["MTIME"] =3D options.mtime - - if not options.stable and not options.keyword: - conf["STABLE"] =3D True - conf["KEYWORD"] =3D True - else: - conf["STABLE"] =3D options.stable - conf["KEYWORD"] =3D options.keyword - -# conf["EXPERIMENTAL"] =3D options.experimental - conf["CATEGORIES"] =3D options.categories - - conf["MAINTAINER"] =3D options.maintainer - conf["HERD"] =3D options.herd - - # append to our existing - conf =3D get_settings( conf ) - pkgs =3D get_packages( conf ) - pkgs =3D get_imlate( conf, pkgs ) - - show_result( conf, pkgs ) - -if __name__ =3D=3D "__main__": - main() - Copied: tags/gentoolkit-dev-0.2.6.14/src/imlate/imlate (from rev 760, tru= nk/gentoolkit-dev/src/imlate/imlate) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- tags/gentoolkit-dev-0.2.6.14/src/imlate/imlate = (rev 0) +++ tags/gentoolkit-dev-0.2.6.14/src/imlate/imlate 2010-03-30 11:15:33 UT= C (rev 761) @@ -0,0 +1,477 @@ +#!/usr/bin/python +# Copyright 1999-2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ +# Author: Christian Ruppert + +# Python 2.6 compatibility +from __future__ import print_function + +VERSION =3D "1.0.0" + +# works just with stable keywords! +MAIN_ARCH =3D "auto" # can be overridden by -m ARCH +TARGET_ARCH =3D "auto" # can be overridden by -t ARCH +# auto means e.g.: +# MAIN_ARCH =3D amd64 +# TARGET_ARCH =3D ~amd64 +# That will show you general stable candidates for amd64. +# The arch will be taken from your portage settings (e.g. make.conf). + +################################ +# do not change anything below # +################################ + +from os.path import join, basename +from sys import stderr, stdout +from os import stat +from time import time +from xml.dom import minidom, NotFoundErr +from xml.parsers.expat import ExpatError +# TODO: just import needed stuff to safe memory/time and maybe use "as f= oo" +import portage +import portage.versions + +if __name__ =3D=3D "__main__": + from optparse import OptionParser + from time import gmtime, strftime + +# override/change portage module settings +def _portage_settings( var, value, settings =3D None ): + if not settings: + settings =3D portage.settings + + settings.unlock() + settings[var] =3D value + # backup_changes is very important since it can cause trouble, + # if we do not backup our changes! + settings.backup_changes( var ) + settings.lock() + +# add stuff to our imlate dict +def _add_ent( imlate, cat, pkg, ver, our_ver ): + if not cat in list(imlate.keys()): + imlate[cat] =3D {} + if not pkg in list(imlate[cat].keys()): + imlate[cat][pkg] =3D [] + + imlate[cat][pkg].append( ver ) + imlate[cat][pkg].append( our_ver ) + + return imlate + +def _fill( width, line, fill =3D " " ): + while len( line ) < width: + line =3D "%s%s" % ( str( line ), str( fill ) ) + return line + +# create a hopefully pretty result +def show_result( conf, pkgs ): + # X - len(colX) =3D space to fill + col1 =3D 40 + col2 =3D 20 + + _header =3D "%s candidates for 'gentoo' on '%s'" + _helper =3D "category/package[:SLOT] our version = best version" + _cand =3D "" + header =3D "" + + if conf["FILE"] =3D=3D "stdout": + out =3D stdout + elif conf["FILE"] =3D=3D "stderr": + out =3D stderr + else: + out =3D open( conf["FILE"], "w" ) + + if conf["STABLE"] and conf["KEYWORD"]: + _cand =3D "%i Stable and %i Keyword(~)" % ( conf["STABLE_SUM"], + conf["KEYWORD_SUM"] ) + elif conf["STABLE"]: + _cand =3D "%i Stable" % conf["STABLE_SUM"] + elif conf["KEYWORD"]: + _cand =3D "%i Keyword(~)" % conf["KEYWORD_SUM"] + + header =3D _header % ( _cand, conf["MAIN_ARCH"] ) + + print("Generated on: %s" % conf["TIME"], file=3Dout) + print(_fill( len( header ), "", "=3D" ), file=3Dout) + print(header, file=3Dout) + print(_fill( len( header ), "", "=3D" ), file=3Dout) + print(file=3Dout) + + print(_helper, file=3Dout) + print(_fill( len( _helper ), "", "-" ), file=3Dout) + + for cat in sorted( pkgs.keys() ): + print("%s/" % cat, file=3Dout) + for pkg in sorted( pkgs[cat].keys() ): + print("%s%s%s" % ( _fill( col1, ( " %s" % pkg ) ), + _fill( col2, pkgs[cat][pkg][1] ), + pkgs[cat][pkg][0] ), file=3Dout) + + if conf["FILE"] !=3D "stdout": + out.close() + +def _get_metadata(metadata, element, tag): + values =3D [] + + try: + metadatadom =3D minidom.parse(metadata) + except ExpatError as e: + raise ExpatError("%s: %s" % (metadata, e,)) + + try: + elements =3D metadatadom.getElementsByTagName(element) + if not elements: + return values + except NotFoundErr: + return values + + try: + for _element in elements: + node =3D _element.getElementsByTagName(tag) + + if tag =3D=3D "herd" and (not node or not node[0].childNodes): +# print >> stderr, "'%s' is missing a tag or it is empty," % m= etadata +# print >> stderr, "please file a bug at https://bugs.gentoo.org and = refer to http://www.gentoo.org/proj/en/devrel/handbook/handbook.xml?part=3D= 2&chap=3D4" + values.append("no-herd") + continue + + values.append(node[0].childNodes[0].data) + except NotFoundErr: + raise NotFoundErr("%s: Malformed input: missing 'flag' tag(s)" % (meta= data)) + + metadatadom.unlink() + return values + +def is_maintainer(maintainer, metadata): + data =3D [] + + if maintainer =3D=3D None: + return True + + mtainer =3D maintainer.split(",") + + data =3D _get_metadata(metadata, "maintainer", "email") + + if not data and len(maintainer) =3D=3D 0: + return True + elif not data and len(maintainer) > 0: + return False + else: + for addy in data: + for contact in mtainer: + if addy =3D=3D contact: + return True + if addy.startswith(contact): + return True + return False + +def is_herd(herd, metadata): + data =3D [] + + if herd =3D=3D None: + return True + + hrd =3D herd.split(",") + data =3D _get_metadata(metadata, "pkgmetadata", "herd") + + if not data and len(herd) =3D=3D 0: + return True + elif not data and len(herd) > 0: + return False + else: + for hd in data: + for hd2 in hrd: + if hd =3D=3D hd2: + return True + if hd.startswith(hd2): + return True +=09 + return False + + +# fetch a list of arch (just stable) packages +# -* is important to be sure that just arch is used +def get_packages( conf ): + _pkgs =3D {} + + _portage_settings( "ACCEPT_KEYWORDS", ( "-* %s" % str( conf["TARGET_ARC= H"] ) ), + conf["portdb"].settings ) + + for cp in conf["portdb"].dbapi.cp_all(): + cpvrs =3D [] + slots =3D {} + + if conf["USER_PKGS"]: + if not cp in conf["USER_PKGS"]: + continue + + # None is important to match also on empty string + if conf["MAINTAINER"] !=3D None: + if not is_maintainer(conf["MAINTAINER"], join(conf["PORTDIR"], cp, "m= etadata.xml")): + continue + if conf["HERD"] !=3D None: + if not is_herd(conf["HERD"], join(conf["PORTDIR"], cp, "metadata.xml"= )): + continue + + cpvrs =3D conf["portdb"].dbapi.match( cp ) + + for cpvr in cpvrs: + slot =3D conf["portdb"].dbapi.aux_get( cpvr, ["SLOT"] )[0] + if not slot in slots: + slots[slot] =3D [] + slots[slot].append(cpvr) + =09 + for slot in sorted(slots): + cpvr =3D portage.versions.best( slots[slot] ) + + if cpvr: + ( cat, pkg, ver, rev ) =3D portage.versions.catpkgsplit( cpvr ) + + if not cat in list(_pkgs.keys()): + _pkgs[cat] =3D {} + if not pkg in list(_pkgs[cat].keys()): + _pkgs[cat][pkg] =3D [] + + if rev !=3D "r0": + ver =3D "%s-%s" % ( ver, rev ) + + _pkgs[cat][pkg].append( ver ) + + return _pkgs + +# compare get_packages() against MAIN_ARCH +def get_imlate( conf, pkgs ): + _portage_settings( "ACCEPT_KEYWORDS", ( "-* %s" % str( conf["MAIN_ARCH"= ] ) ), + conf["portdb"].settings ) + + stable =3D str( conf["MAIN_ARCH"].lstrip("~") ) + testing =3D "~%s" % stable + exclude =3D "-%s" % stable + exclude_all =3D "-*" + + imlate =3D {} + + for cat in sorted( pkgs.keys() ): + for pkg in sorted( pkgs[cat].keys() ): + for vr in pkgs[cat][pkg]: + cpvr =3D "" + abs_pkg =3D "" + kwds =3D "" + our =3D "" + our_ver =3D "" + mtime =3D 0 + slot =3D 0 +=09 + # 0 =3D none(default), 1 =3D testing(~arch), 2 =3D stable(arch), + # 3 =3D exclude(-arch), 4 =3D exclude_all(-*) + # -* would be overridden by ~arch or arch + kwd_type =3D 0 + + cpvr =3D "%s/%s-%s" % ( cat, pkg, vr ) +=09 + # absolute ebuild path for mtime check + abs_pkg =3D join( conf["PORTDIR"], cat, pkg, basename( cpvr ) ) + abs_pkg =3D "%s.ebuild" % str( abs_pkg ) +=09 + kwds =3D conf["portdb"].dbapi.aux_get( cpvr, ["KEYWORDS"] )[0] +=09 + # FIXME: %s is bad.. maybe even cast it, else there are issues becau= se its unicode + slot =3D ":%s" % conf["portdb"].dbapi.aux_get( cpvr, ["SLOT"] )[0] + if slot =3D=3D ":0": + slot =3D "" +=09 + # sorted() to keep the right order + # e.g. -* first, -arch second, arch third and ~arch fourth + # -* -foo ~arch + # example: -* would be overridden by ~arch + for kwd in sorted( kwds.split() ): + if kwd =3D=3D stable: + kwd_type =3D 2 + break + elif kwd =3D=3D exclude: + kwd_type =3D 3 + break + elif kwd =3D=3D exclude_all: + kwd_type =3D 4 + elif kwd =3D=3D testing: + kwd_type =3D 1 + break +=09 + # ignore -arch and already stabilized packages + if kwd_type =3D=3D 3 or kwd_type =3D=3D 2: + continue + # drop packages with -* and without ~arch or arch + # even if there is another version which includes arch or ~arch + if kwd_type =3D=3D 4: + continue + # drop "stable candidates" with mtime < 30 days + # Shall we use gmtime/UTC here? + if kwd_type =3D=3D 1: + mtime =3D int( ( time() - stat( abs_pkg ).st_mtime ) / 60 / 60 / 24= ) + if mtime < conf["MTIME"]: + continue +=09 + # look for an existing stable version + our =3D portage.versions.best( conf["portdb"].dbapi.match( "%s/%s%s"= % ( cat, pkg, slot ) ) ) + if our: + _foo =3D portage.versions.pkgsplit( our ) + our_ver =3D _foo[1] + if _foo[2] !=3D "r0": + our_ver =3D "%s-%s" % ( our_ver, _foo[2] ) + else: + our_ver =3D "" +=09 + # we just need the version if > our_ver + if our_ver: + if portage.versions.vercmp( our_ver, vr ) >=3D 0: + continue +=09 + if kwd_type =3D=3D 1 and conf["STABLE"]: + imlate =3D _add_ent( imlate, cat, ("%s%s" % (pkg, slot)), vr, our_v= er ) + conf["STABLE_SUM"] +=3D 1 + elif kwd_type =3D=3D 0 and conf["KEYWORD"]: + conf["KEYWORD_SUM"] +=3D 1 + imlate =3D _add_ent( imlate, cat, ( "~%s%s" % (pkg, slot) ), + vr, our_ver ) + + return imlate + +# fetch portage related settings +def get_settings( conf =3D None ): + if not isinstance( conf, dict ) and conf: + raise TypeError("conf must be dict() or None") + if not conf: + conf =3D {} + + # TODO: maybe we should improve it a bit ;) + mysettings =3D portage.config( config_incrementals =3D portage.const.IN= CREMENTALS, local_config =3D False ) + + if conf["MAIN_ARCH"] =3D=3D "auto": + conf["MAIN_ARCH"] =3D "%s" % mysettings["ACCEPT_KEYWORDS"].split(" ")[= 0].lstrip("~") + if conf["TARGET_ARCH"] =3D=3D "auto": + conf["TARGET_ARCH"] =3D "~%s" % mysettings["ACCEPT_KEYWORDS"].split(" = ")[0].lstrip("~") + + # TODO: exclude overlay categories from check + if conf["CATEGORIES"]: + _mycats =3D [] + for _cat in conf["CATEGORIES"].split(","): + _cat =3D _cat.strip() + _mycats.append(_cat ) + if _cat not in mysettings.categories: + raise ValueError("invalid category for -C switch '%s'" % _cat) + mysettings.categories =3D _mycats + + # maybe thats not necessary because we override porttrees below.. + _portage_settings( "PORTDIR_OVERLAY", "", mysettings ) + trees =3D portage.create_trees() + trees["/"]["porttree"].settings =3D mysettings + portdb =3D trees["/"]["porttree"] + portdb.dbapi.settings =3D mysettings + portdb.dbapi.porttrees =3D [portage.portdb.porttree_root] + # does it make sense to remove _all_ useless stuff or just leave it as = it is? + #portdb.dbapi._aux_cache_keys.clear() + #portdb.dbapi._aux_cache_keys.update(["EAPI", "KEYWORDS", "SLOT"]) + + conf["PORTDIR"] =3D portage.settings["PORTDIR"] + conf["portdb"] =3D portdb + + return conf + + +# just for standalone +def main(): + conf =3D {} + pkgs =3D {} + + parser =3D OptionParser( version =3D "%prog " + VERSION ) + parser.usage =3D "%prog [options] [category/package] ..." + parser.disable_interspersed_args() + + parser.add_option( "-f", "--file", dest =3D "filename", action =3D "sto= re", type =3D "string", + help =3D "write result into FILE [default: %default]", metavar =3D "F= ILE", default =3D "stdout" ) + parser.add_option( "-m", "--main", dest =3D "main_arch", action =3D "st= ore", type =3D "string", + help =3D "set main ARCH (e.g. your arch) [default: %default]", metava= r =3D "ARCH", default =3D MAIN_ARCH ) + parser.add_option( "-t", "--target", dest =3D "target_arch", action =3D= "store", type =3D "string", + help =3D "set target ARCH (e.g. x86) [default: %default]", metavar =3D= "ARCH", default =3D TARGET_ARCH ) + parser.add_option( "--mtime", dest =3D "mtime", action =3D "store", typ= e =3D "int", + help =3D "set minimum MTIME in days [default: %default]", metavar =3D= "MTIME", default =3D 30 ) + + # TODO: leave a good comment here (about True/False) :) + parser.add_option( "-s", "--stable", dest =3D "stable", action =3D "sto= re_true", default =3D False, + help =3D "just show stable candidates (e.g. -s and -k is the default = result) [default: True]" ) + parser.add_option( "-k", "--keyword", dest =3D "keyword", action =3D "s= tore_true", default =3D False, + help =3D "just show keyword candidates (e.g. -s and -k is the default= result) [default: True]" ) + + parser.add_option( "-M", "--maintainer", dest =3D "maintainer", action = =3D "store", type =3D "string", + help =3D "Show only packages from the specified maintainer", metavar = =3D "MAINTAINER", default =3D None) + + parser.add_option( "-H", "--herd", dest =3D "herd", action =3D "store",= type =3D "string", + help =3D "Show only packages from the specified herd", metavar =3D "H= ERD", default =3D None) + +# # EXPERIMENTAL +# parser.add_option( "-e", "--experimental", dest =3D "experimental", ac= tion =3D "store_true", default =3D False, +# help =3D "enables experimental functions/features (have a look for #= EXPERIMENTAL comments in the source) [default: %default]" ) + + parser.add_option( "-C", "--category", "--categories", dest =3D "catego= ries", action =3D "store", default =3D None, + metavar =3D "CATEGORIES", + help =3D "just check in the specified category/categories (comma sepa= rated) [default: %default]") + + ( options, args ) =3D parser.parse_args() + + if len( args ) > 0: + conf["USER_PKGS"] =3D args + else: + conf["USER_PKGS"] =3D [] + + # cleanup optparse + try: + parser.destroy() + except AttributeError: + # to be at least python 2.4 compatible + del parser._short_opt + del parser._long_opt + del parser.defaults + + # generated timestamp (UTC) + conf["TIME"] =3D strftime( "%a %b %d %H:%M:%S %Z %Y", gmtime() ) + + # package counter + conf["KEYWORD_SUM"] =3D 0 + conf["STABLE_SUM"] =3D 0 + + if not options.main_arch in portage.archlist and options.main_arch !=3D= "auto": + raise ValueError("invalid MAIN ARCH defined!") + if not options.target_arch in portage.archlist and options.target_arch = !=3D "auto": + raise ValueError("invalid TARGET ARCH defined!") + + conf["MAIN_ARCH"] =3D options.main_arch + conf["TARGET_ARCH"] =3D options.target_arch + + conf["FILE"] =3D options.filename + conf["MTIME"] =3D options.mtime + + if not options.stable and not options.keyword: + conf["STABLE"] =3D True + conf["KEYWORD"] =3D True + else: + conf["STABLE"] =3D options.stable + conf["KEYWORD"] =3D options.keyword + +# conf["EXPERIMENTAL"] =3D options.experimental + conf["CATEGORIES"] =3D options.categories + + conf["MAINTAINER"] =3D options.maintainer + conf["HERD"] =3D options.herd + + # append to our existing + conf =3D get_settings( conf ) + pkgs =3D get_packages( conf ) + pkgs =3D get_imlate( conf, pkgs ) + + show_result( conf, pkgs ) + +if __name__ =3D=3D "__main__": + main() +