Mercurial > kallithea
comparison rhodecode/lib/helpers.py @ 2865:6d9b3ade3051 beta
Allowing multiple issue servers to be autolinked in the changeset view;
linking is now contingent on issue_server_link, issue_pat and issue_prefix
being defined; multiple servers can be used by specifying a common suffix on all
the above variables, ie ..
issue_server_link_1
issue_pat_1
issue_prefix_1
.. and ..
issue_server_link_other
issue_pat_other
issue_prefix_other
.. would be treated as two distinct servers, but ..
issue_pat_thing
.. would be ignored (since the other two requisite vars aren't present).
This patch is backwards compatible with existing variables (as a suffix
isn't needed).
author | Zachary Auclair <zach101@gmail.com> |
---|---|
date | Thu, 20 Sep 2012 20:30:55 -0400 |
parents | 819eb7f8a555 |
children | 736678a8c881 |
comparison
equal
deleted
inserted
replaced
2864:5c1ad3b410e5 | 2865:6d9b3ade3051 |
---|---|
998 links.append(e) | 998 links.append(e) |
999 | 999 |
1000 return ''.join(links) | 1000 return ''.join(links) |
1001 | 1001 |
1002 # urlify changesets - extrac revisions and make link out of them | 1002 # urlify changesets - extrac revisions and make link out of them |
1003 text_ = urlify_changesets(escaper(text_), repository) | 1003 newtext = urlify_changesets(escaper(text_), repository) |
1004 | 1004 |
1005 try: | 1005 try: |
1006 conf = config['app_conf'] | 1006 conf = config['app_conf'] |
1007 | 1007 |
1008 URL_PAT = re.compile(r'%s' % conf.get('issue_pat')) | 1008 # allow multiple issue servers to be used |
1009 | 1009 valid_indices = [ |
1010 if URL_PAT: | 1010 x.group(1) |
1011 ISSUE_SERVER_LNK = conf.get('issue_server_link') | 1011 for x in map(lambda x: re.match(r'issue_pat(.*)', x), conf.keys()) |
1012 ISSUE_PREFIX = conf.get('issue_prefix') | 1012 if x and conf.has_key('issue_server_link'+x.group(1)) and conf.has_key('issue_prefix'+x.group(1)) |
1013 ] | |
1014 | |
1015 #log.debug('found issue server suffixes ' + ','.join(valid_indices) + ' during valuation of: \n' + newtext) | |
1016 | |
1017 for pattern_index in valid_indices: | |
1018 ISSUE_PATTERN = conf.get('issue_pat'+pattern_index) | |
1019 ISSUE_SERVER_LNK = conf.get('issue_server_link'+pattern_index) | |
1020 ISSUE_PREFIX = conf.get('issue_prefix'+pattern_index) | |
1021 | |
1022 #log.debug(ISSUE_PATTERN + ' ' + ISSUE_SERVER_LNK + ' ' + ISSUE_PREFIX) | |
1023 | |
1024 URL_PAT = re.compile(r'%s' % ISSUE_PATTERN) | |
1013 | 1025 |
1014 def url_func(match_obj): | 1026 def url_func(match_obj): |
1015 pref = '' | 1027 pref = '' |
1016 if match_obj.group().startswith(' '): | 1028 if match_obj.group().startswith(' '): |
1017 pref = ' ' | 1029 pref = ' ' |
1025 url = ISSUE_SERVER_LNK.replace('{id}', issue_id) | 1037 url = ISSUE_SERVER_LNK.replace('{id}', issue_id) |
1026 if repository: | 1038 if repository: |
1027 url = url.replace('{repo}', repository) | 1039 url = url.replace('{repo}', repository) |
1028 repo_name = repository.split(URL_SEP)[-1] | 1040 repo_name = repository.split(URL_SEP)[-1] |
1029 url = url.replace('{repo_name}', repo_name) | 1041 url = url.replace('{repo_name}', repo_name) |
1042 | |
1030 return tmpl % { | 1043 return tmpl % { |
1031 'pref': pref, | 1044 'pref': pref, |
1032 'cls': 'issue-tracker-link', | 1045 'cls': 'issue-tracker-link', |
1033 'url': url, | 1046 'url': url, |
1034 'id-repr': issue_id, | 1047 'id-repr': issue_id, |
1035 'issue-prefix': ISSUE_PREFIX, | 1048 'issue-prefix': ISSUE_PREFIX, |
1036 'serv': ISSUE_SERVER_LNK, | 1049 'serv': ISSUE_SERVER_LNK, |
1037 } | 1050 } |
1038 | 1051 |
1039 newtext = URL_PAT.sub(url_func, text_) | 1052 newtext = URL_PAT.sub(url_func, newtext) |
1040 | 1053 #log.debug('after '+pattern_index+':\n'+newtext) |
1054 | |
1055 # if we actually did something above | |
1056 if valid_indices: | |
1041 if link_: | 1057 if link_: |
1042 # wrap not links into final link => link_ | 1058 # wrap not links into final link => link_ |
1043 newtext = linkify_others(newtext, link_) | 1059 newtext = linkify_others(newtext, link_) |
1044 | 1060 |
1045 return literal(newtext) | 1061 return literal(newtext) |
1046 except: | 1062 except: |
1047 log.error(traceback.format_exc()) | 1063 log.error(traceback.format_exc()) |
1048 pass | 1064 pass |
1049 | 1065 |
1050 return text_ | 1066 return newtext |
1051 | 1067 |
1052 | 1068 |
1053 def rst(source): | 1069 def rst(source): |
1054 return literal('<div class="rst-block">%s</div>' % | 1070 return literal('<div class="rst-block">%s</div>' % |
1055 MarkupRenderer.rst(source)) | 1071 MarkupRenderer.rst(source)) |