Skip to content

Commit 754ba19

Browse files
committed
A small script to run a diff against the master for one single django URL specified in any of the testurl.list files. Uses environment variable DJANGO_SERVER if set, or http://merlot.tools.ietf.org:31415/ otherwise.
- Legacy-Id: 375
1 parent ada5521 commit 754ba19

2 files changed

Lines changed: 56 additions & 5 deletions

File tree

ietf/utils/soup2text.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
except:
88
from BeautifulSoup import Tag, BeautifulSoup, NavigableString
99

10-
block_tags = ["[document]", "html", "body", "div", "blockquote", "table", "tr", "p", "pre", "h1", "h2", "h3", "h4", "h5", "h6", "li"]
11-
space_tags = ["th", "td", "br"]
10+
block_tags = ["[document]", "html", "body", "div", "blockquote", "table", "tr", "p", "pre", "h1", "h2", "h3", "h4", "h5", "h6", "li", "option"]
11+
space_tags = ["th", "td"]
12+
break_tags = ["br"]
1213
ignore_tags = ["head", "script", "style"]
13-
pre_tags = ["pre"]
14+
pre_tags = ["pre", "option"]
1415
entities = [("&lt;", "<"), ("&gt;", ">"),
1516
("&quot;", '"'), ("&apos;", "'"),
1617
("&nbsp;", " "),
@@ -85,8 +86,11 @@ def render(node, encoding='latin-1', pre=False):
8586
node.is_block = True
8687
else:
8788
words.append(child.text)
88-
if child.name in space_tags and not (words and words[-1] and words[-1][-1] in [" ", "\t", "\n"]):
89-
words.append(" ")
89+
if child.text[-1] not in [" ", "\t", "\n"]:
90+
if child.name in space_tags:
91+
words.append(" ")
92+
if child.name in break_tags:
93+
words.append("\n")
9094
else:
9195
raise ValueError("Unexpected node type: '%s'" % child)
9296
if words:

test/check_url

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import os
5+
6+
# Warning: The following code assumes that this file is located in the svn
7+
# checkout directory, and hasn't been moved:
8+
ietfpath = os.path.abspath(__file__.rsplit("/", 1)[0] + "/..")
9+
sys.path.append(ietfpath)
10+
11+
os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings"
12+
13+
from ietf.utils.soup2text import soup2text as html2text
14+
from difflib import unified_diff
15+
import urllib2 as urllib
16+
from ietf.tests import read_testurls
17+
18+
django_server = os.environ.get("DJANGO_SERVER", "http://merlot.tools.ietf.org:31415")
19+
django_server.rstrip("/")
20+
21+
testtuples = []
22+
for root, dirs, files in os.walk(ietfpath):
23+
if "testurl.list" in files:
24+
testtuples += read_testurls(root+"/testurl.list")
25+
if "testurls.list" in files:
26+
testtuples += read_testurls(root+"/testurls.list")
27+
testurls = dict([ (tuple[1], tuple) for tuple in testtuples ])
28+
29+
def fetch(url):
30+
file = urllib.urlopen(url)
31+
html = file.read()
32+
file.close()
33+
return html
34+
35+
for url in sys.argv[1:]:
36+
tuple = testurls[url]
37+
if len(tuple) > 2:
38+
url1 = tuple[2]
39+
url2 = django_server + tuple[1]
40+
print "Fetching %s ..." % url1
41+
text1 = html2text(fetch(url1)).split("\n")
42+
print "Fetching %s ..." % url2
43+
text2 = html2text(fetch(url2)).split("\n")
44+
print "\n".join(unified_diff(text1, text2, url1, url2, "", "", 3, lineterm=""))
45+
46+
47+

0 commit comments

Comments
 (0)