]> git.decadent.org.uk Git - dak.git/blob - dak/ls.py
Enmasse adaptation for removal of silly names.
[dak.git] / dak / ls.py
1 #!/usr/bin/env python
2
3 # Display information about package(s) (suite, version, etc.)
4 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006  James Troup <james@nocrew.org>
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 ################################################################################
21
22 # <aj> ooo, elmo has "special powers"
23 # <neuro> ooo, does he have lasers that shoot out of his eyes?
24 # <aj> dunno
25 # <aj> maybe he can turn invisible? that'd sure help with improved transparency!
26
27 ################################################################################
28
29 import os, pg, sys
30 import dak.lib.utils, dak.lib.database
31 import apt_pkg
32
33 ################################################################################
34
35 Cnf = None
36 projectB = None
37
38 ################################################################################
39
40 def usage (exit_code=0):
41     print """Usage: dak ls [OPTION] PACKAGE[...]
42 Display information about PACKAGE(s).
43
44   -a, --architecture=ARCH    only show info for ARCH(s)
45   -b, --binary-type=TYPE     only show info for binary TYPE
46   -c, --component=COMPONENT  only show info for COMPONENT(s)
47   -g, --greaterorequal       show buildd 'dep-wait pkg >= {highest version}' info
48   -G, --greaterthan          show buildd 'dep-wait pkg >> {highest version}' info
49   -h, --help                 show this help and exit
50   -r, --regex                treat PACKAGE as a regex
51   -s, --suite=SUITE          only show info for this suite
52   -S, --source-and-binary    show info for the binary children of source pkgs
53
54 ARCH, COMPONENT and SUITE can be comma (or space) separated lists, e.g.
55     --architecture=m68k,i386"""
56     sys.exit(exit_code)
57
58 ################################################################################
59
60 def main ():
61     global Cnf, projectB
62
63     Cnf = dak.lib.utils.get_conf()
64
65     Arguments = [('a', "architecture", "Ls::Options::Architecture", "HasArg"),
66                  ('b', "binarytype", "Ls::Options::BinaryType", "HasArg"),
67                  ('c', "component", "Ls::Options::Component", "HasArg"),
68                  ('f', "format", "Ls::Options::Format", "HasArg"),
69                  ('g', "greaterorequal", "Ls::Options::GreaterOrEqual"),
70                  ('G', "greaterthan", "Ls::Options::GreaterThan"),
71                  ('r', "regex", "Ls::Options::Regex"),
72                  ('s', "suite", "Ls::Options::Suite", "HasArg"),
73                  ('S', "source-and-binary", "Ls::Options::Source-And-Binary"),
74                  ('h', "help", "Ls::Options::Help")]
75     for i in [ "architecture", "binarytype", "component", "format",
76                "greaterorequal", "greaterthan", "regex", "suite",
77                "source-and-binary", "help" ]:
78         if not Cnf.has_key("Ls::Options::%s" % (i)):
79             Cnf["Ls::Options::%s" % (i)] = ""
80
81     packages = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
82     Options = Cnf.SubTree("Ls::Options")
83
84     if Options["Help"]:
85         usage()
86     if not packages:
87         dak.lib.utils.fubar("need at least one package name as an argument.")
88
89     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
90     dak.lib.database.init(Cnf, projectB)
91
92     # If cron.daily is running; warn the user that our output might seem strange
93     if os.path.exists(os.path.join(Cnf["Dir::Root"], "Archive_Maintenance_In_Progress")):
94         dak.lib.utils.warn("Archive maintenance is in progress; database inconsistencies are possible.")
95
96     # Handle buildd maintenance helper options
97     if Options["GreaterOrEqual"] or Options["GreaterThan"]:
98         if Options["GreaterOrEqual"] and Options["GreaterThan"]:
99             dak.lib.utils.fubar("-g/--greaterorequal and -G/--greaterthan are mutually exclusive.")
100         if not Options["Suite"]:
101             Options["Suite"] = "unstable"
102
103     # Parse -a/--architecture, -c/--component and -s/--suite
104     (con_suites, con_architectures, con_components, check_source) = \
105                  dak.lib.utils.parse_args(Options)
106
107     if Options["BinaryType"]:
108         if Options["BinaryType"] != "udeb" and Options["BinaryType"] != "deb":
109             dak.lib.utils.fubar("Invalid binary type.  'udeb' and 'deb' recognised.")
110         con_bintype = "AND b.type = '%s'" % (Options["BinaryType"])
111         # REMOVE ME TRAMP
112         if Options["BinaryType"] == "udeb":
113             check_source = 0
114     else:
115         con_bintype = ""
116
117     if Options["Regex"]:
118         comparison_operator = "~"
119     else:
120         comparison_operator = "="
121
122     if Options["Source-And-Binary"]:
123         new_packages = []
124         for package in packages:
125             q = projectB.query("SELECT DISTINCT b.package FROM binaries b, bin_associations ba, suite su, source s WHERE b.source = s.id AND su.id = ba.suite AND b.id = ba.bin AND s.source %s '%s' %s" % (comparison_operator, package, con_suites))
126             new_packages.extend(map(lambda x: x[0], q.getresult()))
127             if package not in new_packages:
128                 new_packages.append(package)
129         packages = new_packages
130
131     results = 0
132     for package in packages:
133         q = projectB.query("""
134 SELECT b.package, b.version, a.arch_string, su.suite_name, c.name, m.name
135   FROM binaries b, architecture a, suite su, bin_associations ba,
136        files f, location l, component c, maintainer m
137  WHERE b.package %s '%s' AND a.id = b.architecture AND su.id = ba.suite
138    AND b.id = ba.bin AND b.file = f.id AND f.location = l.id
139    AND l.component = c.id AND b.maintainer = m.id %s %s %s
140 """ % (comparison_operator, package, con_suites, con_architectures, con_bintype))
141         ql = q.getresult()
142         if check_source:
143             q = projectB.query("""
144 SELECT s.source, s.version, 'source', su.suite_name, c.name, m.name
145   FROM source s, suite su, src_associations sa, files f, location l,
146        component c, maintainer m
147  WHERE s.source %s '%s' AND su.id = sa.suite AND s.id = sa.source
148    AND s.file = f.id AND f.location = l.id AND l.component = c.id
149    AND s.maintainer = m.id %s
150 """ % (comparison_operator, package, con_suites))
151             ql.extend(q.getresult())
152         d = {}
153         highver = {}
154         for i in ql:
155             results += 1
156             (pkg, version, architecture, suite, component, maintainer) = i
157             if component != "main":
158                 suite = "%s/%s" % (suite, component)
159             if not d.has_key(pkg):
160                 d[pkg] = {}
161             highver.setdefault(pkg,"")
162             if not d[pkg].has_key(version):
163                 d[pkg][version] = {}
164                 if apt_pkg.VersionCompare(version, highver[pkg]) > 0:
165                     highver[pkg] = version
166             if not d[pkg][version].has_key(suite):
167                 d[pkg][version][suite] = []
168             d[pkg][version][suite].append(architecture)
169
170         packages = d.keys()
171         packages.sort()
172         for pkg in packages:
173             versions = d[pkg].keys()
174             versions.sort(apt_pkg.VersionCompare)
175             for version in versions:
176                 suites = d[pkg][version].keys()
177                 suites.sort()
178                 for suite in suites:
179                     arches = d[pkg][version][suite]
180                     arches.sort(dak.lib.utils.arch_compare_sw)
181                     if Options["Format"] == "": #normal
182                         sys.stdout.write("%10s | %10s | %13s | " % (pkg, version, suite))
183                         sys.stdout.write(", ".join(arches))
184                         sys.stdout.write('\n')
185                     elif Options["Format"] == "control-suite":
186                         for arch in arches:
187                             sys.stdout.write("%s %s %s\n" % (pkg, version, arch))
188             if Options["GreaterOrEqual"]:
189                 print "\n%s (>= %s)" % (pkg, highver[pkg])
190             if Options["GreaterThan"]:
191                 print "\n%s (>> %s)" % (pkg, highver[pkg])
192
193     if not results:
194         sys.exit(1)
195
196 #######################################################################################
197
198 if __name__ == '__main__':
199     main()
200