OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """\ | 6 """\ |
7 Wrapper script around Rietveld's upload.py that simplifies working with groups | 7 Wrapper script around Rietveld's upload.py that simplifies working with groups |
8 of files. | 8 of files. |
9 """ | 9 """ |
10 | 10 |
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 file_re = re.compile(r"^[a-z].+\Z", re.IGNORECASE) | 1088 file_re = re.compile(r"^[a-z].+\Z", re.IGNORECASE) |
1089 affected_files = [x for x in other_files if file_re.match(x[0])] | 1089 affected_files = [x for x in other_files if file_re.match(x[0])] |
1090 unaffected_files = [x for x in other_files if not file_re.match(x[0])] | 1090 unaffected_files = [x for x in other_files if not file_re.match(x[0])] |
1091 | 1091 |
1092 description = description.rstrip() + '\n' | 1092 description = description.rstrip() + '\n' |
1093 | 1093 |
1094 separator1 = ("\n---All lines above this line become the description.\n" | 1094 separator1 = ("\n---All lines above this line become the description.\n" |
1095 "---Repository Root: " + change_info.GetLocalRoot() + "\n" | 1095 "---Repository Root: " + change_info.GetLocalRoot() + "\n" |
1096 "---Paths in this changelist (" + change_info.name + "):\n") | 1096 "---Paths in this changelist (" + change_info.name + "):\n") |
1097 separator2 = "\n\n---Paths modified but not in any changelist:\n\n" | 1097 separator2 = "\n\n---Paths modified but not in any changelist:\n\n" |
1098 text = (description + separator1 + '\n' + | 1098 |
| 1099 description_to_write = description |
| 1100 if sys.platform == 'win32': |
| 1101 description_to_write = description.replace('\n', '\r\n') |
| 1102 |
| 1103 text = (description_to_write + separator1 + '\n' + |
1099 '\n'.join([f[0] + f[1] for f in change_info.GetFiles()])) | 1104 '\n'.join([f[0] + f[1] for f in change_info.GetFiles()])) |
1100 | 1105 |
1101 if change_info.Exists(): | 1106 if change_info.Exists(): |
1102 text += (separator2 + | 1107 text += (separator2 + |
1103 '\n'.join([f[0] + f[1] for f in affected_files]) + '\n') | 1108 '\n'.join([f[0] + f[1] for f in affected_files]) + '\n') |
1104 else: | 1109 else: |
1105 text += ('\n'.join([f[0] + f[1] for f in affected_files]) + '\n' + | 1110 text += ('\n'.join([f[0] + f[1] for f in affected_files]) + '\n' + |
1106 separator2) | 1111 separator2) |
1107 text += '\n'.join([f[0] + f[1] for f in unaffected_files]) + '\n' | 1112 text += '\n'.join([f[0] + f[1] for f in unaffected_files]) + '\n' |
1108 | 1113 |
1109 handle, filename = tempfile.mkstemp(text=True) | 1114 handle, filename = tempfile.mkstemp(text=True) |
1110 os.write(handle, text) | 1115 os.write(handle, text) |
1111 os.close(handle) | 1116 os.close(handle) |
1112 | |
1113 # Open up the default editor in the system to get the CL description. | 1117 # Open up the default editor in the system to get the CL description. |
1114 try: | 1118 try: |
1115 if not silent: | 1119 if not silent: |
1116 cmd = '%s %s' % (GetEditor(), filename) | 1120 cmd = '%s %s' % (GetEditor(), filename) |
1117 if sys.platform == 'win32' and os.environ.get('TERM') == 'msys': | 1121 if sys.platform == 'win32' and os.environ.get('TERM') == 'msys': |
1118 # Msysgit requires the usage of 'env' to be present. | 1122 # Msysgit requires the usage of 'env' to be present. |
1119 cmd = 'env ' + cmd | 1123 cmd = 'env ' + cmd |
1120 try: | 1124 try: |
1121 # shell=True to allow the shell to handle all forms of quotes in | 1125 # shell=True to allow the shell to handle all forms of quotes in |
1122 # $EDITOR. | 1126 # $EDITOR. |
1123 subprocess2.check_call(cmd, shell=True) | 1127 subprocess2.check_call(cmd, shell=True) |
1124 except subprocess2.CalledProcessError, e: | 1128 except subprocess2.CalledProcessError, e: |
1125 ErrorExit('Editor returned %d' % e.returncode) | 1129 ErrorExit('Editor returned %d' % e.returncode) |
1126 result = gclient_utils.FileRead(filename, 'r') | 1130 result = gclient_utils.FileRead(filename, 'r') |
1127 finally: | 1131 finally: |
1128 os.remove(filename) | 1132 os.remove(filename) |
1129 | 1133 |
1130 if not result: | 1134 if not result: |
1131 return 0 | 1135 return 0 |
1132 | 1136 |
1133 split_result = result.split(separator1, 1) | 1137 split_result = result.split(separator1, 1) |
1134 if len(split_result) != 2: | 1138 if len(split_result) != 2: |
1135 ErrorExit("Don't modify the text starting with ---!\n\n" + result) | 1139 ErrorExit("Don't modify the text starting with ---!\n\n" + result) |
1136 | 1140 |
1137 # Update the CL description if it has changed. | 1141 # Update the CL description if it has changed. |
1138 new_description = split_result[0] | 1142 new_description = split_result[0] |
| 1143 |
| 1144 if sys.platform == 'win32': |
| 1145 new_description = new_description.replace('\r\n', '\n') |
| 1146 |
1139 cl_files_text = split_result[1] | 1147 cl_files_text = split_result[1] |
1140 if new_description != description or override_description: | 1148 if new_description != description or override_description: |
1141 change_info.description = new_description | 1149 change_info.description = new_description |
1142 change_info.needs_upload = True | 1150 change_info.needs_upload = True |
1143 | 1151 |
1144 new_cl_files = [] | 1152 new_cl_files = [] |
1145 for line in cl_files_text.splitlines(): | 1153 for line in cl_files_text.splitlines(): |
1146 if not len(line): | 1154 if not len(line): |
1147 continue | 1155 continue |
1148 if line.startswith("---"): | 1156 if line.startswith("---"): |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 raise | 1469 raise |
1462 print >> sys.stderr, ( | 1470 print >> sys.stderr, ( |
1463 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1471 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1464 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) | 1472 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) |
1465 return 1 | 1473 return 1 |
1466 | 1474 |
1467 | 1475 |
1468 if __name__ == "__main__": | 1476 if __name__ == "__main__": |
1469 fix_encoding.fix_encoding() | 1477 fix_encoding.fix_encoding() |
1470 sys.exit(main(sys.argv[1:])) | 1478 sys.exit(main(sys.argv[1:])) |
OLD | NEW |