| 1 |
# -*- coding: utf-8 -*- |
|---|
| 2 |
|
|---|
| 3 |
import sys |
|---|
| 4 |
from trac.core import * |
|---|
| 5 |
from trac.wiki.macros import WikiMacroBase |
|---|
| 6 |
from trac.wiki.macros import IWikiMacroProvider |
|---|
| 7 |
#from trac.versioncontrol.api import NoSuchChangeset |
|---|
| 8 |
from trac.versioncontrol.web_ui.util import * |
|---|
| 9 |
|
|---|
| 10 |
import re |
|---|
| 11 |
import urllib |
|---|
| 12 |
import os.path |
|---|
| 13 |
from fnmatch import fnmatchcase |
|---|
| 14 |
|
|---|
| 15 |
from trac import util |
|---|
| 16 |
from trac.config import ListOption, Option |
|---|
| 17 |
#from trac.core import * |
|---|
| 18 |
from trac.mimeview import Mimeview, is_binary, get_mimetype |
|---|
| 19 |
from trac.perm import IPermissionRequestor |
|---|
| 20 |
from trac.util import sorted, embedded_numbers |
|---|
| 21 |
from trac.util.datefmt import http_date, format_datetime, pretty_timedelta |
|---|
| 22 |
from trac.util.html import escape, html, Markup |
|---|
| 23 |
from trac.util.text import pretty_size |
|---|
| 24 |
from trac.web import IRequestHandler, RequestDone |
|---|
| 25 |
from trac.web.chrome import add_link, add_stylesheet, INavigationContributor |
|---|
| 26 |
from trac.wiki import wiki_to_html, IWikiSyntaxProvider |
|---|
| 27 |
from trac.versioncontrol.api import NoSuchChangeset |
|---|
| 28 |
from trac.versioncontrol.web_ui.util import * |
|---|
| 29 |
from trac.web.href import Href |
|---|
| 30 |
|
|---|
| 31 |
from urllib import quote, urlencode |
|---|
| 32 |
from trac.util.text import unicode_quote, unicode_urlencode |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
from svn import core, fs, ra |
|---|
| 36 |
import codecs |
|---|
| 37 |
from StringIO import StringIO |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
CHUNK_SIZE = 4096 |
|---|
| 41 |
|
|---|
| 42 |
class SvnQuery(WikiMacroBase): |
|---|
| 43 |
|
|---|
| 44 |
implements(IPermissionRequestor) |
|---|
| 45 |
|
|---|
| 46 |
def get_permission_actions(self): |
|---|
| 47 |
return ['BROWSER_VIEW', 'FILE_VIEW'] |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
""" Usage: `[[SvnQuery]]` """ |
|---|
| 51 |
def render_macro(self, formatter, name, content): |
|---|
| 52 |
if not content: |
|---|
| 53 |
return 'Not Argument for SvnQuery' |
|---|
| 54 |
|
|---|
| 55 |
args = content.split(',') |
|---|
| 56 |
if len(args) == 0: |
|---|
| 57 |
raise Exception("No argument.") |
|---|
| 58 |
|
|---|
| 59 |
# print 'args:' + args[0].encode('utf-8') |
|---|
| 60 |
repos = self.env.get_repository(formatter.authname) |
|---|
| 61 |
|
|---|
| 62 |
node = get_existing_node(formatter, repos, args[1].encode('utf-8').strip(), repos.youngest_rev) |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
formatter.perm.assert_permission('FILE_VIEW') |
|---|
| 66 |
|
|---|
| 67 |
content = node.get_content() |
|---|
| 68 |
import StringIO as StringIO |
|---|
| 69 |
self.strin = StringIO.StringIO('') |
|---|
| 70 |
chunk = content.read(CHUNK_SIZE) |
|---|
| 71 |
|
|---|
| 72 |
res=-1 |
|---|
| 73 |
i = 0 |
|---|
| 74 |
self.str = '' |
|---|
| 75 |
while 1: |
|---|
| 76 |
if not chunk: |
|---|
| 77 |
n = self.find_line(args[2].encode('utf-8'), formatter) |
|---|
| 78 |
if n != -1: |
|---|
| 79 |
return Markup(html.A(args[0].encode('utf-8'), href=formatter.href.browser(args[1].encode('utf-8').strip()) + '#L%d' % n |
|---|
| 80 |
, style='padding:0; border:none') ).sanitize() |
|---|
| 81 |
return |
|---|
| 82 |
self.strin.write(chunk) |
|---|
| 83 |
chunk = content.read(CHUNK_SIZE) |
|---|
| 84 |
return '' |
|---|
| 85 |
# return 'SvnQuery: ' + formatter.href.browser(content, format = 'raw') |
|---|
| 86 |
def find_line(self, str, fmt): |
|---|
| 87 |
res = -1 |
|---|
| 88 |
i = 1 |
|---|
| 89 |
self.strin.seek(0) |
|---|
| 90 |
# line = self.strin.readline() |
|---|
| 91 |
for line in self.strin.readlines():#while 1: |
|---|
| 92 |
if line.find(str) != -1: |
|---|
| 93 |
res = i |
|---|
| 94 |
return res |
|---|
| 95 |
#line = self.strin.readline() |
|---|
| 96 |
i = i + 1 |
|---|
| 97 |
|
|---|
| 98 |
return -1 |
|---|