import daklib.daksql as daksql
from daklib.dbconn import DBConn, session_wrapper
+from collections import defaultdict
+
@session_wrapper
def list_packages(packages, suites=None, components=None, architectures=None, binary_types=None,
result = session.execute(query)
for row in result:
yield "{0} {1} {2}".format(row[t.c.package], row[t.c.version], row[t.c.architecture])
+ elif format == "python":
+ c_architectures = daksql.string_agg(t.c.architecture, ',', order_by=[t.c.architecture_is_source.desc(), t.c.architecture])
+ query = sql.select([t.c.package,
+ t.c.version,
+ t.c.display_suite,
+ c_architectures,
+ t.c.source,
+ t.c.source_version,
+ t.c.component]) \
+ .where(where) \
+ .group_by(t.c.package,
+ t.c.version,
+ t.c.display_suite,
+ t.c.source,
+ t.c.component,
+ t.c.source_version)
+ result = session.execute(query).fetchall()
+
+ if len(result) == 0:
+ raise StopIteration
+
+ val = lambda: defaultdict(val)
+ ret = val()
+ for row in result:
+ ret[row[t.c.package]] \
+ [row[t.c.display_suite]] \
+ [row[t.c.version]]={'component': row[t.c.component],
+ 'architectures': row[c_architectures].split(','),
+ 'source': row[t.c.source],
+ 'source_version': row[t.c.source_version]
+ }
+
+ yield ret
+ return
else:
raise ValueError("Unknown output format requested.")
kwargs['source_and_binary'] = True
#if 'r' in r.query:
# kwargs['regex'] = True
+ format = r.query.get('f', None)
+ if format is not None:
+ kwargs['format'] = 'python'
result = list_packages(packages, **kwargs)
- bottle.response.content_type = 'text/plain'
- for row in result:
- yield row
- yield "\n"
+ if format is None:
+ bottle.response.content_type = 'text/plain'
+ for row in result:
+ yield row
+ yield "\n"
+ else:
+ yield json.dumps(list(result))
+
QueryRegister().register_path('/madison', madison)