2015-08-22 23:39:10 +00:00
|
|
|
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
BASE_RTD_URL = 'http://boltons.readthedocs.org/en/latest/'
|
|
|
|
BASE_ISSUES_URL = 'https://github.com/mahmoud/boltons/issues/'
|
|
|
|
|
|
|
|
_issues_re = re.compile('#(\d+)')
|
|
|
|
_member_re = re.compile('((\w+utils)\.[a-zA-Z0-9_.]+)')
|
|
|
|
|
2015-08-22 23:48:52 +00:00
|
|
|
URL_MAP = {}
|
2015-08-22 23:39:10 +00:00
|
|
|
|
|
|
|
def sub_member_match(match):
|
|
|
|
full_name = match.group(1)
|
|
|
|
mod_name = match.group(2)
|
|
|
|
url = BASE_RTD_URL + mod_name + '.html#boltons.' + full_name
|
2015-08-22 23:48:52 +00:00
|
|
|
ret = '[%s][%s]' % (full_name, full_name)
|
|
|
|
URL_MAP[full_name] = url
|
2015-08-22 23:39:10 +00:00
|
|
|
# print ret
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def sub_issue_match(match):
|
|
|
|
link_text = match.group(0)
|
|
|
|
issue_num = match.group(1)
|
2015-08-22 23:48:52 +00:00
|
|
|
link_target = 'i%s' % issue_num
|
|
|
|
link_url = BASE_ISSUES_URL + issue_num
|
|
|
|
ret = '[%s][%s]' % (link_text, link_target)
|
|
|
|
URL_MAP[link_target] = link_url
|
2015-08-22 23:39:10 +00:00
|
|
|
# print ret
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
cl_filename = sys.argv[1]
|
|
|
|
except IndexError:
|
|
|
|
cl_filename = 'CHANGELOG.md'
|
|
|
|
cl_text = open(cl_filename).read().decode('utf-8')
|
|
|
|
ret = _member_re.sub(sub_member_match, cl_text)
|
|
|
|
ret = _issues_re.sub(sub_issue_match, ret)
|
2015-08-22 23:48:52 +00:00
|
|
|
|
|
|
|
link_map_lines = []
|
|
|
|
for (name, url) in sorted(URL_MAP.items()):
|
|
|
|
link_map_lines.append('[%s]: %s' % (name, url))
|
|
|
|
|
2015-08-22 23:39:10 +00:00
|
|
|
print ret
|
2015-08-22 23:48:52 +00:00
|
|
|
print
|
|
|
|
print
|
|
|
|
print '\n'.join(link_map_lines)
|
|
|
|
print
|
2015-08-22 23:39:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|