comparison garcon/changelog.py @ 740:3ab6f7a3a2c7

cm: Add generation of Mardown changelog suitable for the online documentation.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 02 Jun 2016 20:21:36 -0700
parents e6d9eed35c8e
children be8b233cc69a
comparison
equal deleted inserted replaced
739:c6035785dbfc 740:3ab6f7a3a2c7
43 'hg', 'log', 43 'hg', 'log',
44 '--rev', 'reverse(::master)', 44 '--rev', 'reverse(::master)',
45 '--template', hg_log_template]) 45 '--template', hg_log_template])
46 hglog = hglog.decode('utf8') 46 hglog = hglog.decode('utf8')
47 47
48 templates = _get_templates() 48 _, out_ext = os.path.splitext(out_file)
49 templates = _get_templates(out_ext)
49 50
50 with open(out_file, 'w', encoding='utf8', newline='') as fp: 51 with open(out_file, 'w', encoding='utf8', newline='') as fp:
51 fp.write(templates['header']) 52 fp.write(templates['header'])
52 53
53 skip = False 54 skip = False
127 msgs = changes.get(cat_name) 128 msgs = changes.get(cat_name)
128 if not msgs: 129 if not msgs:
129 continue 130 continue
130 131
131 tokens = { 132 tokens = {
133 'num': str(version),
132 'sub_num': str(i), 134 'sub_num': str(i),
133 'category': cat_name.title()} 135 'category': cat_name.title()}
134 tpl = _multi_replace(templates['category_title'], tokens) 136 tpl = _multi_replace(templates['category_title'], tokens)
135 fp.write(tpl) 137 fp.write(tpl)
136 138
144 for token in tokens: 146 for token in tokens:
145 s = s.replace('%%%s%%' % token, tokens[token]) 147 s = s.replace('%%%s%%' % token, tokens[token])
146 return s 148 return s
147 149
148 150
149 def _get_templates(): 151 def _get_templates(extension):
150 tpl_dir = os.path.join(os.path.dirname(__file__), 'changelog') 152 tpl_dir = os.path.join(os.path.dirname(__file__), 'changelog')
151 tpls = {} 153 tpls = {}
152 for name in os.listdir(tpl_dir): 154 for name in os.listdir(tpl_dir):
153 tpl = _get_template(os.path.join(tpl_dir, name)) 155 if name.endswith(extension):
154 name_no_ext, _ = os.path.splitext(name) 156 tpl = _get_template(os.path.join(tpl_dir, name))
155 tpls[name_no_ext] = tpl 157 name_no_ext, _ = os.path.splitext(name)
158 tpls[name_no_ext] = tpl
156 return tpls 159 return tpls
157 160
158 161
159 def _get_template(filename): 162 def _get_template(filename):
160 with open(filename, 'r', encoding='utf8', newline='') as fp: 163 with open(filename, 'r', encoding='utf8', newline='') as fp: