]> git.decadent.org.uk Git - dak.git/blobdiff - dak/make_changelog.py
make-changelog. document --archive option
[dak.git] / dak / make_changelog.py
index 398c3526a54c4f3721be5b7362afc3769c87a3be..9246b40c0640673d0cac85749c6f6dd424f60004 100755 (executable)
@@ -67,7 +67,7 @@ def usage (exit_code=0):
 
        Usage:
        make-changelog -s <suite> -b <base_suite> [OPTION]...
-       make-changelog -e
+       make-changelog -e -a <archive>
 
 Options:
 
@@ -76,7 +76,8 @@ Options:
   -b, --base-suite          suite to be taken as reference for comparison
   -n, --binnmu              display binNMUs uploads instead of source ones
 
-  -e, --export              export interesting files from source packages"""
+  -e, --export              export interesting files from source packages
+  -a, --archive             archive to fetch data from"""
 
     sys.exit(exit_code)
 
@@ -160,24 +161,28 @@ def display_changes(uploads, index):
         print upload[index]
         prev_upload = upload[0]
 
-def export_files(session, pool, clpool, temppath):
+def export_files(session, archive, clpool):
     """
     Export interesting files from source packages.
     """
+    pool = os.path.join(archive.path, 'pool')
 
     sources = {}
     unpack = {}
     files = ('changelog', 'copyright', 'NEWS.Debian', 'README.Debian')
     stats = {'unpack': 0, 'created': 0, 'removed': 0, 'errors': 0, 'files': 0}
-    query = """SELECT DISTINCT s.source, su.suite_name AS suite, s.version, f.filename
+    query = """SELECT DISTINCT s.source, su.suite_name AS suite, s.version, c.name || '/' || f.filename
                FROM source s
                JOIN newest_source n ON n.source = s.source AND n.version = s.version
                JOIN src_associations sa ON sa.source = s.id
                JOIN suite su ON su.id = sa.suite
                JOIN files f ON f.id = s.file
+               JOIN files_archive_map fam ON f.id = fam.file_id AND fam.archive_id = su.id
+               JOIN component c ON fam.component_id = c.id
+               WHERE su.archive_id = :archive_id
                ORDER BY s.source, suite"""
 
-    for p in session.execute(query):
+    for p in session.execute(query, {'archive_id': archive.archive_id}):
         if not sources.has_key(p[0]):
             sources[p[0]] = {}
         sources[p[0]][p[1]] = (re_no_epoch.sub('', p[2]), p[3])
@@ -225,7 +230,7 @@ def export_files(session, pool, clpool, temppath):
                         os.link(version, suite)
                         stats['created'] += 1
             unpacked.cleanup()
-        except Exception, e:
+        except Exception as e:
             print 'make-changelog: unable to unpack %s\n%s' % (p, e)
             stats['errors'] += 1
 
@@ -254,6 +259,7 @@ def main():
     Cnf = utils.get_conf()
     cnf = Config()
     Arguments = [('h','help','Make-Changelog::Options::Help'),
+                 ('a','archive','Make-Changelog::Options::Archive','HasArg'),
                  ('s','suite','Make-Changelog::Options::Suite','HasArg'),
                  ('b','base-suite','Make-Changelog::Options::Base-Suite','HasArg'),
                  ('n','binnmu','Make-Changelog::Options::binNMU'),
@@ -263,8 +269,8 @@ def main():
         if not Cnf.has_key('Make-Changelog::Options::%s' % (i)):
             Cnf['Make-Changelog::Options::%s' % (i)] = ''
 
-    apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
-    Options = Cnf.SubTree('Make-Changelog::Options')
+    apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
+    Options = Cnf.subtree('Make-Changelog::Options')
     suite = Cnf['Make-Changelog::Options::Suite']
     base_suite = Cnf['Make-Changelog::Options::Base-Suite']
     binnmu = Cnf['Make-Changelog::Options::binNMU']
@@ -281,8 +287,9 @@ def main():
 
     if export:
         if cnf.exportpath:
+            archive = session.query(Archive).filter_by(archive_name=Options['Archive']).one()
             exportpath = os.path.join(Cnf['Dir::Export'], cnf.exportpath)
-            export_files(session, Cnf['Dir::Pool'], exportpath, Cnf['Dir::TempPath'])
+            export_files(session, archive, exportpath)
         else:
             utils.fubar('No changelog export path defined')
     elif binnmu: