Author: rjollos
Date: Thu Aug 15 08:23:29 2013
New Revision: 1514197
URL: http://svn.apache.org/r1514197
Log:
Replace `TracGuideToc` with `UserGuideToc` on bh wiki upgrade. Refs #555.
A regression introduced in [1496686], which fixed unintended replacement of
`TracIni` macro markup, also broke the ability to intentionally replace macro
markup. `_do_wiki_rename_links` now supports replacement of macro markup by
using the macro syntax when specifying the word to replace (i.e. wrapping the
!CamelCase word in double brackets).
Modified:
bloodhound/trunk/bloodhound_dashboard/bhdashboard/admin.py
Modified: bloodhound/trunk/bloodhound_dashboard/bhdashboard/admin.py
URL:
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_dashboard/bhdashboard/admin.py?rev=1514197&r1=1514196&r2=1514197&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_dashboard/bhdashboard/admin.py (original)
+++ bloodhound/trunk/bloodhound_dashboard/bhdashboard/admin.py Thu Aug 15
08:23:29 2013
@@ -24,6 +24,7 @@ r"""Project dashboard for Apache(TM) Blo
Administration commands for Bloodhound Dashboard.
"""
import json
+import re
from sys import stdout
from trac.admin.api import IAdminCommandProvider, AdminCommandError
@@ -116,21 +117,24 @@ class BloodhoundAdmin(Component):
redirection.text = _('See [wiki:"%(name)s"].',
name=new_name)
comment = 'Bloodhound guide update'
redirection.save('bloodhound', comment, '0.0.0.0')
- self._do_wiki_rename_links('TracGuideToc', 'UserGuideToc')
+ self._do_wiki_rename_links('[[TracGuideToc]]', '[[UserGuideToc]]')
def _do_wiki_rename_links(self, old_name, new_name):
- import re
+ if old_name.startswith('[[') and old_name.endswith(']]'):
+ pattern = r'%s'
+ else:
+ pattern = r'\b%s\b'
with self.env.db_transaction as db:
pages = db("""SELECT name, text FROM wiki
WHERE text %s
""" % db.like(),
('%' + db.like_escape(old_name) + '%',))
for name, text in pages:
- res = db("""UPDATE wiki
- SET text=%s
- WHERE name=%s
- """,
- (re.sub(r'(?!\[\[)\b%s\b(?!\]\])' % old_name,
new_name, text), name))
+ db("""UPDATE wiki
+ SET text=%s
+ WHERE name=%s
+ """, (re.sub(pattern % re.escape(old_name),
+ new_name, text), name))
def _get_tdump(self, db, table, fields):
"""Dumps all the data from a table for a known set of fields"""