[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1362809586-18477-1-git-send-email-raphael.scarv@gmail.com>
Date: Sat, 9 Mar 2013 03:13:06 -0300
From: "Raphael S. Carvalho" <raphael.scarv@...il.com>
To: unlisted-recipients:; (no To-header on input)
Cc: linux-kernel@...r.kernel.org,
"Raphael S. Carvalho" <raphael.scarv@...il.com>
Subject: [PATCH 1/1] scripts/gen_sendmail.py: Script Added: Generate git send-email arguments automatically!
I guess this script won't be merged upstream, but I think it could be useful for someone else.
Description borrowed from the header:
---------------
!# This script generates the git send-email automatically
!# by looking at the output generated by scripts/get_maintainer.pl
!#
!# You can pass as many patch files as needed.
!# Usage: python send-mail.py [option] <patch1> <patch2> ...
Example of use:
Passed as arguments one patch file and -v (verbose mode).
---------------
raphaelsc@...ian:~/kernel/linux$ scripts/gen_sendmail.py -v 0001-kernel-pid.c-Improve-flow-of-a-loop-inside-alloc_pid.patch
git send-email --from "Raphael S. Carvalho <raphael.scarv@...il.com>" --to "Eric W. Biederman <ebiederm@...ssion.com>" --to "Andrew Morton <akpm@...ux-foundation.org>" --to "Serge E. Hallyn <serge@...lyn.com>" --to "Serge Hallyn <serge.hallyn@...onical.com>" --to "David S. Miller <davem@...emloft.net>" --cc "linux-kernel@...r.kernel.org" 0001-kernel-pid.c-Improve-flow-of-a-loop-inside-alloc_pid.patch
* Statistics: Maintainer(s): 5, List(s): 1
---------------
Any bug reports or improvements are welcome!
Signed-off-by: Raphael S. Carvalho <raphael.scarv@...il.com>
---
scripts/gen_sendmail.py | 165 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 165 insertions(+), 0 deletions(-)
create mode 100755 scripts/gen_sendmail.py
diff --git a/scripts/gen_sendmail.py b/scripts/gen_sendmail.py
new file mode 100755
index 0000000..921a8cc
--- /dev/null
+++ b/scripts/gen_sendmail.py
@@ -0,0 +1,165 @@
+#! /usr/bin/env python
+#
+# Generate git send-email arguments (gen_sendmail.py)
+# (c) 2013, Raphael S.Carvalho <raphael.scarv@...il.com>
+#
+# This script generates the git send-email automatically
+# by looking at the output generated by scripts/get_maintainer.pl
+#
+# You can pass as many patch files as needed.
+# Usage: python send-mail.py [options] <patch1> <patch2> ...
+#
+# Licensed under the terms of the GNU GPL License version 2
+
+import commands
+import sys
+import StringIO
+import getopt
+
+# Default definitions
+GIT_SENDMAIL = "git send-email"
+SCRIPT = "scripts/get_maintainer.pl"
+
+
+def get_user_gitconfig(git_config):
+ get_name = "git config user.name"
+ get_email = "git config user.email"
+
+ (stat, name) = commands.getstatusoutput(get_name)
+ if (stat != 0):
+ return (stat, get_name)
+
+ (stat, email) = commands.getstatusoutput(get_email)
+ if (stat != 0):
+ return (stat, get_email)
+
+ # Setup git config structure!
+ git_config['user_name'] = name
+ git_config['user_email'] = email
+
+ return (0, None)
+
+
+# Try to execute: get_maintainer.pl <patch>
+def exec_get_maintainers(patch_name):
+ command = SCRIPT + ' ' + patch_name
+ (stat, output) = commands.getstatusoutput(command)
+ return (stat, output)
+
+
+def find_maintainer(maintainers, email):
+ for m in maintainers:
+ if m['email'] == email:
+ return True
+ return False
+
+
+# Get file and/or mail from each line,
+# and build a simple maintainers database.
+def build_list(buf):
+ maintainers = []
+
+ for line in iter(buf.readline, ""):
+ name = ""
+ email = ""
+
+ pos = line.find("<")
+ if pos != -1:
+ name = line[: pos-1].replace('"', "")
+ pos2 = line.find("(")
+ email = line[pos : pos2-1]
+ else:
+ pos = line.find("(")
+ email = line[: pos-1]
+
+ # If not find_maintainer, then add to the list.
+ if not find_maintainer(maintainers, email):
+ maintainer = {'name': name, 'email': email}
+ maintainers.append(maintainer)
+
+ return maintainers
+
+
+# Generates command from the built database.
+def generate_gitmail_cmd(maintainers, git_config, args):
+ mnt_count = list_count = 0
+
+ print '%s --from "%s <%s>"' % \
+ (GIT_SENDMAIL, \
+ git_config['user_name'], git_config['user_email']),
+
+ for m in maintainers:
+ if m['name'] != "":
+ print '--to "%s %s"' % (m['name'], m['email']),
+ mnt_count += 1
+ else:
+ print '--cc "%s"' % m['email'],
+ list_count += 1
+ for arg in args:
+ print arg,
+
+ return (mnt_count, list_count)
+
+
+def usage(program):
+ print 'Usage: %s [options] <patch(es) file>\n' \
+ '-v --verbose: Print verbose messages.\n' \
+ '-h --help: Print this information.\n\n' \
+ 'This script must be installed in the directory' \
+ ' scripts of linux tree!' % program,
+ sys.exit(2)
+
+
+def main(argc, argv):
+ verbose = False
+
+ try:
+ opts, args = getopt.getopt(argv[1:], 'hv', ['help', 'verbose'])
+ if not opts and argc < 2:
+ usage(argv[0])
+ except getopt.GetoptError, e:
+ print e
+ usage(argv[0])
+
+ arg_count = 1 # program name: argv[0]
+ for opt, arg in opts:
+ arg_count += 1
+ if opt in ('-h', '--help'):
+ usage(argv[0])
+ elif opt in ('-v', '--verbose'):
+ verbose = True
+ else:
+ usage(argv[0])
+ if (arg_count == argc):
+ usage(argv[0])
+
+ git_config = {'user_name': "", 'user_email': ""}
+ (stat, err_msg) = get_user_gitconfig(git_config)
+ if (stat != 0):
+ print "It wasn't possible to execute: %s" % err_msg
+ sys.exit(2)
+
+ final_output = ""
+ args = argv[arg_count:]
+ # Get output regarding to the each patch file!
+ for arg in args:
+ (stat, output) = exec_get_maintainers(arg)
+ if (stat != 0):
+ print '%s: %s failed! Please, check the patch: %s,' \
+ ' and make sure you "installed" this script' \
+ ' in the *directory scripts* of Linux tree.' \
+ % (argv[0], SCRIPT, arg)
+ sys.exit(2)
+ final_output += (output + '\n')
+
+ buf = StringIO.StringIO(final_output)
+ (mnt_count, list_count) = \
+ generate_gitmail_cmd(build_list(buf), git_config, args)
+
+ if (verbose):
+ print "\n\n* Statistics: Maintainer(s): %d, List(s): %d" \
+ % (mnt_count, list_count)
+
+
+if __name__ == "__main__":
+ main(len(sys.argv), sys.argv)
--
1.7.2.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists