]> code.delx.au - gnu-emacs-elpa/blobdiff - admin/forward-diffs.py
* README: Update for new "Version: 0" convention.
[gnu-emacs-elpa] / admin / forward-diffs.py
index 45bc9ac5dfae2a196b7b001ad98b31c6a840e4e5..c0c330d230b554fd899cb87bf819a85dba495e73 100755 (executable)
@@ -1,9 +1,10 @@
 #!/usr/bin/python
-### forward-diffs.py --- forward emacs-elpa-diffs mails to maintainers
+### forward-diffs.py --- forward emacs-diffs mails to maintainers
 
-## Copyright (C) 2012 Free Software Foundation, Inc.
+## Copyright (C) 2012-2014 Free Software Foundation, Inc.
 
 ## Author: Glenn Morris <rgm@gnu.org>
+## Maintainer: emacs-devel@gnu.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
@@ -20,7 +21,7 @@
 
 ### Commentary:
 
-## Forward emails from the emacs-elpa-diffs mailing list to the
+## Forward emails from an emacs-diffs style mailing list to the
 ## maintainer(s) of the modified files.
 
 ## Two modes of operation:
@@ -35,7 +36,8 @@
 
 ## :0c
 ## * ^TO_emacs-elpa-diffs@gnu\.org
-## | forward-diffs.py -p packagedir -m maintfile -l logfile -s sender
+## | forward-diffs.py -p packagedir -m maintfile -l logfile \
+## -o overmaint -s sender
 
 ## where 
 
 ##
 ## package1/file1   email1
 ## package2/file2   email2,email3
+## package3         email4
 ##
 ## Use "nomail" for the email field to not send a mail.
+## An entry that is a directory applies to all files in that directory
+## that do not have specific maintainers.
 ##
-## overmaintfile = like maintfile, but takes precedence over it.
+## overmaint = like maintfile, but takes precedence over it.
 
 ### Code:
 
@@ -159,8 +164,9 @@ def scan_dir(dir, outfile=None):
 
 
 usage="""usage: %prog <-p /path/to/packages> <-m maintfile>
-   <-l logfile -s sender|--create> [-o overmaintfile] [--sendmail] [--debug]
-Take a GNU ELPA diff on stdin, and forward it to the maintainer(s)."""
+   <-l logfile -s sender|--create> [-o overmaintfile] [--prefix prefix]
+   [--sendmail] [--debug]
+Take an emacs-diffs mail on stdin, and forward it to the maintainer(s)."""
 
 parser = optparse.OptionParser()
 parser.set_usage ( usage )
@@ -176,6 +182,14 @@ parser.add_option( "-s", dest="sender", default=None,
                    help="sender address for forwards")
 parser.add_option( "--create", dest="create", default=False,
                    action="store_true", help="create maintfile")
+parser.add_option( "--no-scan", dest="noscan", default=True,
+                   action="store_true",
+                   help="don't scan for maintainers; implies --no-update")
+parser.add_option( "--no-update", dest="noupdate", default=False,
+                   action="store_true",
+                   help="do not update the maintfile")
+parser.add_option( "--prefix", dest="prefix", default="packages/",
+                   help="prefix to remove from modified file name [default: %default]")
 parser.add_option( "--sendmail", dest="sendmail", default=False,
                    action="store_true", help="use sendmail rather than smtp")
 parser.add_option( "--debug", dest="debug", default=False,
@@ -204,12 +218,6 @@ if not opts.create:
         parser.error('No sender specified')
 
 
-## Create the maintfile.
-if opts.create:
-    scan_dir( opts.packagedir, opts.maintfile )
-    sys.exit()
-
-
 try:
     lfile = open( opts.logfile, 'a' )
 except Exception as err:
@@ -223,6 +231,12 @@ except Exception as err:
     lfile.write('Error opening maintfile: %s\n' % str(err))
     sys.exit(1)
 
+## Create the maintfile.
+if opts.create:
+    scan_dir( opts.packagedir, opts.maintfile )
+    sys.exit()
+
+
 ## Each element is package/file: maint1, maint2, ...
 maints = {}
 
@@ -255,7 +269,7 @@ stdin = sys.stdin
 text = stdin.read()
 
 
-resent_via = 'GNU ELPA diff forwarder'
+resent_via = 'GNU Emacs diff forwarder'
 
 message = email.message_from_string( text )
 
@@ -276,20 +290,42 @@ maints_seen = []
 
 for line in text.splitlines():
 
-    if re.match( 'modified:$', line ):
+    # Look for and process things that look like (Git):
+    #
+    # Summary of changes:
+    #  packages/vlf/vlf.el |    2 +-
+    #  1 files changed, 1 insertions(+), 1 deletions(-)
+    #
+    # or things that look like (Git):
+    #
+    # ---
+    #  packages/vlf/vlf.el |    2 +-
+    #  1 files changed, 1 insertions(+), 1 deletions(-)
+
+    #BZR: if re.match( 'modified:$', line ):
+    if re.match( '---|Summary of changes:$', line ):
         start = True
         continue
 
     if not start: continue
 
-    if re.match( ' *$', line ): break
-
-
-    reg = re.match( 'packages/([^ ]+)', line.strip() )
-    if not reg: break
-
+    ## An empty line or a line with non-empty first character.
+    if re.match( '( *$|[^ ])', line ): break
+    # Any line that doesn't match the diffstat format (Git).
+    if not re.match( ' [^ ]+ +\| ', line ):
+        lfile.write('Stop scanning at: %s\n' % line)
+        break
+
+    if opts.prefix:
+        #BZR: reg = re.match( '%s([^ ]+)' % opts.prefix, line.strip() )
+        reg = re.match( ' %s([^ ]+)' % opts.prefix, line )
+        if not reg:
+            lfile.write('Skip: %s\n' % line)
+            continue
+        pfile = reg.group(1)
+    else:
+        pfile = line.strip()
 
-    pfile = reg.group(1)
 
     lfile.write('File: %s\n' % pfile)
 
@@ -303,26 +339,43 @@ for line in text.splitlines():
 
     if not pfile in maints:
 
-        lfile.write('Unknown maintainer, scanning file...\n')
+        lfile.write('Unknown maintainer\n')
 
-        thismaint = []
-        thisfile = os.path.join( opts.packagedir, pfile )
+        if not opts.noscan:
 
-        scan_file( thisfile, thismaint )
+            lfile.write('Scanning file...\n')
+            thismaint = []
+            thisfile = os.path.join( opts.packagedir, pfile )
+            # scan_file( thisfile, thismaint )
 
-        if not thismaint: continue
+            if thismaint:
+                maints[pfile] = thismaint
 
-        maints[pfile] = thismaint
+                ## Append maintainer to file.
+                if not opts.noupdate:
+                    try:
+                        mfile = open( opts.maintfile, 'a' )
+                        string = "%-50s %s\n" % (pfile, ",".join(thismaint))
+                        mfile.write(string)
+                        mfile.close()
+                        lfile.write('Appended to maintfile\n')
+                    except Exception as err:
+                        lfile.write('Error appending to maintfile: %s\n' % 
+                                    str(err))
 
-        ## Append maintainer to file.
-        try:
-            mfile = open( opts.maintfile, 'a' )
-            string = "%-50s %s\n" % (pfile, ",".join(thismaint))
-            mfile.write(string)
-            mfile.close()
-            lfile.write('Appended to maintfile\n')
-        except Exception as err:
-            lfile.write('Error appending to maintfile: %s\n' % str(err))
+    ## Didn't scan, or scanning did not work.
+    ## Look for a directory maintainer.
+    if not pfile in maints:
+        lfile.write('No file maintainer, trying directories...\n')
+        while True:
+            (pfile, tail) = os.path.split(pfile)
+            if not pfile: break
+            if pfile in maints: break
+
+
+    if not pfile in maints:
+        lfile.write('No maintainer, skipping\n')
+        continue
 
 
     for maint in maints[pfile]: