Debian Codegraph @

examples/debtags/tagsbyrelevance

raw
1 #!/usr/bin/python3
2
3 # debtags - Implement package tags support for Debian
4 #
5 # Copyright (C) 2003--2006 Enrico Zini <[email protected]>
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 import sys
21 import re
22 from debian import debtags
23
24 if len(sys.argv) < 2:
25 print("Usage: %s tagdb [packagelist]" % (sys.argv[0]), file=sys.stderr)
26 sys.exit(1)
27
28 full = debtags.DB()
29 # Read full database
30 tag_filter = re.compile(r"^special::.+$|^.+::TODO$")
31 full.read(open(sys.argv[1], "r"), lambda x: not tag_filter.match(x))
32
33 # Read the package list and create the subcollection
34 input = len(sys.argv) > 2 and open(sys.argv[2],"r") or sys.stdin
35 pkgs = set()
36 for pkg in input:
37 # Tolerate apt-cache search output as well
38 pkg, none = pkg.rstrip("\n").split(' - ', 1)
39 pkgs.add(pkg)
40
41 sub = full.choose_packages(pkgs)
42
43 rel_index = debtags.relevance_index_function(full, sub)
44
45 # Get all the tags sorted by increasing relevance
46 tags = sorted(sub.iter_tags(), lambda a, b: cmp(rel_index(a), rel_index(b)))
47
48 ## And finally print them
49 for tag in tags:
50 print(tag)
51 #print(tag, sub.card(tag), full.card(tag), float(sub.card(tag)) / float(full.card(tag)))