]> code.delx.au - gnu-emacs-elpa/blobdiff - admin/forward-diffs.py
Update AUCTeX ELPA package to the new 11.87 release.
[gnu-emacs-elpa] / admin / forward-diffs.py
index 52a73fccfa155639962f0f30adac8306ea8693e7..67c7d8a53fe9f61db7076a5746e63e1937cea1f2 100755 (executable)
@@ -1,5 +1,5 @@
 #!/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.
 
@@ -20,7 +20,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:
 ## 1) Create the maintfile (really this is just an optimization):
 ## forward-diffs.py --create -p packagesdir -m maintfile
 
+## You can start with an empty maintfile and normal operation in 2)
+## will append information as needed.
+
 ## 2) Call from eg procmail to forward diffs.  Example usage:
 
 ## :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 
 
 ## packagedir = /path/to/packages
 ## sender = your email address
 ## logfile = file to write log to (you might want to rotate/compress/examine it)
-## maintfile = file listing packages and their maintainers, with format:
+## maintfile = file listing files and their maintainers, with format:
 ##
-## package1   email1
-## package2   email2,email3
+## 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:
 
@@ -143,7 +150,8 @@ def scan_dir(dir, outfile=None):
             scan_file(path, maints)
             ## This would skip printing empty maints.
             ## That would mean we would scan the file each time for no reason.
-##            if not maints: continue
+            ## But empty maintainers are an error at present.
+            if not maints: continue
             path = re.sub( '^%s' % dir, '', path )
             string = "%-50s %s\n" % (path, ",".join(maints))
             if fd:
@@ -155,8 +163,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 )
@@ -172,6 +181,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=False,
+                   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,
@@ -219,13 +236,14 @@ except Exception as err:
     lfile.write('Error opening maintfile: %s\n' % str(err))
     sys.exit(1)
 
-## Each element is package: maint1, maint2, ...
+## Each element is package/file: maint1, maint2, ...
 maints = {}
 
 for line in mfile:
     if re.match( '#| *$', line ): continue
-    (pack, maint) = line.split()
-    maints[pack] = maint.split(',')
+    ## FIXME error here if empty maintainer.
+    (pfile, maint) = line.split()
+    maints[pfile] = maint.split(',')
 
 mfile.close()
 
@@ -239,8 +257,8 @@ if opts.overmaintfile:
 
     for line in ofile:
         if re.match( '#| *$', line ): continue
-        (pack, maint) = line.split()
-        maints[pack] = maint.split(',')
+        (pfile, maint) = line.split()
+        maints[pfile] = maint.split(',')
 
     ofile.close()
 
@@ -250,7 +268,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 )
 
@@ -266,7 +284,7 @@ if resent_via == message['x-resent-via']:
 
 
 start = False
-packs_seen = []
+pfiles_seen = []
 maints_seen = []
 
 for line in text.splitlines():
@@ -277,30 +295,70 @@ for line in text.splitlines():
 
     if not start: continue
 
-    if re.match( ' *$', line ): break
-
+    ## An empty line or a line with non-empty first character.
+    if re.match( '( *$|[^ ])', line ): break
 
-    reg = re.match( 'packages/([^/]+)', line.strip() )
-    if not reg: break
 
+    if opts.prefix:
+        reg = re.match( '%s([^ ]+)' % opts.prefix, line.strip() )
+        if not reg: continue
+        pfile = reg.group(1)
+    else:
+        pfile = line.strip()
 
-    pack = reg.group(1)
 
-    lfile.write('Package: %s\n' % pack)
+    lfile.write('File: %s\n' % pfile)
 
-    if pack in packs_seen:
-        lfile.write('Already seen this package\n')
+    ## Should not be possible for files (rather than packages)...
+    if pfile in pfiles_seen:
+        lfile.write('Already seen this file\n')
         continue
 
-    packs_seen.append(pack)
+    pfiles_seen.append(pfile)
 
 
-    if not pack in maints:
+    if not pfile in maints:
+
         lfile.write('Unknown maintainer\n')
+
+        if not opts.noscan:
+
+            lfile.write('Scanning file...\n')
+            thismaint = []
+            thisfile = os.path.join( opts.packagedir, pfile )
+            scan_file( thisfile, thismaint )
+
+            if 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))
+
+    ## 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[pack]:
+    for maint in maints[pfile]:
 
         lfile.write('Maint: %s\n' % maint)