comparison unixSoft/bin/apply-patchbomb @ 521:6cc5a0550281

tools: port hg utility scripts to python 3
author Augie Fackler <raf@durin42.com>
date Thu, 14 Jul 2022 14:09:04 -0400
parents 0b8457903012
children
comparison
equal deleted inserted replaced
520:9af1fc9b713c 521:6cc5a0550281
1 #!/usr/bin/python 1 #!/usr/bin/env python
2 # shebang for system python explicitly so we're sure to have pyobjc and 2 # shebang for system python explicitly so we're sure to have pyobjc and
3 # the scripting bridge. 3 # the scripting bridge.
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
16 mail = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_( 16 mail = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_(
17 'com.apple.Mail') 17 'com.apple.Mail')
18 messages = list(sorted(mail.selection(), 18 messages = list(sorted(mail.selection(),
19 cmp=lambda x,y: cmp(x.subject(), y.subject()))) 19 cmp=lambda x,y: cmp(x.subject(), y.subject())))
20 for m in messages: 20 for m in messages:
21 print 'Applying', m.subject() 21 print('Applying', m.subject())
22 p = subprocess.Popen(['hg', 'import', '--obsolete', '-'], stdin=subprocess.PIPE) 22 p = subprocess.Popen(['hg', 'import', '--obsolete', '-'], stdin=subprocess.PIPE)
23 p.stdin.write(m.source()) 23 p.stdin.write(m.source())
24 p.stdin.close() 24 p.stdin.close()
25 if p.wait() != 0: 25 if p.wait() != 0:
26 print 'hg import failed, bailing' 26 print('hg import failed, bailing')
27 return 2 27 return 2
28 return 0 28 return 0
29 29
30 if __name__ == '__main__': 30 if __name__ == '__main__':
31 sys.exit(main()) 31 sys.exit(main())