Page MenuHomePhabricator
Paste P11639

pcc-diff
ActivePublic

Authored by Kormat on Jun 23 2020, 10:42 AM.
Tags
None
Referenced Files
F31876242: raw.txt
Jun 23 2020, 10:42 AM
Subscribers
None
#!/usr/bin/python3
import os
import sys
import re
from urllib.request import urlopen
from urllib.parse import urlparse
from bs4 import BeautifulSoup
jenkins_re = re.compile(r'/srv/jenkins-workspace/puppet-compiler/\d+/(production|change)')
def main():
url=sys.argv[1]
if not url.endswith("/"):
url += "/"
base_dir = os.path.join(os.curdir, urlparse(url).path.strip("/"))
prod_dir = os.path.join(base_dir, "prod")
change_dir = os.path.join(base_dir, "change")
os.makedirs(prod_dir)
os.makedirs(change_dir)
print("Fetching %s" % url)
with urlopen(url) as response:
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
h2 = soup.find('h2', string="Hosts that compile with differences")
assert h2 is not None
ul = h2.next_sibling.next_sibling
assert ul.name == 'ul'
for host in ul.find_all('a'):
hostname = host.text
prod = fetch_pson("%s/%s/prod.%s.pson" % (url, hostname, hostname))
with open(os.path.join(prod_dir, "%s.pson" % hostname), "w+") as f:
f.write(prod)
change = fetch_pson("%s/%s/change.%s.pson" % (url, hostname, hostname))
with open(os.path.join(change_dir, "%s.pson" % hostname), "w+") as f:
f.write(change)
os.system("diff --color=auto -urN %s %s" % (prod_dir, change_dir))
def fetch_pson(url):
pson=[]
with urlopen(url) as response:
for line in response:
line_s = line.decode("utf-8")
m = jenkins_re.search(line_s)
if m:
line_s = line_s[:m.start()] + line_s[m.end():]
pson.append(line_s)
return "".join(pson)
if __name__ == '__main__':
main()