]> git.decadent.org.uk Git - dak.git/commitdiff
Merge commit 'twerner/msfl' into merge
authorJoerg Jaspert <joerg@debian.org>
Mon, 2 Nov 2009 21:01:02 +0000 (22:01 +0100)
committerJoerg Jaspert <joerg@debian.org>
Mon, 2 Nov 2009 21:01:02 +0000 (22:01 +0100)
* commit 'twerner/msfl':
  require db schema 23
  add generate-filelist to control script
  add license and reindent file
  add database update script for generate_filelist
  add generate_filelist.py to maybe replace msfl.py

Signed-off-by: Joerg Jaspert <joerg@debian.org>
dak/dak.py
dak/dakdb/update23.py [new file with mode: 0644]
dak/generate_filelist.py [new file with mode: 0755]
dak/update_db.py

index 8840975037e29a42f4ab33a51b6a800ca213c0af..cd42c3ed4bcaa70bd76bd17268c322c3bf43c8b0 100755 (executable)
@@ -74,6 +74,8 @@ def init():
          "Generate lists of packages per suite for apt-ftparchive"),
         ("make-pkg-file-mapping",
          "Generate package <-> file mapping"),
+        ("generate-filelist",
+         "Generate file lists for apt-ftparchive"),
         ("generate-releases",
          "Generate Release files"),
         ("contents",
diff --git a/dak/dakdb/update23.py b/dak/dakdb/update23.py
new file mode 100644 (file)
index 0000000..70f2fc4
--- /dev/null
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+"""
+Add view for new generate_filelist command.
+
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2009  Torsten Werner <twerner@debian.org>
+@license: GNU General Public License version 2 or later
+"""
+
+# 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
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import psycopg2
+
+def do_update(self):
+    print "Add views for generate_filelist to database."
+
+    try:
+        c = self.db.cursor()
+
+        print "Drop old views."
+        c.execute("DROP VIEW IF EXISTS binfiles_suite_component_arch CASCADE")
+        c.execute("DROP VIEW IF EXISTS srcfiles_suite_component CASCADE")
+
+        print "Create new views."
+        c.execute("""
+CREATE VIEW binfiles_suite_component_arch AS
+  SELECT files.filename, binaries.type, location.path, location.component,
+         bin_associations.suite, binaries.architecture
+    FROM binaries
+    JOIN bin_associations ON binaries.id = bin_associations.bin
+    JOIN files ON binaries.file = files.id
+    JOIN location ON files.location = location.id;
+           """)
+        c.execute("""
+CREATE VIEW srcfiles_suite_component AS
+  SELECT files.filename, location.path, location.component,
+         src_associations.suite
+    FROM source
+    JOIN src_associations ON source.id = src_associations.source
+    JOIN files ON source.file = files.id
+    JOIN location ON files.location = location.id;
+           """)
+
+    except psycopg2.InternalError, msg:
+        self.db.rollback()
+        raise DBUpdateError, "Database error, rollback issued. Error message : %s" % (str(msg))
+
diff --git a/dak/generate_filelist.py b/dak/generate_filelist.py
new file mode 100755 (executable)
index 0000000..02f5f18
--- /dev/null
@@ -0,0 +1,143 @@
+#!/usr/bin/python
+
+"""
+Generate file lists for apt-ftparchive.
+
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2009  Torsten Werner <twerner@debian.org>
+@license: GNU General Public License version 2 or later
+"""
+
+# 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
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from daklib.dbconn import *
+from daklib.config import Config
+from daklib import utils
+import apt_pkg, os, sys
+
+def fetch(query, args, session):
+    return [path + filename for (path, filename) in \
+        session.execute(query, args).fetchall()]
+
+def getSources(suite, component, session):
+    query = """
+        SELECT path, filename
+            FROM srcfiles_suite_component
+            WHERE suite = :suite AND component = :component
+    """
+    args = { 'suite': suite.suite_id,
+             'component': component.component_id }
+    return fetch(query, args, session)
+
+def getBinaries(suite, component, architecture, type, session):
+    query = """
+        SELECT path, filename
+            FROM binfiles_suite_component_arch
+            WHERE suite = :suite AND component = :component AND type = :type AND
+                  (architecture = :architecture OR architecture = 2)
+    """
+    args = { 'suite': suite.suite_id,
+             'component': component.component_id,
+             'architecture': architecture.arch_id,
+             'type': type }
+    return fetch(query, args, session)
+
+def listPath(suite, component, architecture = None, type = None):
+    """returns full path to the list file"""
+    suffixMap = { 'deb': "binary-",
+                  'udeb': "debian-installer_binary-" }
+    if architecture:
+        suffix = suffixMap[type] + architecture.arch_string
+    else:
+        suffix = "source"
+    filename = "%s_%s_%s.list" % \
+        (suite.suite_name, component.component_name, suffix)
+    pathname = os.path.join(Config()["Dir::Lists"], filename)
+    return utils.open_file(pathname, "w")
+
+def writeSourceList(suite, component, session):
+    file = listPath(suite, component)
+    for filename in getSources(suite, component, session):
+        file.write(filename + '\n')
+    file.close()
+
+def writeBinaryList(suite, component, architecture, type, session):
+    file = listPath(suite, component, architecture, type)
+    for filename in getBinaries(suite, component, architecture, type, session):
+        file.write(filename + '\n')
+    file.close()
+
+def usage():
+    print """Usage: dak generate_filelist [OPTIONS]
+Create filename lists for apt-ftparchive.
+
+  -s, --suite=SUITE                    act on this suite
+  -c, --component=COMPONENT    act on this component
+  -a, --architecture=ARCH        act on this architecture
+  -h, --help                                 show this help and exit
+
+ARCH, COMPONENT and SUITE can be comma (or space) separated list, e.g.
+    --suite=testing,unstable"""
+    sys.exit()
+
+def main():
+    cnf = Config()
+    Arguments = [('h', "help",         "Filelist::Options::Help"),
+                 ('s', "suite",        "Filelist::Options::Suite", "HasArg"),
+                 ('c', "component",    "Filelist::Options::Component", "HasArg"),
+                 ('a', "architecture", "Filelist::Options::Architecture", "HasArg")]
+    query_suites = DBConn().session().query(Suite)
+    suites = [suite.suite_name for suite in query_suites.all()]
+    if not cnf.has_key('Filelist::Options::Suite'):
+        cnf['Filelist::Options::Suite'] = ','.join(suites)
+    # we can ask the database for components if 'mixed' is gone
+    if not cnf.has_key('Filelist::Options::Component'):
+        cnf['Filelist::Options::Component'] = 'main,contrib,non-free'
+    query_architectures = DBConn().session().query(Architecture)
+    architectures = \
+        [architecture.arch_string for architecture in query_architectures.all()]
+    if not cnf.has_key('Filelist::Options::Architecture'):
+        cnf['Filelist::Options::Architecture'] = ','.join(architectures)
+    cnf['Filelist::Options::Help'] = ''
+    apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
+    Options = cnf.SubTree("Filelist::Options")
+    if Options['Help']:
+        usage()
+    session = DBConn().session()
+    suite_arch = session.query(SuiteArchitecture)
+    for suite_name in utils.split_args(Options['Suite']):
+        suite = query_suites.filter_by(suite_name = suite_name).one()
+        join = suite_arch.filter_by(suite_id = suite.suite_id)
+        for component_name in utils.split_args(Options['Component']):
+            component = session.query(Component).\
+                filter_by(component_name = component_name).one()
+            for architecture_name in utils.split_args(Options['Architecture']):
+                architecture = query_architectures.\
+                    filter_by(arch_string = architecture_name).one()
+                try:
+                    join.filter_by(arch_id = architecture.arch_id).one()
+                    if architecture_name == 'source':
+                        writeSourceList(suite, component, session)
+                    elif architecture_name != 'all':
+                        writeBinaryList(suite, component, architecture, 'deb', session)
+                        writeBinaryList(suite, component, architecture, 'udeb', session)
+                except:
+                    pass
+    # this script doesn't change the database
+    session.rollback()
+
+if __name__ == '__main__':
+    main()
+
index 27b6ad8fd1e8dcf0bccb2fb1f39405ad94d11a72..49a6b584d1fc59ea76f5b2cefde9380b4a6452ca 100755 (executable)
@@ -45,7 +45,7 @@ from daklib.dak_exceptions import DBUpdateError
 ################################################################################
 
 Cnf = None
-required_database_schema = 22
+required_database_schema = 23
 
 ################################################################################