public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Nirbheek Chauhan" <nirbheek@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gnome:master commit in: scripts/
Date: Wed, 23 Mar 2011 21:59:21 +0000 (UTC)	[thread overview]
Message-ID: <2af0175847b6b8d097e7e3dbbe11228c724eaaf4.nirbheek@gentoo> (raw)

commit:     2af0175847b6b8d097e7e3dbbe11228c724eaaf4
Author:     Nirbheek Chauhan <nirbheek <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 23 12:54:16 2011 +0000
Commit:     Nirbheek Chauhan <nirbheek <AT> gentoo <DOT> org>
CommitDate: Wed Mar 23 21:59:03 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gnome.git;a=commit;h=2af01758

slot_rindex.py: add slower portage-only mode, reorganize code

* Set PORTAGE_ONLY to True to use the slower code
* It's about 5x slower on hot cache

---
 scripts/slot_rindex.py |  123 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 84 insertions(+), 39 deletions(-)

diff --git a/scripts/slot_rindex.py b/scripts/slot_rindex.py
index bf5f834..3610813 100755
--- a/scripts/slot_rindex.py
+++ b/scripts/slot_rindex.py
@@ -11,26 +11,31 @@
 # Currently prints out a list of revdeps which *don't* use a slot in the
 # dependency atom containing the given library
 #
-# TODO: Add a slower portage-only mode which calculates the required rindex
-#
 
 import sys
-import urllib2
 import os.path as osp
 
 import portage
 from portage.xml.metadata import MetaDataXML
 
+portdb = portage.portdb
+portdb.porttrees = [portage.settings['PORTDIR']]
+PORTDIR = portage.settings['PORTDIR']
+DEPVARS = ['RDEPEND', 'PDEPEND', 'DEPEND']
+
+#####################
+### Configuration ###
+#####################
 if len(sys.argv) < 2:
     print "Usage: %s <cat/pkg>" % sys.argv[0]
     sys.exit(1)
 
-portage.portdb.porttrees = [portage.settings['PORTDIR']]
-PORTDIR = portage.settings['PORTDIR']
-RINDEX = "http://tinderbox.dev.gentoo.org/misc/rindex"
-DEPSTR = ['RDEPEND', 'PDEPEND', 'DEPEND']
 KEY = sys.argv[1]
+PORTAGE_ONLY = False
 
+########################
+### Output Functions ###
+########################
 def get_herds():
     return osp.join(PORTDIR, 'metadata', 'herds.xml')
 
@@ -50,7 +55,9 @@ def rdeps_with_slot(slot_rdeps, slot=None):
     if not slot_rdeps.has_key(slot):
         # No rdeps using the given slot
         return
+    print "-------------------------------"
     print "All packages:"
+    print "-------------------------------"
     for pkg in slot_rdeps[slot]:
         pkg_md = MetaDataXML(get_md_path(pkg), get_herds())
         for herd in pkg_md.herds():
@@ -69,54 +76,92 @@ def rdeps_with_slot(slot_rdeps, slot=None):
             print '%s' % i.email,
         print
 
+    print "-------------------------------"
     print "Herd packages:"
+    print "-------------------------------"
     for (herd, pkgs) in pkg_herds.iteritems():
         print 'Herd: %s' % herd
         for pkg in pkgs:
             print '\t%s' % pkg
 
+    print "-------------------------------"
     print "Maintainer packages:"
+    print "-------------------------------"
     for (maint, pkgs) in pkg_maints.iteritems():
         print 'Maintainer: %s' % maint
         for pkg in pkgs:
             print '\t%s' % pkg
 
+#############################
+### Portage API Functions ###
+#############################
+def get_deps_both(cpv, depvars=DEPVARS):
+    """
+    Parses the dependency variables listed in depvars for cpv
 
-vrdeps = urllib2.urlopen('/'.join([RINDEX, KEY])).read().split()
-rdeps = []
-for i in vrdeps:
-    rdeps.append(i.split(':')[0])
-
-slot_rdeps = {}
-failed_rdeps = []
-for rdep in rdeps:
-    rdep = rdep.split(':')[0]
-    if not portage.isvalidatom('='+rdep):
-        print 'Invalid atom: ' + rdep
-        continue
+    returns (set(dep_cps), set(dep_strs))
+    """
+    dep_cps = set()
+    dep_strs = set()
+    raw_deps = []
     try:
-        temp = portage.portdb.aux_get(rdep, DEPSTR)[0].split()
+        raw_deps = portdb.aux_get(cpv, depvars)[0].split()
     except KeyError:
-        failed_rdeps.append(rdep)
+        return (dep_cps, dep_strs)
+    for dep in portage.dep.use_reduce(' '.join(raw_deps),
+                                      matchall=True, flat=True):
+        # Ignore blockers, etc
+        if portage.isvalidatom(dep):
+            dep_strs.add(dep)
+            dep_cps.add(portage.dep.dep_getkey(dep))
+    return (dep_cps, dep_strs)
+
+def get_revdeps_rindex(key):
+    """
+    Given a key, returns a reverse-dependency list of that key using the tinderbox rindex
+    """
+    import urllib2
+    RINDEX = "http://tinderbox.dev.gentoo.org/misc/rindex"
+    revdeps = []
+    rdeps_raw = urllib2.urlopen('/'.join([RINDEX, key])).read().split()
+    for i in rdeps_raw:
+        cpv = i.split(':')[0]
+        if portage.isvalidatom('='+cpv):
+            revdeps.append(cpv)
+    return revdeps
+
+def get_revdeps_portage(key):
+    """
+    Given a key, returns a reverse-dependency list of that key using portage API
+    """
+    revdeps = []
+    for cp in portdb.cp_all():
+        cpvrs = portdb.xmatch('match-all', cp)
+        for cpvr in cpvrs:
+            if key in get_deps_both(cpvr)[0]:
+                revdeps.append(cpvr)
+    return revdeps
+
+###################
+### Actual Work ###
+###################
+slot_rdeps = {}
+revdeps = []
+if PORTAGE_ONLY:
+    revdeps = get_revdeps_portage(KEY)
+else:
+    revdeps = get_revdeps_rindex(KEY)
+
+for rdep in revdeps:
+    (cps, deps) = get_deps_both(rdep)
+    if KEY not in cps:
         continue
-    for dep in temp:
-        # Ignore ||, (, ), etc.
-        if not portage.isvalidatom(dep):
+    for cpv in deps:
+        if cpv.find(KEY) == -1:
             continue
-        # Categorize the dep into the slot it uses
-        if portage.dep.dep_getkey(dep) == KEY:
-            slot = portage.dep.dep_getslot(dep)
-            if not slot_rdeps.has_key(slot):
-                # We use a set here because atoms often get repeated
-                slot_rdeps[slot] = set()
-            slot_rdeps[slot].add(rdep)
-
-# Convert back to list, and sort the atoms
-for slot in slot_rdeps.keys():
-    slot_rdeps[slot] = list(slot_rdeps[slot])
-    slot_rdeps[slot].sort()
-
-if failed_rdeps:
-    print 'Failed: ' + str(failed_rdeps)
+        slot = portage.dep.dep_getslot(cpv)
+        if not slot_rdeps.has_key(slot):
+            slot_rdeps[slot] = []
+        slot_rdeps[slot].append(rdep)
 
 rdeps_with_slot(slot_rdeps)



             reply	other threads:[~2011-03-23 21:59 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-23 21:59 Nirbheek Chauhan [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-04-03 19:42 [gentoo-commits] proj/gnome:master commit in: scripts/ Matt Turner
2020-04-03 19:42 Matt Turner
2020-03-28  8:31 Mart Raudsepp
2020-03-10 22:05 Matt Turner
2019-02-07 11:58 Mart Raudsepp
2018-04-25 10:32 Mart Raudsepp
2018-01-10  3:25 Mart Raudsepp
2012-04-01 21:14 Nirbheek Chauhan
2012-04-01 19:12 Nirbheek Chauhan
2011-08-18  6:23 Nirbheek Chauhan
2011-07-12 21:15 Nirbheek Chauhan
2011-05-21 18:38 Nirbheek Chauhan
2011-05-19 12:35 Gilles Dartiguelongue
2011-04-13  9:57 Nirbheek Chauhan
2011-04-09  6:29 Nirbheek Chauhan
2011-03-28 16:15 Nirbheek Chauhan
2011-03-28 15:04 Nirbheek Chauhan
2011-03-26  1:58 Nirbheek Chauhan
2011-03-23 21:59 Nirbheek Chauhan
2011-03-23 21:59 Nirbheek Chauhan
2011-03-23 19:21 Gilles Dartiguelongue
2011-03-23 10:39 Gilles Dartiguelongue
2011-03-20  8:11 Nirbheek Chauhan
2011-03-18  9:59 Nirbheek Chauhan
2011-03-18  8:23 Nirbheek Chauhan
2011-03-17 17:12 Nirbheek Chauhan
2011-03-15 13:08 Nirbheek Chauhan
2011-03-14 18:41 Nirbheek Chauhan
2011-03-12 20:10 Nirbheek Chauhan
2011-03-04 15:40 Nirbheek Chauhan
2011-02-18  4:40 Nirbheek Chauhan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2af0175847b6b8d097e7e3dbbe11228c724eaaf4.nirbheek@gentoo \
    --to=nirbheek@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox