changeset 185:b5d71972aa72

apply-patchbomb: script to apply patchbomb from selected messages in Mail.app.
author Augie Fackler <durin42@gmail.com>
date Sat, 30 Jan 2010 12:21:00 -0600
parents efa2bfc73d2d
children 802472e96f27
files unixSoft/bin/apply-patchbomb
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
new file mode 100755
--- /dev/null
+++ b/unixSoft/bin/apply-patchbomb
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+# shebang for system python explicitly so we're sure to have pyobjc and
+# the scripting bridge.
+"""apply-patchbomb: apply selected messages in Mail.app to an hg repo in pwd.
+
+This uses the scripting bridge to talk to Mail and subprocess to pass the
+patch to Mercurial on stdin.
+"""
+
+
+import ScriptingBridge
+import subprocess
+
+def main():
+    mail = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_(
+        'com.apple.Mail')
+    messages = list(sorted(mail.selection(),
+                           cmp=lambda x,y: cmp(x.subject(), y.subject())))
+    for m in messages:
+        print 'Applying', m.subject()
+        p = subprocess.Popen(['hg', 'import', '-'], stdin=subprocess.PIPE)
+        p.stdin.write(m.source())
+        p.stdin.close()
+        if p.wait() != 0:
+            print 'hg import failed, bailing'
+            break
+
+if __name__ == '__main__':
+    main()