Mercurial > dotfiles
comparison unixSoft/bin/apply-patchbomb @ 227:e8170eba88cd
apply-patchbomb: clean up imports and improve exit status
| author | Augie Fackler <durin42@gmail.com> |
|---|---|
| date | Mon, 04 Oct 2010 21:47:22 -0500 |
| parents | b5d71972aa72 |
| children | 4b661cede8ad |
comparison
equal
deleted
inserted
replaced
| 226:f8a4c55ad070 | 227:e8170eba88cd |
|---|---|
| 4 """apply-patchbomb: apply selected messages in Mail.app to an hg repo in pwd. | 4 """apply-patchbomb: apply selected messages in Mail.app to an hg repo in pwd. |
| 5 | 5 |
| 6 This uses the scripting bridge to talk to Mail and subprocess to pass the | 6 This uses the scripting bridge to talk to Mail and subprocess to pass the |
| 7 patch to Mercurial on stdin. | 7 patch to Mercurial on stdin. |
| 8 """ | 8 """ |
| 9 | 9 import email |
| 10 import subprocess | |
| 11 import sys | |
| 10 | 12 |
| 11 import ScriptingBridge | 13 import ScriptingBridge |
| 12 import subprocess | |
| 13 | 14 |
| 14 def main(): | 15 def main(): |
| 15 mail = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_( | 16 mail = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_( |
| 16 'com.apple.Mail') | 17 'com.apple.Mail') |
| 17 messages = list(sorted(mail.selection(), | 18 messages = list(sorted(mail.selection(), |
| 21 p = subprocess.Popen(['hg', 'import', '-'], stdin=subprocess.PIPE) | 22 p = subprocess.Popen(['hg', 'import', '-'], stdin=subprocess.PIPE) |
| 22 p.stdin.write(m.source()) | 23 p.stdin.write(m.source()) |
| 23 p.stdin.close() | 24 p.stdin.close() |
| 24 if p.wait() != 0: | 25 if p.wait() != 0: |
| 25 print 'hg import failed, bailing' | 26 print 'hg import failed, bailing' |
| 26 break | 27 return 2 |
| 28 return 0 | |
| 27 | 29 |
| 28 if __name__ == '__main__': | 30 if __name__ == '__main__': |
| 29 main() | 31 sys.exit(main()) |
