Gentoo Archives: gentoo-commits

From: "Markos Chandras (hwoarang)" <hwoarang@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo commit in xml/htdocs/proj/en/qa/treecleaners/scripts: check-orphaned-packages.py.txt
Date: Thu, 23 Jan 2014 18:00:15
Message-Id: 20140123180009.1F3CE2004C@flycatcher.gentoo.org
1 hwoarang 14/01/23 18:00:09
2
3 Modified: check-orphaned-packages.py.txt
4 Log:
5 Update script to work with python-3 thanks to Chris Stout
6
7 Revision Changes Path
8 1.2 xml/htdocs/proj/en/qa/treecleaners/scripts/check-orphaned-packages.py.txt
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/proj/en/qa/treecleaners/scripts/check-orphaned-packages.py.txt?rev=1.2&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/proj/en/qa/treecleaners/scripts/check-orphaned-packages.py.txt?rev=1.2&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/proj/en/qa/treecleaners/scripts/check-orphaned-packages.py.txt?r1=1.1&r2=1.2
13
14 Index: check-orphaned-packages.py.txt
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo/xml/htdocs/proj/en/qa/treecleaners/scripts/check-orphaned-packages.py.txt,v
17 retrieving revision 1.1
18 retrieving revision 1.2
19 diff -u -r1.1 -r1.2
20 --- check-orphaned-packages.py.txt 7 Dec 2012 00:44:18 -0000 1.1
21 +++ check-orphaned-packages.py.txt 23 Jan 2014 18:00:08 -0000 1.2
22 @@ -1,28 +1,45 @@
23 -#!/usr/bin/python
24 -from bs4 import BeautifulSoup
25 +#!/usr/bin/env python
26 import portage
27 -import urllib2
28 +import re
29 +# For python2.6 compatibility
30 +try:
31 + from urllib.request import urlopen
32 +except:
33 + from urllib2 import urlopen
34
35 +# Compatibility with bs3 users
36 +try:
37 + from bs4 import BeautifulSoup
38 +except:
39 + from BeautifulSoup import BeautifulSoup
40 +
41 +# Make a list of orphaned packages by parsing xml with BeautifulSoup
42 url = 'http://www.gentoo.org/proj/en/qa/treecleaners/maintainer-needed.xml'
43
44 -# Build a to remove set
45 -f = urllib2.urlopen(url)
46 -soup = BeautifulSoup(f.read())
47 -table = soup.find('table', {'class': 'ntable'})
48 -toremove = set(row.findChild('a').text for row in table.findChildren('tr')[1:])
49 -f.close()
50 +orphan_page = urlopen(url)
51 +soup = BeautifulSoup(orphan_page)
52 +orphan_page.close()
53 +table = soup.find('table', 'ntable')
54 +# compatibility for bs3 users
55 +try:
56 + orphan_links = table.find_all('a', href=re.compile('https?://packages.gentoo.org'))
57 +except:
58 + orphan_links = table.findAll('a', href=re.compile('https?://packages.gentoo.org'))
59 +orphans = set([a.text for a in orphan_links])
60
61 -# Build an installed set
62 +# Build a list of packages that are installed
63 vartree = portage.db[portage.root]['vartree']
64 installed = set(vartree.dbapi.cp_all())
65
66 -# Print installed, but to be removed
67 -packages = sorted(toremove.intersection(installed))
68 +# Print list of all orphans that are installed
69 +packages = sorted(orphans.intersection(installed))
70 +
71 +# Python 2.6 requires the '0' in between curly braces to work
72 if packages:
73 - print "The following %d installed package(s) need a maintainer" % len(packages)
74 + print("The following {0} installed package(s) need a maintainer".format(len(packages)))
75 for package in packages:
76 - print "-", package
77 + print("-{0}".format(str(package)))
78 exit(1)
79 else:
80 - print "All installed packages have a maintainer :)"
81 + print("All installed packages have a maintainer :)")
82 exit(0)