]> git.decadent.org.uk Git - dak.git/blob - dak/ls.py
Use correct db_name for MD5 hash
[dak.git] / dak / ls.py
1 #!/usr/bin/env python
2
3 """
4 Display information about package(s) (suite, version, etc.)
5
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
9
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.
15
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.
20
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
24
25 ################################################################################
26
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!
31
32 ################################################################################
33
34 import os
35 import sys
36 import apt_pkg
37
38 from daklib.config import Config
39 from daklib.ls import list_packages
40 from daklib import utils
41
42 ################################################################################
43
44 def usage (exit_code=0):
45     print """Usage: dak ls [OPTION] PACKAGE[...]
46 Display information about PACKAGE(s).
47
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
57   -f, --format=control-suite use same format as control-suite for output
58
59 ARCH, COMPONENT and SUITE can be comma (or space) separated lists, e.g.
60     --architecture=amd64,i386"""
61     sys.exit(exit_code)
62
63 ################################################################################
64
65 def main ():
66     cnf = Config()
67
68     Arguments = [('a', "architecture", "Ls::Options::Architecture", "HasArg"),
69                  ('b', "binarytype", "Ls::Options::BinaryType", "HasArg"),
70                  ('c', "component", "Ls::Options::Component", "HasArg"),
71                  ('f', "format", "Ls::Options::Format", "HasArg"),
72                  ('g', "greaterorequal", "Ls::Options::GreaterOrEqual"),
73                  ('G', "greaterthan", "Ls::Options::GreaterThan"),
74                  ('r', "regex", "Ls::Options::Regex"),
75                  ('s', "suite", "Ls::Options::Suite", "HasArg"),
76                  ('S', "source-and-binary", "Ls::Options::Source-And-Binary"),
77                  ('h', "help", "Ls::Options::Help")]
78     for i in [ "architecture", "binarytype", "component", "format",
79                "greaterorequal", "greaterthan", "regex", "suite",
80                "source-and-binary", "help" ]:
81         if not cnf.has_key("Ls::Options::%s" % (i)):
82             cnf["Ls::Options::%s" % (i)] = ""
83
84     packages = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
85     Options = cnf.subtree("Ls::Options")
86
87     if Options["Help"]:
88         usage()
89     if not packages:
90         utils.fubar("need at least one package name as an argument.")
91
92     # If cron.daily is running; warn the user that our output might seem strange
93     if os.path.exists(os.path.join(cnf["Dir::Lock"], "daily.lock")):
94         utils.warn("Archive maintenance is in progress; database inconsistencies are possible.")
95
96     # Handle buildd maintenance helper options
97     if Options["GreaterOrEqual"] or Options["GreaterThan"]:
98         if Options["GreaterOrEqual"] and Options["GreaterThan"]:
99             utils.fubar("-g/--greaterorequal and -G/--greaterthan are mutually exclusive.")
100         if not Options["Suite"]:
101             Options["Suite"] = "unstable"
102
103     kwargs = dict()
104
105     if Options["Regex"]:
106         kwargs['regex'] = True
107     if Options["Source-And-Binary"]:
108         kwargs['source_and_binary'] = True
109     if Options["Suite"]:
110         kwargs['suites'] = utils.split_args(Options['Suite'])
111     if Options["Architecture"]:
112         kwargs['architectures'] = utils.split_args(Options['Architecture'])
113     if Options['BinaryType']:
114         kwargs['binary_types'] = utils.split_args(Options['BinaryType'])
115     if Options['Component']:
116         kwargs['components'] = utils.split_args(Options['Component'])
117
118     if Options['Format']:
119         kwargs['format'] = Options['Format']
120     if Options['GreaterOrEqual']:
121         kwargs['highest'] = '>='
122     elif Options['GreaterThan']:
123         kwargs['highest'] = '>>'
124
125     for line in list_packages(packages, **kwargs):
126         print line
127
128 ######################################################################################
129
130 if __name__ == '__main__':
131     main()