|
43 | 43 | if not GITHUB_API_TOKEN:
|
44 | 44 | sys.exit("GITHUB_API_TOKEN must be set")
|
45 | 45 |
|
46 |
| -# Write new contributors list to <old_file_name>.new |
| 46 | +# Write new contributors list to <old_file_name>.final |
47 | 47 | if not os.path.isfile(contributors_file_name):
|
48 | 48 | print "Contributors file %s does not exist!" % contributors_file_name
|
49 | 49 | print "Have you run ./generate-contributors.py yet?"
|
50 | 50 | sys.exit(1)
|
51 | 51 | contributors_file = open(contributors_file_name, "r")
|
52 |
| -new_contributors_file_name = contributors_file_name + ".new" |
53 |
| -new_contributors_file = open(new_contributors_file_name, "w") |
54 | 52 | warnings = []
|
55 | 53 |
|
56 | 54 | # In non-interactive mode, this script will choose the first replacement that is valid
|
|
73 | 71 | known_translations_file = open(known_translations_file_name, "r")
|
74 | 72 | for line in known_translations_file:
|
75 | 73 | if line.startswith("#"): continue
|
76 |
| - [old_name, new_name] = line.split(" - ") |
| 74 | + [old_name, new_name] = line.strip("\n").split(" - ") |
77 | 75 | known_translations[old_name] = new_name
|
78 | 76 | known_translations_file.close()
|
79 | 77 |
|
@@ -147,16 +145,16 @@ def generate_candidates(author, issues):
|
147 | 145 | # If no such name exists, the original name is used (without the JIRA numbers).
|
148 | 146 | print "\n========================== Translating contributor list =========================="
|
149 | 147 | lines = contributors_file.readlines()
|
| 148 | +contributions = [] |
150 | 149 | for i, line in enumerate(lines):
|
151 |
| - temp_author = line.split(" - ")[0] |
| 150 | + temp_author = line.strip(" * ").split(" -- ")[0] |
152 | 151 | print "Processing author %s (%d/%d)" % (temp_author, i + 1, len(lines))
|
153 | 152 | if not temp_author:
|
154 |
| - error_msg = " ERROR: Expected the following format <author> - <contributions>\n" |
| 153 | + error_msg = " ERROR: Expected the following format \" * <author> -- <contributions>\"\n" |
155 | 154 | error_msg += " ERROR: Actual = %s" % line
|
156 | 155 | print error_msg
|
157 | 156 | warnings.append(error_msg)
|
158 |
| - new_contributors_file.write(line) |
159 |
| - new_contributors_file.flush() |
| 157 | + contributions.append(line) |
160 | 158 | continue
|
161 | 159 | author = temp_author.split("/")[0]
|
162 | 160 | # Use the local copy of known translations where possible
|
@@ -222,10 +220,26 @@ def generate_candidates(author, issues):
|
222 | 220 | known_translations_file.write("%s - %s\n" % (author, new_author))
|
223 | 221 | known_translations_file.flush()
|
224 | 222 | line = line.replace(temp_author, author)
|
225 |
| - new_contributors_file.write(line) |
226 |
| - new_contributors_file.flush() |
| 223 | + contributions.append(line) |
227 | 224 | print "==================================================================================\n"
|
228 | 225 | contributors_file.close()
|
| 226 | +known_translations_file.close() |
| 227 | + |
| 228 | +# Sort the contributions before writing them to the new file. |
| 229 | +# Additionally, check if there are any duplicate author rows. |
| 230 | +# This could happen if the same user has both a valid full |
| 231 | +# name (e.g. Andrew Or) and an invalid one (andrewor14). |
| 232 | +# If so, warn the user about this at the end. |
| 233 | +contributions.sort() |
| 234 | +all_authors = set() |
| 235 | +new_contributors_file_name = contributors_file_name + ".final" |
| 236 | +new_contributors_file = open(new_contributors_file_name, "w") |
| 237 | +for line in contributions: |
| 238 | + author = line.strip(" * ").split(" -- ")[0] |
| 239 | + if author in all_authors: |
| 240 | + warnings.append("Detected duplicate author name %s. Please merge these manually." % author) |
| 241 | + all_authors.add(author) |
| 242 | + new_contributors_file.write(line) |
229 | 243 | new_contributors_file.close()
|
230 | 244 |
|
231 | 245 | print "Translated contributors list successfully written to %s!" % new_contributors_file_name
|
|
0 commit comments