3 # Display information about package(s) (suite, version, etc.)
4 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org>
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.
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.
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
20 ################################################################################
22 # <aj> ooo, elmo has "special powers"
23 # <neuro> ooo, does he have lasers that shoot out of his eyes?
25 # <aj> maybe he can turn invisible? that'd sure help with improved transparency!
27 ################################################################################
30 import dak.lib.utils, dak.lib.database
33 ################################################################################
38 ################################################################################
40 def usage (exit_code=0):
41 print """Usage: dak ls [OPTION] PACKAGE[...]
42 Display information about PACKAGE(s).
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
54 ARCH, COMPONENT and SUITE can be comma (or space) separated lists, e.g.
55 --architecture=m68k,i386"""
58 ################################################################################
63 Cnf = dak.lib.utils.get_conf()
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)] = ""
81 packages = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
82 Options = Cnf.SubTree("Ls::Options")
87 dak.lib.utils.fubar("need at least one package name as an argument.")
89 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
90 dak.lib.database.init(Cnf, projectB)
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.")
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"
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)
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"])
112 if Options["BinaryType"] == "udeb":
118 comparison_operator = "~"
120 comparison_operator = "="
122 if Options["Source-And-Binary"]:
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
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))
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())
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):
161 highver.setdefault(pkg,"")
162 if not d[pkg].has_key(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)
173 versions = d[pkg].keys()
174 versions.sort(apt_pkg.VersionCompare)
175 for version in versions:
176 suites = d[pkg][version].keys()
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":
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])
196 #######################################################################################
198 if __name__ == '__main__':