Coverage for dak/ls.py: 70%
33 statements
« prev ^ index » next coverage.py v7.6.0, created at 2026-08-03 16:46 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2026-08-03 16:46 +0000
1"""
2Display information about package(s) (suite, version, etc.)
4@contact: Debian FTP Master <ftpmaster@debian.org>
5@copyright: 2000, 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org>
6@license: GNU General Public License version 2 or later
8"""
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24################################################################################
26# <aj> ooo, elmo has "special powers"
27# <neuro> ooo, does he have lasers that shoot out of his eyes?
28# <aj> dunno
29# <aj> maybe he can turn invisible? that'd sure help with improved transparency!
31################################################################################
33import sys
35import apt_pkg
37from daklib import utils
38from daklib.config import Config
39from daklib.ls import list_packages
41################################################################################
44def usage(exit_code=0):
45 print(
46 """Usage: dak ls [OPTION] PACKAGE[...]
47Display information about PACKAGE(s).
49 -a, --architecture=ARCH only show info for ARCH(s)
50 -b, --binary-type=TYPE only show info for binary TYPE
51 -c, --component=COMPONENT only show info for COMPONENT(s)
52 -g, --greaterorequal show buildd 'dep-wait pkg >= {highest version}' info
53 -G, --greaterthan show buildd 'dep-wait pkg >> {highest version}' info
54 -h, --help show this help and exit
55 -r, --regex treat PACKAGE as a regex
56 -s, --suite=SUITE only show info for this suite
57 -S, --source-and-binary show info for the binary children of source pkgs
58 -f, --format=control-suite use same format as control-suite for output
60ARCH, COMPONENT and SUITE can be comma (or space) separated lists, e.g.
61 --architecture=amd64,i386"""
62 )
63 sys.exit(exit_code)
66################################################################################
69def main():
70 cnf = Config()
72 Arguments = [
73 ("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 ]
84 for i in [
85 "architecture",
86 "binarytype",
87 "component",
88 "format",
89 "greaterorequal",
90 "greaterthan",
91 "regex",
92 "suite",
93 "source-and-binary",
94 "help",
95 ]:
96 key = "Ls::Options::%s" % i
97 if key not in cnf: 97 ↛ 84line 97 didn't jump to line 84
98 cnf[key] = ""
100 packages = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) # type: ignore[attr-defined]
101 Options = cnf.subtree("Ls::Options")
103 if Options["Help"]:
104 usage()
105 if not packages: 105 ↛ 106line 105 didn't jump to line 106 because the condition on line 105 was never true
106 utils.fubar("need at least one package name as an argument.")
108 # Handle buildd maintenance helper options
109 if Options["GreaterOrEqual"] or Options["GreaterThan"]: 109 ↛ 110line 109 didn't jump to line 110 because the condition on line 109 was never true
110 if Options["GreaterOrEqual"] and Options["GreaterThan"]:
111 utils.fubar(
112 "-g/--greaterorequal and -G/--greaterthan are mutually exclusive."
113 )
114 if not Options["Suite"]:
115 Options["Suite"] = "unstable"
117 highest: str | None = None
118 if Options["GreaterOrEqual"]: 118 ↛ 119line 118 didn't jump to line 119 because the condition on line 118 was never true
119 highest = ">="
120 elif Options["GreaterThan"]: 120 ↛ 121line 120 didn't jump to line 121 because the condition on line 120 was never true
121 highest = ">>"
123 for line in list_packages(
124 packages,
125 suites=utils.split_args_or_none(Options["Suite"]),
126 components=(utils.split_args_or_none(Options["Component"])),
127 architectures=(utils.split_args_or_none(Options["Architecture"])),
128 binary_types=(utils.split_args_or_none(Options["BinaryType"])),
129 source_and_binary=bool(Options["Source-And-Binary"]),
130 regex=bool(Options["Regex"]),
131 format=Options["Format"] or None,
132 highest=highest,
133 ):
134 print(line)