OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # git-cl -- a git-command for integrating reviews on Rietveld | 2 # git-cl -- a git-command for integrating reviews on Rietveld |
3 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 3 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
4 | 4 |
5 import errno | 5 import errno |
6 import logging | 6 import logging |
7 import optparse | 7 import optparse |
8 import os | 8 import os |
9 import re | 9 import re |
10 import StringIO | 10 import StringIO |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 def UserEditedLog(starting_text): | 681 def UserEditedLog(starting_text): |
682 """Given some starting text, let the user edit it and return the result.""" | 682 """Given some starting text, let the user edit it and return the result.""" |
683 editor = os.getenv('EDITOR', 'vi') | 683 editor = os.getenv('EDITOR', 'vi') |
684 | 684 |
685 (file_handle, filename) = tempfile.mkstemp() | 685 (file_handle, filename) = tempfile.mkstemp() |
686 fileobj = os.fdopen(file_handle, 'w') | 686 fileobj = os.fdopen(file_handle, 'w') |
687 fileobj.write(starting_text) | 687 fileobj.write(starting_text) |
688 fileobj.close() | 688 fileobj.close() |
689 | 689 |
690 # Open up the default editor in the system to get the CL description. | 690 # Open up the default editor in the system to get the CL description. |
691 ret = subprocess.call(editor + ' ' + filename, shell=True) | 691 try: |
692 if ret != 0: | 692 cmd = '%s %s' % (editor, filename) |
| 693 if sys.platform == 'win32' and os.environ.get('TERM') == 'msys': |
| 694 # Msysgit requires the usage of 'env' to be present. |
| 695 cmd = 'env ' + cmd |
| 696 # shell=True to allow the shell to handle all forms of quotes in $EDITOR. |
| 697 subprocess.check_call(cmd, shell=True) |
| 698 fileobj = open(filename) |
| 699 text = fileobj.read() |
| 700 fileobj.close() |
| 701 finally: |
693 os.remove(filename) | 702 os.remove(filename) |
| 703 |
| 704 if not text: |
694 return | 705 return |
695 fileobj = open(filename) | |
696 text = fileobj.read() | |
697 fileobj.close() | |
698 | |
699 os.remove(filename) | |
700 | 706 |
701 stripcomment_re = re.compile(r'^#.*$', re.MULTILINE) | 707 stripcomment_re = re.compile(r'^#.*$', re.MULTILINE) |
702 return stripcomment_re.sub('', text).strip() | 708 return stripcomment_re.sub('', text).strip() |
703 | 709 |
704 | 710 |
705 def ConvertToInteger(inputval): | 711 def ConvertToInteger(inputval): |
706 """Convert a string to integer, but returns either an int or None.""" | 712 """Convert a string to integer, but returns either an int or None.""" |
707 try: | 713 try: |
708 return int(inputval) | 714 return int(inputval) |
709 except (TypeError, ValueError): | 715 except (TypeError, ValueError): |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1373 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1368 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1374 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1369 | 1375 |
1370 # Not a known command. Default to help. | 1376 # Not a known command. Default to help. |
1371 GenUsage(parser, 'help') | 1377 GenUsage(parser, 'help') |
1372 return CMDhelp(parser, argv) | 1378 return CMDhelp(parser, argv) |
1373 | 1379 |
1374 | 1380 |
1375 if __name__ == '__main__': | 1381 if __name__ == '__main__': |
1376 sys.exit(main(sys.argv[1:])) | 1382 sys.exit(main(sys.argv[1:])) |
OLD | NEW |