diff options
author | Jacek Antonelli | 2010-03-18 03:09:14 -0500 |
---|---|---|
committer | Jacek Antonelli | 2010-03-18 21:35:39 -0500 |
commit | 0f3d6ce1fb4b7d581b7e18e940e03cffe5e098ce (patch) | |
tree | 672cb9c542b6efe3a6073b9b31b52bfeb4528b48 | |
parent | ChangeLog.txt is no longer required for packaging. (diff) | |
download | meta-impy-0f3d6ce1fb4b7d581b7e18e940e03cffe5e098ce.zip meta-impy-0f3d6ce1fb4b7d581b7e18e940e03cffe5e098ce.tar.gz meta-impy-0f3d6ce1fb4b7d581b7e18e940e03cffe5e098ce.tar.bz2 meta-impy-0f3d6ce1fb4b7d581b7e18e940e03cffe5e098ce.tar.xz |
Improved make_changelog.py.
* Uses 'subprocess' module instead of 'commands' (which is Unix-only).
* No longer overwrites ChangeLog.txt when it fails.
@nochangelog
-rwxr-xr-x | linden/scripts/make_changelog.py | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/linden/scripts/make_changelog.py b/linden/scripts/make_changelog.py index 43745a4..713adc1 100755 --- a/linden/scripts/make_changelog.py +++ b/linden/scripts/make_changelog.py | |||
@@ -50,9 +50,7 @@ | |||
50 | # | 50 | # |
51 | 51 | ||
52 | 52 | ||
53 | 53 | import re, os, sys, subprocess | |
54 | import commands, re, os, sys | ||
55 | from string import Template | ||
56 | 54 | ||
57 | 55 | ||
58 | SCRIPT_DIR = os.path.abspath( os.path.dirname( sys.argv[0] ) ) | 56 | SCRIPT_DIR = os.path.abspath( os.path.dirname( sys.argv[0] ) ) |
@@ -316,8 +314,9 @@ Author: %(an)s <%(ae)s>""" % { "ad" : self.author_date, | |||
316 | "id" : self.id[0:7] }) | 314 | "id" : self.id[0:7] }) |
317 | 315 | ||
318 | if self.commit_name != self.author_name: | 316 | if self.commit_name != self.author_name: |
319 | texts.append("Committer: %(cn)s <%(ce)s>" % { "cn" : self.commit_name, | 317 | texts.append("Committer: %(cn)s <%(ce)s>" % \ |
320 | "ce" : self.commit_mail }) | 318 | { "cn" : self.commit_name, |
319 | "ce" : self.commit_mail }) | ||
321 | 320 | ||
322 | texts.append("\n") | 321 | texts.append("\n") |
323 | 322 | ||
@@ -360,32 +359,52 @@ Author: %(an)s <%(ae)s>""" % { "ad" : self.author_date, | |||
360 | 359 | ||
361 | 360 | ||
362 | 361 | ||
362 | def fail( reason, abort=False ): | ||
363 | """Prints a message that the ChangeLog couldn't be generated, then | ||
364 | exits the script. If abort is True, exit with status code 1 (to | ||
365 | indicate that Make/VisualStudio/Xcode/etc. should abort), | ||
366 | otherwise exit with status code 0.""" | ||
367 | |||
368 | if abort: | ||
369 | print "Error: Could not generate ChangeLog.txt: " + reason | ||
370 | exit(1) | ||
371 | else: | ||
372 | print "Warning: Could not generate ChangeLog.txt: " + reason | ||
373 | exit(0) | ||
374 | |||
375 | |||
363 | 376 | ||
364 | def main(): | 377 | def main(): |
365 | commits = sys.argv[1:] | 378 | commits = sys.argv[1:] |
366 | if commits: | 379 | if not commits: |
367 | commits = " ".join(commits) | 380 | commits = ["HEAD"] |
368 | else: | ||
369 | commits = "HEAD" | ||
370 | 381 | ||
371 | 382 | ||
372 | # Set PATH to help find the git executable on Mac OS X. | 383 | # Set PATH to help find the git executable on Mac OS X. |
373 | if sys.platform == "darwin": | 384 | if sys.platform == "darwin": |
374 | os.environ["PATH"] += ":/usr/local/bin:/usr/local/git/bin:/sw/bin:/opt/bin:~/bin" | 385 | os.environ["PATH"] += ":/usr/local/bin:/usr/local/git/bin:/sw/bin:/opt/bin:~/bin" |
375 | 386 | ||
376 | # Fetch the log entries from git in one big chunk. | ||
377 | cmd = "git log --pretty=fuller --name-status --date=short --date-order " + commits | ||
378 | status, output = commands.getstatusoutput(cmd) | ||
379 | |||
380 | 387 | ||
381 | # If the git command failed, write a placeholder ChangeLog.txt and exit. | 388 | # Fetch the log entries from git in one big chunk. |
389 | cmd = ["git", "log", "--pretty=fuller", "--name-status", | ||
390 | "--date=short", "--date-order"] + commits | ||
391 | |||
392 | try: | ||
393 | proc = subprocess.Popen(cmd, | ||
394 | cwd = ROOT_DIR, | ||
395 | stdout = subprocess.PIPE, | ||
396 | stderr = subprocess.STDOUT, | ||
397 | shell = True) | ||
398 | except OSError: | ||
399 | fail("The 'git' command is not available.") | ||
400 | |||
401 | output = proc.communicate()[0] | ||
402 | status = proc.returncode | ||
403 | |||
404 | |||
405 | # If the git command failed, print the reason and exit. | ||
382 | if status != 0: | 406 | if status != 0: |
383 | print "Could not generate ChangeLog.txt: " + output | 407 | fail(output) |
384 | changelog = open(CHANGELOG, "w") | ||
385 | changelog.write( output + "\n (Imprudence must be compiled from a Git repository to generate a ChangeLog.)\n\n") | ||
386 | changelog.close() | ||
387 | exit(0) | ||
388 | |||
389 | 408 | ||
390 | # Split it up into individual commits. | 409 | # Split it up into individual commits. |
391 | logs = re.compile("^commit ", re.MULTILINE).split(output)[1:] | 410 | logs = re.compile("^commit ", re.MULTILINE).split(output)[1:] |