Edgewall Software

Changeset 1508


Ignore:
Timestamp:
Apr 13, 2005, 6:04:25 PM (19 years ago)
Author:
Christian Boos
Message:

InterTrac: updated to take into account mgood's comments, and provide real and implicit inter-project links (currently only for tracd)

Location:
branches/cboos-dev/intertrac-branch/trac
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/cboos-dev/intertrac-branch/trac/WikiFormatter.py

    r1505 r1508  
    121121    OneLinerFormatter"""
    122122
    123     _wiki_modules = "|".join([k for k, v in modules.items() if v[2]])
     123    # regexp fragments for Trac objects:
     124    _page_name = ("(^|(?<=[^A-Za-z]))" # start of string or positive lookbehind is not a letter
     125                  "[A-Z]"              # first letter must be a capitalized letter,
     126                  "[a-z]+"             #  followed by some lower case
     127                  "(?:[A-Z][a-z]*[a-z/])+" # ... followed by one or more wiki page 'component'
     128                  "(?:#[A-Za-z0-9]+)?" # optional reference to a section anchor
     129                  "(?=\Z|\s|[.,;:!?\)}\]])" # lookahed for something indicating the end of the name
     130                  )
     131    _ticket_id = "\d+"
     132    _changeset_id = "\d+"
     133    _report_id = "\d+"
     134
     135    _wiki_ref_modules = "|".join([k for k, v in modules.items() if v[2]])
     136    _module_args = "(&#34;(.*?)&#34;|'(.*?)')|([^ ]*[^'~_\., \)])"
     137
     138    # regexp fragments for InterTrac support:
     139    _project_name = "[a-zA-Z0-9-_]+"
     140    _project_key = "[a-zA-Z]{,3}" # allow at most 3 letters for a project shorthand
     141    # Note: the end of _project_key should be differentiable
     142    #       from the start of _ticket_id and _changeset_id
     143
    124144   
    125145    _rules = [r"(?P<bold>''')",
     
    131151              r"(?P<inlinecode>!?\{\{\{(?P<inline>.*?)\}\}\})",
    132152              r"(?P<htmlescapeentity>!?&#\d+;)",
    133               # InterTrac support:
    134               r"(?P<it_tickethref>!?#((?P<it_ticket>[a-zA-z]+)\d+))",
    135               r"(?P<it_changesethref>!?(\[(?P<it_changeset>[a-zA-z]+)\d+\]))",
    136               r"(?P<it_modulehref>!?((?P<it_modulename>%s):(?P<it_module>[a-zA-z]+):(?P<it_moduleargs>(&#34;(.*?)&#34;|'(.*?)')|([^ ]*[^'~_\., \)]))))" % _wiki_modules,
    137               r"(?P<tickethref>!?#\d+)",
    138               r"(?P<changesethref>!?(\[\d+\]|\br\d+\b))",
    139               r"(?P<reporthref>!?\{\d+\})",
    140               r"(?P<modulehref>!?((?P<modulename>%s):(?P<moduleargs>(&#34;(.*?)&#34;|'(.*?)')|([^ ]*[^'~_\., \)]))))" % _wiki_modules,
    141               r"(?P<wikihref>!?(^|(?<=[^A-Za-z]))[A-Z][a-z]+(?:[A-Z][a-z]*[a-z/])+(?:#[A-Za-z0-9]+)?(?=\Z|\s|[.,;:!?\)}\]]))",
    142               r"(?P<fancylink>!?\[(?P<fancyurl>([a-z]+:[^ ]+)) (?P<linkname>.*?)\])"]
     153              # Trac Objects links:
     154              r"(?P<wikihref>!?%s)" % _page_name,
     155              r"(?P<tickethref>!?(?:%s:)?#%s)" % (_project_name, _ticket_id),
     156              r"(?P<changesethref>!?(?:%s:)?\[%s\]|\br%s\b)" % (_project_name, _changeset_id, _changeset_id),
     157              r"(?P<reporthref>!?(?:%s:)?\{%s\})" % (_project_name, _report_id),
     158              # Shorthand InterTrac links:
     159              r"(?P<it_tickethref>!?#((?P<it_ticket>%s)%s))" % (_project_key, _ticket_id),
     160              r"(?P<it_changesethref>!?(\[(?P<it_changeset>%s)%s\]))" % (_project_key, _changeset_id),
     161              r"(?P<it_reporthref>!?(\{(?P<it_report>%s)%s\}))" % (_project_key, _report_id),
     162              # Generic links:
     163              r"(?P<modulehref>!?((?P<it_module>%s:)?(?P<modulename>%s):(?P<moduleargs>%s)))" \
     164              % (_project_name, _wiki_ref_modules, _module_args),
     165              r"(?P<fancylink>!?\[(?P<it_fancy>%s:)?(?P<fancyurl>([a-z]+:[^ ]+)) (?P<linkname>.*?)\])" \
     166              % (_project_name),
     167              ]
    143168
    144169    _open_tags = []
     
    210235        return match
    211236
    212     # InterTrac support:
     237    # Trac Objects links:
     238
     239    def _wikihref_formatter(self, match, fullmatch):
     240        return self._make_wiki_link(match, match)
     241
     242    def _tickethref_formatter(self, match, fullmatch):
     243        sep = match.find(':')
     244        if sep == -1: #  #id
     245            return self._make_ticket_link(match[1:], match)
     246        else:         #  project:#id
     247            intertrac = match[:sep]
     248            id = match[sep+2:]
     249            return self._intertrac_link(intertrac, 'ticket', id, '#'+id, match)
     250
     251    def _changesethref_formatter(self, match, fullmatch):
     252        if match[0] == 'r':
     253            return self._make_changeset_link(match[1:], match)
     254        else:
     255            sep = match.find(':')
     256            if sep == -1: # [id]
     257                return self._make_changeset_link(match[1:-1], match)
     258            else:         # project:[id]
     259                intertrac = match[:sep]
     260                id = match[sep+2:-1]
     261                return self._intertrac_link(intertrac, 'changeset', id, '[%s]'%id, match)
     262
     263    def _reporthref_formatter(self, match, fullmatch):
     264        sep = match.find(':')
     265        if sep == -1: # {id}
     266            return self._make_report_link(match[1:-1], match)
     267        else:
     268            intertrac = match[:sep]
     269            id = match[sep+2:-1]
     270            return self._intertrac_link(intertrac, 'report', id, '{%s}'%id, match)
     271
     272    # Shorthand InterTrac links:
     273
    213274    def _it_tickethref_formatter(self, match, fullmatch):
    214275        intertrac = fullmatch.group('it_ticket')
    215276        id = match[1+len(intertrac):]
    216         return self._make_intertrac_link(intertrac, 'ticket', id, '#'+id)
     277        return self._intertrac_link(intertrac, 'ticket', id, '#'+id, match)
    217278         
    218279    def _it_changesethref_formatter(self, match, fullmatch):
    219280        intertrac = fullmatch.group('it_changeset')
    220281        id = match[1+len(intertrac):-1]
    221         return self._make_intertrac_link(intertrac, 'changeset', id, '[%s]' % id)
    222 
    223     def _it_modulehref_formatter(self, match, fullmatch):
    224         it_modulename = fullmatch.group('it_modulename')
    225         it_module = fullmatch.group('it_module')
    226         it_moduleargs = fullmatch.group('it_moduleargs')
    227         return self._make_intertrac_link(it_module, it_modulename, it_moduleargs,
    228                                          '%s:%s:%s' % (it_modulename, it_module, it_moduleargs))
    229 
    230     def _tickethref_formatter(self, match, fullmatch):
    231         return self._make_ticket_link(match[1:], match)
    232 
    233     def _changesethref_formatter(self, match, fullmatch):
    234         if match[0] == 'r':
    235             rev = match[1:]
    236         else:
    237             rev = match[1:-1]
    238         return self._make_changeset_link(rev, match)
    239 
    240     def _reporthref_formatter(self, match, fullmatch):
    241         return self._make_report_link(match[1:-1], match)
    242 
    243     def _modulehref_formatter(self, match, fullmatch):
    244         return self._make_module_link(match, match)
    245 
    246     def _wikihref_formatter(self, match, fullmatch):
    247         return self._make_wiki_link(match, match)
    248 
     282        return self._intertrac_link(intertrac, 'changeset', id, '[%s]'%id, match)
     283
     284    def _it_reporthref_formatter(self, match, fullmatch):
     285        intertrac = fullmatch.group('it_report')
     286        id = match[1+len(intertrac):-1]
     287        return self._intertrac_link(intertrac, 'report', id, '{%s}'%id, match)
     288
     289    # Generic links:
     290   
    249291    def _url_formatter(self, match, fullmatch):
    250292        return self._make_ext_link(match, match)
    251293
     294    def _modulehref_formatter(self, match, fullmatch):
     295        it_module = fullmatch.group('it_module')
     296        modulename = fullmatch.group('modulename')
     297        moduleargs = fullmatch.group('moduleargs')
     298        if it_module:
     299            return self._intertrac_link(it_module[:-1], modulename, moduleargs,
     300                                             '%s:%s' % (modulename, moduleargs), match)
     301        else:
     302            return self._make_module_link(match, match)
     303
    252304    def _fancylink_formatter(self, match, fullmatch):
     305        it_fancy = fullmatch.group('it_fancy')
    253306        link = fullmatch.group('fancyurl')
    254307        text = fullmatch.group('linkname')
    255         return self._make_module_link(link, text)
     308        if it_fancy:
     309            sep = link.index(':')
     310            modulename = link[:sep]
     311            moduleargs = link[sep+1:]
     312            return self._intertrac_link(it_fancy[:-1], modulename, moduleargs, link, text)
     313        else:
     314            return self._make_module_link(link, text)
    256315
    257316    # InterTrac support:
    258     def _make_intertrac_link(self, intertrac, module, id, display_id):
    259         href = self.env.get_config('intertrac', intertrac.upper() + '.trac')
     317    def _intertrac_link(self, intertrac, module, id, target, text):
     318        # first, check if it is a project key
     319        intertrac = self.env.get_config('intertrac', intertrac.upper() + '.key', intertrac)
     320        # check if the project name is the one of a sibling environment:
     321        if self.env.siblings.has_key(intertrac):
     322            intertrac_env = self.env.siblings[intertrac]
     323            intertrac_fmt = OneLinerFormatter(intertrac_env, intertrac_env.get_db_cnx(), 1)
     324            return re.sub(intertrac_fmt._compiled_rules, intertrac_fmt.replace, target).replace(target, text)
     325        # otherwise, rely on project names that were configured
     326        href = self.env.get_config('intertrac', intertrac.upper() + '.url')
    260327        if href:
    261             title = self.env.get_config('intertrac', intertrac.upper() + '.title')
     328            title = '%s %s in %s' % (module, id,
     329                                     self.env.get_config('intertrac', intertrac.upper() + '.title'))
    262330            _class = 'intertrac'
    263331        else:
     
    266334            href = self._local # FIXME: should stay on the current page
    267335        return '<a class="%s" title="%s" href="%s/%s/%s">%s</a>' % (
    268             _class, title, href, module, id, display_id)
     336            _class, title, href, module, id, text)
    269337
    270338
     
    426494                        'modulename', 'moduleargs',
    427495                        # InterTrac support:
    428                         'it_ticket', 'it_changeset',
    429                         'it_modulename', 'it_module', 'it_moduleargs')
     496                        'it_ticket', 'it_changeset', 'it_report', 'it_fancy', 'it_module')
    430497
    431498    # Forbid "dangerous" HTML tags and attributes
  • branches/cboos-dev/intertrac-branch/trac/env.py

    r1443 r1508  
    4747    def __init__(self, path, create=0):
    4848        self.path = path
     49        self.siblings = {}
    4950        if create:
    5051            self.create()
  • branches/cboos-dev/intertrac-branch/trac/web/main.py

    r1457 r1508  
    257257    from trac.Wiki import populate_page_dict
    258258    populate_page_dict(db, env)
     259    # FIXME: this dictionary should be created once and then
     260    #        maintained by the Wiki object after creation/deletion,
    259261
    260262    try:
  • branches/cboos-dev/intertrac-branch/trac/web/modpython_frontend.py

    r1474 r1508  
    178178        if not env_path in env_cache:
    179179            env_cache[env_path] = open_environment(env_path)
     180            # TODO: also have a projects dictionary shared by siblings, like in tracd?
    180181        env = env_cache[env_path]
    181182    finally:
  • branches/cboos-dev/intertrac-branch/trac/web/standalone.py

    r1423 r1508  
    148148            auth = auths.get(project, None)
    149149            env = open_environment(path)
     150            env.auth = auth
     151            env.siblings = self.projects
    150152            env.href = href.Href('/' + project)
    151153            env.abs_href = href.Href('http://%s/%s' % (self.http_host, project))
    152154            env.set_config('trac', 'htdocs_location', '/trac_common/')
    153155            self.projects[project] = env
    154             self.projects[project].auth = auth
    155156
    156157
Note: See TracChangeset for help on using the changeset viewer.