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.config import Config
39 from daklib.dbconn import *
40 from daklib import utils
42 ################################################################################
44 def usage (exit_code=0):
45 print """Usage: dak ls [OPTION] PACKAGE[...]
46 Display information about PACKAGE(s).
48 -a, --architecture=ARCH only show info for ARCH(s)
49 -b, --binary-type=TYPE only show info for binary TYPE
50 -c, --component=COMPONENT only show info for COMPONENT(s)
51 -g, --greaterorequal show buildd 'dep-wait pkg >= {highest version}' info
52 -G, --greaterthan show buildd 'dep-wait pkg >> {highest version}' info
53 -h, --help show this help and exit
54 -r, --regex treat PACKAGE as a regex
55 -s, --suite=SUITE only show info for this suite
56 -S, --source-and-binary show info for the binary children of source pkgs
58 ARCH, COMPONENT and SUITE can be comma (or space) separated lists, e.g.
59 --architecture=m68k,i386"""
62 ################################################################################
67 Arguments = [('a', "architecture", "Ls::Options::Architecture", "HasArg"),
68 ('b', "binarytype", "Ls::Options::BinaryType", "HasArg"),
69 ('c', "component", "Ls::Options::Component", "HasArg"),
70 ('f', "format", "Ls::Options::Format", "HasArg"),
71 ('g', "greaterorequal", "Ls::Options::GreaterOrEqual"),
72 ('G', "greaterthan", "Ls::Options::GreaterThan"),
73 ('r', "regex", "Ls::Options::Regex"),
74 ('s', "suite", "Ls::Options::Suite", "HasArg"),
75 ('S', "source-and-binary", "Ls::Options::Source-And-Binary"),
76 ('h', "help", "Ls::Options::Help")]
77 for i in [ "architecture", "binarytype", "component", "format",
78 "greaterorequal", "greaterthan", "regex", "suite",
79 "source-and-binary", "help" ]:
80 if not cnf.has_key("Ls::Options::%s" % (i)):
81 cnf["Ls::Options::%s" % (i)] = ""
83 packages = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
84 Options = cnf.SubTree("Ls::Options")
89 utils.fubar("need at least one package name as an argument.")
91 session = DBConn().session()
93 # If cron.daily is running; warn the user that our output might seem strange
94 if os.path.exists(os.path.join(cnf["Dir::Root"], "Archive_Maintenance_In_Progress")):
95 utils.warn("Archive maintenance is in progress; database inconsistencies are possible.")
97 # Handle buildd maintenance helper options
98 if Options["GreaterOrEqual"] or Options["GreaterThan"]:
99 if Options["GreaterOrEqual"] and Options["GreaterThan"]:
100 utils.fubar("-g/--greaterorequal and -G/--greaterthan are mutually exclusive.")
101 if not Options["Suite"]:
102 Options["Suite"] = "unstable"
104 # Parse -a/--architecture, -c/--component and -s/--suite
105 (con_suites, con_architectures, con_components, check_source) = \
106 utils.parse_args(Options)
108 if Options["BinaryType"]:
109 if Options["BinaryType"] != "udeb" and Options["BinaryType"] != "deb":
110 utils.fubar("Invalid binary type. 'udeb' and 'deb' recognised.")
111 con_bintype = "AND b.type = '%s'" % (Options["BinaryType"])
113 if Options["BinaryType"] == "udeb":
119 comparison_operator = "~"
121 comparison_operator = "="
123 if Options["Source-And-Binary"]:
125 for package in packages:
126 q = session.execute("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 :package %s" % (comparison_operator, con_suites),
127 {'package': package})
128 new_packages.extend([ i[0] for i in q.fetchall() ])
129 if package not in new_packages:
130 new_packages.append(package)
131 packages = new_packages
134 for package in packages:
135 q = session.execute("""
136 SELECT b.package, b.version, a.arch_string, su.suite_name, c.name, m.name
137 FROM binaries b, architecture a, suite su, bin_associations ba,
138 files f, location l, component c, maintainer m
139 WHERE b.package %s :package AND a.id = b.architecture AND su.id = ba.suite
140 AND b.id = ba.bin AND b.file = f.id AND f.location = l.id
141 AND l.component = c.id AND b.maintainer = m.id %s %s %s
142 """ % (comparison_operator, con_suites, con_architectures, con_bintype), {'package': package})
145 q = session.execute("""
146 SELECT s.source, s.version, 'source', su.suite_name, c.name, m.name
147 FROM source s, suite su, src_associations sa, files f, location l,
148 component c, maintainer m
149 WHERE s.source %s :package AND su.id = sa.suite AND s.id = sa.source
150 AND s.file = f.id AND f.location = l.id AND l.component = c.id
151 AND s.maintainer = m.id %s
152 """ % (comparison_operator, con_suites), {'package': package})
153 ql.extend(q.fetchall())
158 (pkg, version, architecture, suite, component, maintainer) = i
159 if component != "main":
160 suite = "%s/%s" % (suite, component)
161 if not d.has_key(pkg):
163 highver.setdefault(pkg,"")
164 if not d[pkg].has_key(version):
166 if apt_pkg.VersionCompare(version, highver[pkg]) > 0:
167 highver[pkg] = version
168 if not d[pkg][version].has_key(suite):
169 d[pkg][version][suite] = []
170 d[pkg][version][suite].append(architecture)
175 versions = d[pkg].keys()
176 versions.sort(apt_pkg.VersionCompare)
177 for version in versions:
178 suites = d[pkg][version].keys()
181 arches = d[pkg][version][suite]
182 arches.sort(utils.arch_compare_sw)
183 if Options["Format"] == "": #normal
184 sys.stdout.write("%10s | %10s | %13s | " % (pkg, version, suite))
185 sys.stdout.write(", ".join(arches))
186 sys.stdout.write('\n')
187 elif Options["Format"] in [ "control-suite", "heidi" ]:
189 sys.stdout.write("%s %s %s\n" % (pkg, version, arch))
190 if Options["GreaterOrEqual"]:
191 print "\n%s (>= %s)" % (pkg, highver[pkg])
192 if Options["GreaterThan"]:
193 print "\n%s (>> %s)" % (pkg, highver[pkg])
198 #######################################################################################
200 if __name__ == '__main__':