]> git.decadent.org.uk Git - dak.git/blobdiff - dak/make_pkg_file_mapping.py
auto-decruft: Disable short options for NVI
[dak.git] / dak / make_pkg_file_mapping.py
index 1eb0f899740e5a21ef0ced357115af2aed937664..f52836f8b2c32881cc0f894a79411115d717ee01 100755 (executable)
@@ -1,25 +1,15 @@
 #!/usr/bin/env python
 
-import os
-import pg
-import sys
-from daklib import database
-from daklib import utils
-
-################################################################################
+"""
+Prints out, for every file in the pool, which source package and version it
+belongs to and for binary packages additionally which arch, binary package
+and binary package version it has in a standard rfc2822-like format.
 
-projectB = None #: database connection, pgobject
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2009  Peter Palfrader <peter@palfrader.org>
+@license: GNU General Public License version 2 or later
+"""
 
-################################################################################
-
-# Usage: dak make-pkg_file_mapping
-#
-# Prints out, for every file in the pool, which source package and version it
-# belongs to and for binary packages additionally which arch, binary package
-# and binary package version it has in a standard rfc2822-like format.
-
-# Copyright 2009 Peter Palfrader <peter@palfrader.org>
-#
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or
@@ -34,9 +24,20 @@ projectB = None #: database connection, pgobject
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+
 ################################################################################
 
-def build_mapping():
+# <arma> it's crypto -- think of it like magic if you like.
+
+################################################################################
+
+import sys
+
+from daklib.dbconn import *
+
+################################################################################
+
+def build_mapping(archive, session):
     # The ORDER BY is in the queries so that compression of the output works
     # better.  It's the difference between a 9 megabyte bzip2 and a 2.5 mb
     # bzip2 file.
@@ -45,11 +46,15 @@ def build_mapping():
     SELECT
         source.source,
         source.version,
-        './pool/' || files.filename AS path
+        './pool/' || component.name || '/' || files.filename AS path
     FROM source
       JOIN dsc_files ON source.id=dsc_files.source
       JOIN files ON files.id=dsc_files.file
-    ORDER BY source, version
+      JOIN files_archive_map ON files.id = files_archive_map.file_id
+      JOIN component ON files_archive_map.component_id = component.id
+      JOIN files_archive_map fam_dsc ON fam_dsc.file_id=source.file AND fam_dsc.component_id=component.id AND fam_dsc.archive_id=files_archive_map.archive_id
+    WHERE files_archive_map.archive_id = :archive_id
+    ORDER BY source, version, component.id, files.filename
     """
 
     query_binaries = """
@@ -57,25 +62,28 @@ def build_mapping():
         source.source,
         source.version,
         architecture.arch_string AS arch,
-        './pool/' || files.filename AS path,
+        './pool/' || component.name || '/' || files.filename AS path,
         binaries.package,
         binaries.version AS bin_version
     FROM source
       JOIN binaries ON source.id=binaries.source
       JOIN files ON binaries.file=files.id
+      JOIN files_archive_map ON files.id = files_archive_map.file_id
+      JOIN component ON files_archive_map.component_id = component.id
       JOIN architecture ON architecture.id=binaries.architecture
+    WHERE files_archive_map.archive_id = :archive_id
     ORDER BY source, version, package, bin_version
     """
 
-    for i in projectB.query(query_sources).getresult():
-        (source, version, path) = i
+    for row in session.execute(query_sources, {'archive_id': archive.archive_id}).fetchall():
+        (source, version, path) = row
         print "Path: %s"%path
         print "Source: %s"%source
         print "Source-Version: %s"%version
         print
 
-    for i in projectB.query(query_binaries).getresult():
-        (source, version, arch, path, bin, binv) = i
+    for row in session.execute(query_binaries, {'archive_id': archive.archive_id}).fetchall():
+        (source, version, arch, path, bin, binv) = row
         print "Path: %s"%path
         print "Source: %s"%source
         print "Source-Version: %s"%version
@@ -86,12 +94,21 @@ def build_mapping():
 
 ################################################################################
 
+def usage():
+    print "usage: dak make-pkg-file-mapping <archive>"
+    sys.exit(0)
+
+################################################################################
+
 def main():
-    global projectB
+    if len(sys.argv) != 2:
+        usage()
+
+    archive_name = sys.argv[1]
 
-    Cnf = utils.get_conf()
-    projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
-    build_mapping()
+    session = DBConn().session()
+    archive = session.query(Archive).filter_by(archive_name=archive_name).one()
+    build_mapping(archive, session)
 
 #########################################################################################