]> git.decadent.org.uk Git - dak.git/blobdiff - dak/make_changelog.py
make-changelog: implement progress option
[dak.git] / dak / make_changelog.py
index dbcbf576c8381c790f697fec0740cddfa45a73e4..7dacf8252afd63f616528099aaa4289edd965110 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,9 @@ 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
+  -p, --progress            display progress status"""
 
     sys.exit(exit_code)
 
@@ -160,7 +162,7 @@ def display_changes(uploads, index):
         print upload[index]
         prev_upload = upload[0]
 
-def export_files(session, archive, clpool):
+def export_files(session, archive, clpool, progress=False):
     """
     Export interesting files from source packages.
     """
@@ -170,15 +172,15 @@ def export_files(session, archive, clpool):
     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, c.name || '/' || f.filename
+    query = """SELECT DISTINCT s.source, su.suite_name AS suite, s.version, c.name || '/' || f.filename AS 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 files_archive_map fam ON f.id = fam.file_id AND fam.archive_id = su.archive_id
                JOIN component c ON fam.component_id = c.id
-               WHERE su.archive = :archive_id
+               WHERE su.archive_id = :archive_id
                ORDER BY s.source, suite"""
 
     for p in session.execute(query, {'archive_id': archive.archive_id}):
@@ -212,6 +214,11 @@ def export_files(session, archive, clpool):
             unpacked = UnpackedSource(p)
             tempdir = unpacked.get_root_directory()
             stats['unpack'] += 1
+            if progress:
+                if stats['unpack'] % 100 == 0:
+                    sys.stderr.write('%d packages unpacked\n' % stats['unpack'])
+                elif stats['unpack'] % 10 == 0:
+                    sys.stderr.write('.')
             for file in files:
                 for f in glob(os.path.join(tempdir, 'debian', '*%s' % file)):
                     for s in unpack[p][1]:
@@ -258,13 +265,14 @@ def main():
     Cnf = utils.get_conf()
     cnf = Config()
     Arguments = [('h','help','Make-Changelog::Options::Help'),
-                 ('a','archive','Make-Changelog::Options::Help','HasArg'),
+                 ('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'),
-                 ('e','export','Make-Changelog::Options::export')]
+                 ('e','export','Make-Changelog::Options::export'),
+                 ('p','progress','Make-Changelog::Options::progress')]
 
-    for i in ['help', 'suite', 'base-suite', 'binnmu', 'export']:
+    for i in ['help', 'suite', 'base-suite', 'binnmu', 'export', 'progress']:
         if not Cnf.has_key('Make-Changelog::Options::%s' % (i)):
             Cnf['Make-Changelog::Options::%s' % (i)] = ''
 
@@ -274,6 +282,7 @@ def main():
     base_suite = Cnf['Make-Changelog::Options::Base-Suite']
     binnmu = Cnf['Make-Changelog::Options::binNMU']
     export = Cnf['Make-Changelog::Options::export']
+    progress = Cnf['Make-Changelog::Options::progress']
 
     if Options['help'] or not (suite and base_suite) and not export:
         usage()
@@ -288,7 +297,7 @@ def main():
         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, archive, exportpath)
+            export_files(session, archive, exportpath, progress)
         else:
             utils.fubar('No changelog export path defined')
     elif binnmu: