id,summary,reporter,owner,description,type,status,priority,component,severity,resolution,keywords,cc,release 2861,SubversionFind macro,anonymous,anybody,"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: `HelloWorld::HelloWorld` It's comfortable if the HelloWorld method moves or changes in the `example.c` code. I wrote the macros: {{{#!python # -*- coding: utf-8 -*- import sys from trac.core import * from trac.wiki.macros import WikiMacroBase from trac.wiki.macros 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 trac.web.chrome import add_link, add_stylesheet, INavigationContributor from trac.wiki 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 CHUNK_SIZE = 4096 class SvnQuery(WikiMacroBase): implements(IPermissionRequestor) 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) formatter.perm.assert_permission('FILE_VIEW') content = node.get_content() import StringIO as StringIO self.strin = StringIO.StringIO('') chunk = content.read(CHUNK_SIZE) res=-1 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() return self.strin.write(chunk) chunk = content.read(CHUNK_SIZE) return '' # return 'SvnQuery: ' + formatter.href.browser(content, format = 'raw') def find_line(self, str, fmt): res = -1 i = 1 self.strin.seek(0) # 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 gmail.com",enhancement,new,normal,Request-a-Hack,normal,,,,0.10