Opened 12 years ago

Last modified 3 years ago

#2861 new enhancement

SubversionFind macro

Reported by: anonymous Owned by: anybody
Priority: normal Component: Request-a-Hack
Severity: normal Keywords:
Cc: Trac Release: 0.10

Description (last modified by Ryan J Ollos)

To describe project architecture I had to do macros that seek the string in source subversion file and set reference to first finding string on wiki page.

for example, wiki page code:

[[SvnQuery(HelloWorld,.../_trunk/example.c, HelloWorld::HelloWorld)]]

result: <a href="/trac/browser/.../_trunk/example.c#L480">HelloWorld::HelloWorld</a>

It's comfortable if the HelloWorld method moves or changes in the example.c code.

I wrote the macros:

# -*- coding: utf-8 -*-

import sys 
from trac.core import * 
from import WikiMacroBase
from import IWikiMacroProvider
#from trac.versioncontrol.api import NoSuchChangeset
from trac.versioncontrol.web_ui.util import *

import re
import urllib
import os.path
from fnmatch import fnmatchcase

from trac import util
from trac.config import ListOption, Option
#from trac.core import *
from trac.mimeview import Mimeview, is_binary, get_mimetype
from trac.perm import IPermissionRequestor
from trac.util import sorted, embedded_numbers
from trac.util.datefmt import http_date, format_datetime, pretty_timedelta
from trac.util.html import escape, html, Markup
from trac.util.text import pretty_size
from trac.web import IRequestHandler, RequestDone
from import add_link, add_stylesheet, INavigationContributor
from import wiki_to_html, IWikiSyntaxProvider
from trac.versioncontrol.api import NoSuchChangeset
from trac.versioncontrol.web_ui.util import *
from trac.web.href import Href

from urllib import quote, urlencode
from trac.util.text import unicode_quote, unicode_urlencode

from svn import core, fs, ra
import codecs
from StringIO import StringIO


class SvnQuery(WikiMacroBase):


    def get_permission_actions(self):
        return ['BROWSER_VIEW', 'FILE_VIEW']

    """ Usage: `[[SvnQuery]]` """
    def render_macro(self, formatter, name, content):
        if not content:
            return 'Not Argument for SvnQuery' 

        args = content.split(',')
        if len(args) == 0: 
            raise Exception("No argument.") 

#        print 'args:' + args[0].encode('utf-8')
        repos = self.env.get_repository(formatter.authname)

        node = get_existing_node(formatter, repos, args[1].encode('utf-8').strip(), repos.youngest_rev)


        content = node.get_content()
        import StringIO as StringIO
        self.strin = StringIO.StringIO('')   
        chunk =

        i = 0
        self.str = ''
        while 1:
            if not chunk:
                n = self.find_line(args[2].encode('utf-8'), formatter)
                if n != -1:
                    return Markup(html.A(args[0].encode('utf-8'), href=formatter.href.browser(args[1].encode('utf-8').strip()) + '#L%d' % n
, style='padding:0; border:none') ).sanitize()
            chunk =
        return ''
# return 'SvnQuery: ' + formatter.href.browser(content, format = 'raw')
    def find_line(self, str, fmt):
        res = -1
        i = 1
#        line = self.strin.readline()
        for line in self.strin.readlines():#while 1:
          if line.find(str) != -1:
              res = i
              return res
#line = self.strin.readline()
          i = i + 1

        return -1

Alexander Alyabushev alexhalf NOTDOG

Attachments (1) (3.0 KB) - added by anonymous 12 years ago.
macros SvnQuery

Download all attachments as: .zip

Change History (5)

comment:1 Changed 12 years ago by anonymous

Type: defectenhancement

Changed 12 years ago by anonymous

Attachment: added

macros SvnQuery

comment:2 Changed 11 years ago by Ryan J Ollos

Summary: find in subversionSubversionFind macro

comment:3 Changed 5 years ago by Ryan J Ollos

Description: modified (diff)

comment:4 Changed 3 years ago by figaro

Severity: blockernormal

Modify Ticket

Change Properties
Set your email in Preferences
as new The owner will remain anybody.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.