Skip to content

Commit 9c9f12e

Browse files
Improved website/issues/extensions/local_replace.py and hg copied it over to the devel and responsive templates.
* Added a substitution for the default hg output format. * Used a base url variable for the two hg substitutions.
1 parent dfe1d3d commit 9c9f12e

File tree

3 files changed

+88
-36
lines changed

3 files changed

+88
-36
lines changed
Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import re
22

3-
substitutions = [ (re.compile('debian:\#(?P<id>\d+)'),
4-
'<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=\g<id>">debian#\g<id></a>' ),
5-
(re.compile('\#(?P<ws>\s*)(?P<id>\d+)'),
6-
"<a href='issue\g<id>'>#\g<ws>\g<id></a>" ),
7-
(re.compile('(?P<prews>^|\s+)(?P<revstr>(revision|rev|r)\s?)(?P<revision>[\da-fA-F]+)(?P<post>\W+|$)'),
8-
"\g<prews><a href='http://sourceforge.net/p/roundup/code/ci/\g<revision>'>\g<revstr>\g<revision></a>\g<post>"),
3+
hg_url_base = r'http://sourceforge.net/p/roundup/code/ci/'
4+
5+
substitutions = [ (re.compile(r'debian:\#(?P<id>\d+)'),
6+
r'<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=\g<id>">debian#\g<id></a>' ),
7+
(re.compile(r'\#(?P<ws>\s*)(?P<id>\d+)'),
8+
r"<a href='issue\g<id>'>#\g<ws>\g<id></a>" ),
9+
(re.compile(r'(?P<prews>^|\s+)issue(?P<ws>\s*)(?P<id>\d+)'),
10+
r"\g<prews><a href='issue\g<id>'>issue\g<ws>\g<id></a>" ),
11+
# matching the typical number:hash format of hg's own output
12+
# and then use use hash instead of the number
13+
(re.compile(r'(?P<prews>(^|\s+))(?P<revstr>(rev|hg))(?P<revnumber>\d+):(?P<refhash>[0-9a-fA-F]{12,40})(?P<post>\W+|$)'),
14+
r'\g<prews><a href="' + hg_url_base + '\g<refhash>">\g<revstr>\g<revnumber>:\g<refhash></a>\g<post>'),
15+
# matching hg revison number or hash
16+
(re.compile(r'(?P<prews>(^|\s+))(?P<revstr>(revision|rev|r)\s?)(?P<revision>([1-9][0-9]*)|[0-9a-fA-F]{4,40})(?P<post>\W+|$)'),
17+
r'\g<prews><a href="' + hg_url_base + '\g<revision>">\g<revstr>\g<revision></a>\g<post>'),
918
]
1019

1120
def local_replace(message):
@@ -19,16 +28,29 @@ def local_replace(message):
1928
def init(instance):
2029
instance.registerUtil('localReplace', local_replace)
2130

31+
def quicktest(msgstr, should_replace = True):
32+
if not should_replace:
33+
print "(no)",
34+
print "'%s' -> '%s'" % (msgstr, local_replace(msgstr))
2235

2336
if "__main__" == __name__:
24-
print " debian:#222", local_replace(" debian:#222")
25-
print " #555", local_replace(" #555")
26-
print " revision 222", local_replace(" revision 222")
27-
print " r 222", local_replace(" r 222")
28-
print " wordthatendswithr 222", local_replace(" wordthatendswithr 222") # should fail
29-
print " references", local_replace(" references") # should fail
30-
print " too many spaces r 222", local_replace(" too many spaces r 222") # should fail
31-
print " r7140eb", local_replace(" r7140eb")
32-
print " rev7140eb ", local_replace(" rev7140eb ")
33-
print "rev7140eb", local_replace("rev7140eb")
34-
print "rev7140eb,", local_replace("rev7140eb,")
37+
print "Replacement examples. '(no)' should result in no replacement:"
38+
quicktest(" debian:#222")
39+
quicktest(" #555")
40+
quicktest("issue333")
41+
quicktest(" revision 222")
42+
quicktest(" r 222")
43+
quicktest(" wordthatendswithr 222", False)
44+
quicktest(" references", False)
45+
quicktest(" too many spaces r 222", False)
46+
quicktest("re-evaluate", False)
47+
quicktest("rex140eb", False)
48+
quicktest("rev 012", False) # too short for a hg hash
49+
quicktest("rev 0123")
50+
quicktest("re140eb")
51+
quicktest(" r7140eb")
52+
quicktest(" rev7140eb ")
53+
quicktest("rev7140eb")
54+
quicktest("rev7140eb,")
55+
quicktest("rev4891:ad3d628e73f2")
56+
quicktest("hg4891:ad3d628e73f2")
Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import re
22

3-
substitutions = [ (re.compile('debian:\#(?P<id>\d+)'),
4-
'<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=\g<id>">debian#\g<id></a>' ),
5-
(re.compile('\#(?P<ws>\s*)(?P<id>\d+)'),
6-
"<a href='issue\g<id>'>#\g<ws>\g<id></a>" ),
7-
(re.compile('(?P<prews>^|\s+)(?P<revstr>(revision|rev|r)\s?)(?P<revision>[\da-fA-F]+)(?P<post>\W+|$)'),
8-
"\g<prews><a href='http://sourceforge.net/p/roundup/code/ci/\g<revision>'>\g<revstr>\g<revision></a>\g<post>"),
3+
hg_url_base = r'http://sourceforge.net/p/roundup/code/ci/'
4+
5+
substitutions = [ (re.compile(r'debian:\#(?P<id>\d+)'),
6+
r'<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=\g<id>">debian#\g<id></a>' ),
7+
(re.compile(r'\#(?P<ws>\s*)(?P<id>\d+)'),
8+
r"<a href='issue\g<id>'>#\g<ws>\g<id></a>" ),
9+
(re.compile(r'(?P<prews>^|\s+)issue(?P<ws>\s*)(?P<id>\d+)'),
10+
r"\g<prews><a href='issue\g<id>'>issue\g<ws>\g<id></a>" ),
11+
# matching the typical number:hash format of hg's own output
12+
# and then use use hash instead of the number
13+
(re.compile(r'(?P<prews>(^|\s+))(?P<revstr>(rev|hg))(?P<revnumber>\d+):(?P<refhash>[0-9a-fA-F]{12,40})(?P<post>\W+|$)'),
14+
r'\g<prews><a href="' + hg_url_base + '\g<refhash>">\g<revstr>\g<revnumber>:\g<refhash></a>\g<post>'),
15+
# matching hg revison number or hash
16+
(re.compile(r'(?P<prews>(^|\s+))(?P<revstr>(revision|rev|r)\s?)(?P<revision>([1-9][0-9]*)|[0-9a-fA-F]{4,40})(?P<post>\W+|$)'),
17+
r'\g<prews><a href="' + hg_url_base + '\g<revision>">\g<revstr>\g<revision></a>\g<post>'),
918
]
1019

1120
def local_replace(message):
@@ -19,16 +28,29 @@ def local_replace(message):
1928
def init(instance):
2029
instance.registerUtil('localReplace', local_replace)
2130

31+
def quicktest(msgstr, should_replace = True):
32+
if not should_replace:
33+
print "(no)",
34+
print "'%s' -> '%s'" % (msgstr, local_replace(msgstr))
2235

2336
if "__main__" == __name__:
24-
print " debian:#222", local_replace(" debian:#222")
25-
print " #555", local_replace(" #555")
26-
print " revision 222", local_replace(" revision 222")
27-
print " r 222", local_replace(" r 222")
28-
print " wordthatendswithr 222", local_replace(" wordthatendswithr 222") # should fail
29-
print " references", local_replace(" references") # should fail
30-
print " too many spaces r 222", local_replace(" too many spaces r 222") # should fail
31-
print " r7140eb", local_replace(" r7140eb")
32-
print " rev7140eb ", local_replace(" rev7140eb ")
33-
print "rev7140eb", local_replace("rev7140eb")
34-
print "rev7140eb,", local_replace("rev7140eb,")
37+
print "Replacement examples. '(no)' should result in no replacement:"
38+
quicktest(" debian:#222")
39+
quicktest(" #555")
40+
quicktest("issue333")
41+
quicktest(" revision 222")
42+
quicktest(" r 222")
43+
quicktest(" wordthatendswithr 222", False)
44+
quicktest(" references", False)
45+
quicktest(" too many spaces r 222", False)
46+
quicktest("re-evaluate", False)
47+
quicktest("rex140eb", False)
48+
quicktest("rev 012", False) # too short for a hg hash
49+
quicktest("rev 0123")
50+
quicktest("re140eb")
51+
quicktest(" r7140eb")
52+
quicktest(" rev7140eb ")
53+
quicktest("rev7140eb")
54+
quicktest("rev7140eb,")
55+
quicktest("rev4891:ad3d628e73f2")
56+
quicktest("hg4891:ad3d628e73f2")

website/issues/extensions/local_replace.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import re
22

3+
hg_url_base = r'http://sourceforge.net/p/roundup/code/ci/'
4+
35
substitutions = [ (re.compile(r'debian:\#(?P<id>\d+)'),
46
r'<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=\g<id>">debian#\g<id></a>' ),
57
(re.compile(r'\#(?P<ws>\s*)(?P<id>\d+)'),
68
r"<a href='issue\g<id>'>#\g<ws>\g<id></a>" ),
79
(re.compile(r'(?P<prews>^|\s+)issue(?P<ws>\s*)(?P<id>\d+)'),
810
r"\g<prews><a href='issue\g<id>'>issue\g<ws>\g<id></a>" ),
11+
# matching the typical number:hash format of hg's own output
12+
# and then use use hash instead of the number
13+
(re.compile(r'(?P<prews>(^|\s+))(?P<revstr>(rev|hg))(?P<revnumber>\d+):(?P<refhash>[0-9a-fA-F]{12,40})(?P<post>\W+|$)'),
14+
r'\g<prews><a href="' + hg_url_base + '\g<refhash>">\g<revstr>\g<revnumber>:\g<refhash></a>\g<post>'),
915
# matching hg revison number or hash
10-
(re.compile(r'(?P<prews>^|\s+)(?P<revstr>(revision|rev|r)\s?)(?P<revision>([1-9][0-9]*)|[0-9a-fA-F]{4,40})(?P<post>\W+|$)'),
11-
r"\g<prews><a href='http://sourceforge.net/p/roundup/code/ci/\g<revision>'>\g<revstr>\g<revision></a>\g<post>"),
16+
(re.compile(r'(?P<prews>(^|\s+))(?P<revstr>(revision|rev|r)\s?)(?P<revision>([1-9][0-9]*)|[0-9a-fA-F]{4,40})(?P<post>\W+|$)'),
17+
r'\g<prews><a href="' + hg_url_base + '\g<revision>">\g<revstr>\g<revision></a>\g<post>'),
1218
]
1319

1420
def local_replace(message):
@@ -46,3 +52,5 @@ def quicktest(msgstr, should_replace = True):
4652
quicktest(" rev7140eb ")
4753
quicktest("rev7140eb")
4854
quicktest("rev7140eb,")
55+
quicktest("rev4891:ad3d628e73f2")
56+
quicktest("hg4891:ad3d628e73f2")

0 commit comments

Comments
 (0)