1 """List packages according to various criteria
3 @copyright: 2014, Ansgar Burchardt <ansgar@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 import sqlalchemy.sql as sql
22 import daklib.daksql as daksql
24 from daklib.dbconn import DBConn, session_wrapper
27 def list_packages(packages, suites=None, components=None, architectures=None, binary_types=None,
28 source_and_binary=False, regex=False,
29 format=None, highest=None,
31 t = DBConn().view_package_list
33 comparison_operator = "~" if regex else "="
36 for package in packages:
37 where = where | t.c.package.op(comparison_operator)(package)
39 where = where | t.c.source.op(comparison_operator)(package)
41 if suites is not None:
42 where = where & t.c.suite.in_(suites)
43 if components is not None:
44 where = where & t.c.component.in_(components)
45 if architectures is not None:
46 where = where & t.c.architecture.in_(architectures)
47 if binary_types is not None:
48 where = where & t.c.type.in_(binary_types)
51 c_architectures = daksql.string_agg(t.c.architecture, ', ', order_by=[t.c.architecture_is_source.desc(), t.c.architecture])
52 query = sql.select([t.c.package, t.c.version, t.c.display_suite, c_architectures]) \
54 .group_by(t.c.package, t.c.version, t.c.display_suite) \
55 .order_by(t.c.package, t.c.version, t.c.display_suite)
56 result = session.execute(query).fetchall()
62 'package': max(10, max(len(row[t.c.package]) for row in result)),
63 'version': max(13, max(len(row[t.c.version]) for row in result)),
64 'suite': max(10, max(len(row[t.c.display_suite]) for row in result))
66 format = "{0:{lengths[package]}} | {1:{lengths[version]}} | {2:{lengths[suite]}} | {3}"
69 yield format.format(row[t.c.package], row[t.c.version], row[t.c.display_suite], row[c_architectures], lengths=lengths)
70 elif format in ('control-suite', 'heidi'):
71 query = sql.select([t.c.package, t.c.version, t.c.architecture]).where(where)
72 result = session.execute(query)
74 yield "{0} {1} {2}".format(row[t.c.package], row[t.c.version], row[t.c.architecture])
76 raise ValueError("Unknown output format requested.")
78 if highest is not None:
79 query = sql.select([t.c.package, sql.func.max(t.c.version)]).where(where) \
80 .group_by(t.c.package).order_by(t.c.package)
81 result = session.execute(query)
84 yield "{0} ({1} {2})".format(row[0], highest, row[1])