Mercurial > piecrust2
comparison util/generate_changelog.py @ 572:442cf576ae25
cm: CHANGELOG generator can handle future versions.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 31 Oct 2015 21:46:05 -0700 |
parents | 9a00e694b42c |
children | 7940861ff9bc |
comparison
equal
deleted
inserted
replaced
571:76f0118276d7 | 572:442cf576ae25 |
---|---|
1 import os | 1 import os |
2 import os.path | 2 import os.path |
3 import re | 3 import re |
4 import sys | 4 import time |
5 import argparse | |
5 import subprocess | 6 import subprocess |
6 | 7 |
7 | 8 |
8 hg_log_template = ("{if(tags, '>>{tags};{date|shortdate}\n')}" | 9 hg_log_template = ("{if(tags, '>>{tags};{date|shortdate}\n')}" |
9 "{desc|firstline}\n\n") | 10 "{desc|firstline}\n\n") |
30 ('miscellaneous', None)] | 31 ('miscellaneous', None)] |
31 category_names = list(map(lambda i: i[0], categories)) | 32 category_names = list(map(lambda i: i[0], categories)) |
32 | 33 |
33 | 34 |
34 def generate(): | 35 def generate(): |
35 out_file = 'CHANGELOG.rst' | 36 parser = argparse.ArgumentParser(description='Generate CHANGELOG file.') |
36 if len(sys.argv) > 1: | 37 parser.add_argument( |
37 out_file = sys.argv[1] | 38 'out_file', |
39 nargs='?', | |
40 default='CHANGELOG.rst', | |
41 help='The output file.') | |
42 parser.add_argument( | |
43 '--last', | |
44 help="The version for the last few untagged changes.") | |
45 args = parser.parse_args() | |
38 | 46 |
39 print("Generating %s" % out_file) | 47 print("Generating %s" % args.out_file) |
40 | 48 |
41 if not os.path.exists('.hg'): | 49 if not os.path.exists('.hg'): |
42 raise Exception("You must run this script from the root of a " | 50 raise Exception("You must run this script from the root of a " |
43 "Mercurial clone of the PieCrust repository.") | 51 "Mercurial clone of the PieCrust repository.") |
44 hglog = subprocess.check_output([ | 52 hglog = subprocess.check_output([ |
47 '--template', hg_log_template]) | 55 '--template', hg_log_template]) |
48 hglog = hglog.decode('utf8') | 56 hglog = hglog.decode('utf8') |
49 | 57 |
50 templates = _get_templates() | 58 templates = _get_templates() |
51 | 59 |
52 with open(out_file, 'w') as fp: | 60 with open(args.out_file, 'w') as fp: |
53 fp.write(templates['header']) | 61 fp.write(templates['header']) |
54 | 62 |
55 skip = False | 63 skip = False |
56 in_desc = False | 64 in_desc = False |
57 current_version = 0 | 65 current_version = 0 |
58 current_version_info = None | 66 current_version_info = None |
59 current_changes = None | 67 current_changes = None |
68 | |
69 if args.last: | |
70 current_version = 1 | |
71 cur_date = time.strftime('%Y-%m-%d') | |
72 current_version_info = args.last, cur_date | |
73 current_changes = {} | |
74 | |
60 for line in hglog.splitlines(): | 75 for line in hglog.splitlines(): |
61 if line == '': | 76 if line == '': |
62 skip = False | 77 skip = False |
63 in_desc = False | 78 in_desc = False |
64 continue | 79 continue |