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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 | 703 |
704 def UserEditedLog(starting_text): | 704 def UserEditedLog(starting_text): |
705 """Given some starting text, let the user edit it and return the result.""" | 705 """Given some starting text, let the user edit it and return the result.""" |
706 editor = os.getenv('EDITOR', 'vi') | 706 editor = os.getenv('EDITOR', 'vi') |
707 | 707 |
708 (file_handle, filename) = tempfile.mkstemp() | 708 (file_handle, filename) = tempfile.mkstemp() |
709 fileobj = os.fdopen(file_handle, 'w') | 709 fileobj = os.fdopen(file_handle, 'w') |
710 fileobj.write(starting_text) | 710 fileobj.write(starting_text) |
711 fileobj.close() | 711 fileobj.close() |
712 | 712 |
713 ret = subprocess.call(editor + ' ' + filename, shell=True) | 713 result = None |
M-A Ruel
2011/03/12 02:17:43
not needed
| |
714 if ret != 0: | 714 try: |
715 subprocess.check_call(['env', editor, filename], shell=True) | |
716 fileobj = open(filename) | |
717 result = fileobj.read() | |
718 fileobj.close() | |
719 finally: | |
715 os.remove(filename) | 720 os.remove(filename) |
721 | |
722 if not result: | |
716 return | 723 return |
717 | 724 |
718 fileobj = open(filename) | |
719 text = fileobj.read() | |
720 fileobj.close() | |
721 os.remove(filename) | |
722 stripcomment_re = re.compile(r'^#.*$', re.MULTILINE) | 725 stripcomment_re = re.compile(r'^#.*$', re.MULTILINE) |
723 return stripcomment_re.sub('', text).strip() | 726 return stripcomment_re.sub('', result).strip() |
724 | 727 |
725 | 728 |
726 def ConvertToInteger(inputval): | 729 def ConvertToInteger(inputval): |
727 """Convert a string to integer, but returns either an int or None.""" | 730 """Convert a string to integer, but returns either an int or None.""" |
728 try: | 731 try: |
729 return int(inputval) | 732 return int(inputval) |
730 except (TypeError, ValueError): | 733 except (TypeError, ValueError): |
731 return None | 734 return None |
732 | 735 |
733 | 736 |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1394 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1397 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1395 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1398 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1396 | 1399 |
1397 # Not a known command. Default to help. | 1400 # Not a known command. Default to help. |
1398 GenUsage(parser, 'help') | 1401 GenUsage(parser, 'help') |
1399 return CMDhelp(parser, argv) | 1402 return CMDhelp(parser, argv) |
1400 | 1403 |
1401 | 1404 |
1402 if __name__ == '__main__': | 1405 if __name__ == '__main__': |
1403 sys.exit(main(sys.argv[1:])) | 1406 sys.exit(main(sys.argv[1:])) |
OLD | NEW |