Coverage for dak/ls.py: 70%

33 statements  

« 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.) 

3 

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 

7 

8""" 

9 

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. 

14 

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. 

19 

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 

23 

24################################################################################ 

25 

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! 

30 

31################################################################################ 

32 

33import sys 

34 

35import apt_pkg 

36 

37from daklib import utils 

38from daklib.config import Config 

39from daklib.ls import list_packages 

40 

41################################################################################ 

42 

43 

44def usage(exit_code=0): 

45 print( 

46 """Usage: dak ls [OPTION] PACKAGE[...] 

47Display information about PACKAGE(s). 

48 

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 

59 

60ARCH, COMPONENT and SUITE can be comma (or space) separated lists, e.g. 

61 --architecture=amd64,i386""" 

62 ) 

63 sys.exit(exit_code) 

64 

65 

66################################################################################ 

67 

68 

69def main(): 

70 cnf = Config() 

71 

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] = "" 

99 

100 packages = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) # type: ignore[attr-defined] 

101 Options = cnf.subtree("Ls::Options") 

102 

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.") 

107 

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" 

116 

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 = ">>" 

122 

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)