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