forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_url
executable file
·54 lines (44 loc) · 1.65 KB
/
check_url
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
import sys
import os
# Warning: The following code assumes that this file is located in the svn
# checkout directory, and hasn't been moved:
ietfpath = os.path.abspath(__file__.rsplit("/", 1)[0] + "/..")
sys.path.append(ietfpath)
os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings"
from ietf.utils.soup2text import soup2text as html2text
from difflib import unified_diff
import urllib2 as urllib
from ietf.tests import read_testurls
django_server = os.environ.get("DJANGO_SERVER", "http://merlot.tools.ietf.org:31415")
django_server.rstrip("/")
testtuples = []
for root, dirs, files in os.walk(ietfpath):
if "testurl.list" in files:
testtuples += read_testurls(root+"/testurl.list")
if "testurls.list" in files:
testtuples += read_testurls(root+"/testurls.list")
testurls = dict([ (tuple[1], tuple) for tuple in testtuples ])
def fetch(url):
file = urllib.urlopen(url)
html = file.read()
file.close()
return html
for url in sys.argv[1:]:
tuple = testurls[url]
if len(tuple) > 2:
url1 = tuple[2]
url2 = django_server + tuple[1]
print "Fetching %s ..." % url1
text1 = html2text(fetch(url1), fill=False)
text1 = text1.replace('."', '".').replace(',"', '",')
list1 = text1.split("\n")
print "Fetching %s ..." % url2
text2 = html2text(fetch(url2), fill=False)
text2 = text2.replace('."', '".').replace(',"', '",')
list2 = text2.split("\n")
diff = "\n".join(unified_diff(list1, list2, url1, url2, "", "", 0, lineterm=""))
if diff:
print diff
else:
print "\nNo difference found"