Coverage for dak/ls.py: 70%
33 statements
« prev ^ index » next coverage.py v7.6.0, created at 2026-01-04 16:18 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2026-01-04 16:18 +0000
1#! /usr/bin/env python3
3"""
4Display 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
10"""
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?
29# <aj> dunno
30# <aj> maybe he can turn invisible? that'd sure help with improved transparency!
32################################################################################
34import sys
36import apt_pkg
38from daklib import utils
39from daklib.config import Config
40from daklib.ls import list_packages
42################################################################################
45def usage(exit_code=0):
46 print(
47 """Usage: dak ls [OPTION] PACKAGE[...]
48Display information about PACKAGE(s).
50 -a, --architecture=ARCH only show info for ARCH(s)
51 -b, --binary-type=TYPE only show info for binary TYPE
52 -c, --component=COMPONENT only show info for COMPONENT(s)
53 -g, --greaterorequal show buildd 'dep-wait pkg >= {highest version}' info
54 -G, --greaterthan show buildd 'dep-wait pkg >> {highest version}' info
55 -h, --help show this help and exit
56 -r, --regex treat PACKAGE as a regex
57 -s, --suite=SUITE only show info for this suite
58 -S, --source-and-binary show info for the binary children of source pkgs
59 -f, --format=control-suite use same format as control-suite for output
61ARCH, COMPONENT and SUITE can be comma (or space) separated lists, e.g.
62 --architecture=amd64,i386"""
63 )
64 sys.exit(exit_code)
67################################################################################
70def main():
71 cnf = Config()
73 Arguments = [
74 ("a", "architecture", "Ls::Options::Architecture", "HasArg"),
75 ("b", "binarytype", "Ls::Options::BinaryType", "HasArg"),
76 ("c", "component", "Ls::Options::Component", "HasArg"),
77 ("f", "format", "Ls::Options::Format", "HasArg"),
78 ("g", "greaterorequal", "Ls::Options::GreaterOrEqual"),
79 ("G", "greaterthan", "Ls::Options::GreaterThan"),
80 ("r", "regex", "Ls::Options::Regex"),
81 ("s", "suite", "Ls::Options::Suite", "HasArg"),
82 ("S", "source-and-binary", "Ls::Options::Source-And-Binary"),
83 ("h", "help", "Ls::Options::Help"),
84 ]
85 for i in [
86 "architecture",
87 "binarytype",
88 "component",
89 "format",
90 "greaterorequal",
91 "greaterthan",
92 "regex",
93 "suite",
94 "source-and-binary",
95 "help",
96 ]:
97 key = "Ls::Options::%s" % i
98 if key not in cnf: 98 ↛ 85line 98 didn't jump to line 85
99 cnf[key] = ""
101 packages = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) # type: ignore[attr-defined]
102 Options = cnf.subtree("Ls::Options")
104 if Options["Help"]:
105 usage()
106 if not packages: 106 ↛ 107line 106 didn't jump to line 107 because the condition on line 106 was never true
107 utils.fubar("need at least one package name as an argument.")
109 # Handle buildd maintenance helper options
110 if Options["GreaterOrEqual"] or Options["GreaterThan"]: 110 ↛ 111line 110 didn't jump to line 111 because the condition on line 110 was never true
111 if Options["GreaterOrEqual"] and Options["GreaterThan"]:
112 utils.fubar(
113 "-g/--greaterorequal and -G/--greaterthan are mutually exclusive."
114 )
115 if not Options["Suite"]:
116 Options["Suite"] = "unstable"
118 highest: str | None = None
119 if Options["GreaterOrEqual"]: 119 ↛ 120line 119 didn't jump to line 120 because the condition on line 119 was never true
120 highest = ">="
121 elif Options["GreaterThan"]: 121 ↛ 122line 121 didn't jump to line 122 because the condition on line 121 was never true
122 highest = ">>"
124 for line in list_packages(
125 packages,
126 suites=utils.split_args_or_none(Options["Suite"]),
127 components=(utils.split_args_or_none(Options["Component"])),
128 architectures=(utils.split_args_or_none(Options["Architecture"])),
129 binary_types=(utils.split_args_or_none(Options["BinaryType"])),
130 source_and_binary=bool(Options["Source-And-Binary"]),
131 regex=bool(Options["Regex"]),
132 format=Options["Format"] or None,
133 highest=highest,
134 ):
135 print(line)
138######################################################################################
141if __name__ == "__main__":
142 main()