Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Most of the Python Matrix #74

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
- name: Install Perl dependencies
run: |
sudo apt-get update
sudo apt-get install libwww-perl
sudo apt-get install libwww-perl libfile-copy-recursive-perl
- name: Run Tests
run: perl run_tests.pl
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
.venv
269 changes: 145 additions & 124 deletions autobuild_rss.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
#!/usr/bin/python
#!/usr/bin/env python3

from optparse import OptionParser
import sys, string
import sys
import string
import xml.sax
import xml.sax.handler
from xml.dom.minidom import getDOMImplementation
from datetime import datetime

rfc822 = "%a, %d %b %Y %H:%M:%S GMT"

def parse_args ():
parser = OptionParser ()

parser.add_option ("-i", dest="input", default="",
help="Scoreboard configuration file to generate reports")
parser.add_option ("-o", dest="output", default="",
help="Filename to output report to")
parser.add_option ("-n", dest="number", default=10,
help="Number of recent builds to include")
parser.add_option ("--uri-regex", dest="uri_regex", default="", nargs=2,
help="Regular expression used to transform URIs. Must be two strings, separated by a space, ie: --uri-regex search replace")
parser.add_option ("-a", dest="name", default="DOC Group Scoreboard",
help="Feed name")
return parser.parse_args ()
def parse_args():
parser = OptionParser()

parser.add_option("-i", dest="input", default="",
help="Scoreboard configuration file to generate reports")
parser.add_option("-o", dest="output", default="",
help="Filename to output report to")
parser.add_option("-n", dest="number", default=10,
help="Number of recent builds to include")
parser.add_option(
"--uri-regex",
dest="uri_regex",
default="",
nargs=2,
help="Regular expression used to transform URIs. Must be two strings, separated by a space, ie: --uri-regex search replace")
parser.add_option("-a", dest="name", default="DOC Group Scoreboard",
help="Feed name")
return parser.parse_args()


(opts, args) = parse_args()

(opts, args) = parse_args ()

class ScoreboardHandler (xml.sax.handler.ContentHandler):
def __init__ (self):
self.pos = list ()
self.state = dict ()
self.builds = list ()
def __init__(self):
self.pos = list()
self.state = dict()
self.builds = list()
return

def startElement (self, name, attrs):
self.pos.append (name)
def startElement(self, name, attrs):
self.pos.append(name)

if name == "build":
self.state["name"] = ""
Expand All @@ -43,184 +51,197 @@ def startElement (self, name, attrs):

return

def characters (self, content):
def characters(self, content):
name = self.pos[-1]

self.state[name] = content

def endElement (self, name):
def endElement(self, name):

if self.pos.pop () != name:
print "ERROR: endElement called for a state we shouldn't be in: " + name
if self.pos.pop() != name:
print("ERROR: endElement called for a state we shouldn't be in: " + name)
return

if name == "build":
self.builds.append ((self.state["name"], self.state["url"], self.state["sponsor"]))
self.builds.append(
(self.state["name"],
self.state["url"],
self.state["sponsor"]))

# Helper methond to append a text node onto a DOM tree.


def appendTextNode(doc, parent, name, value):
ele = doc.createElement(name)
ele.appendChild(doc.createTextNode(str(value)))
parent.appendChild(ele)

### Helper methond to append a text node onto a DOM tree.
def appendTextNode (doc, parent, name, value) :
ele = doc.createElement (name)
ele.appendChild (doc.createTextNode (str (value)))
parent.appendChild (ele)

class RSSItem :
def __init__ (self):
class RSSItem:
def __init__(self):
self.title = ""
self.link = ""
self.description = ""
self.pubDate = datetime.utcnow ()
self.pubDate = datetime.utcnow()
self.guid = ""

def to_xml (self, parent, doc):
item = doc.createElement ("item")
def to_xml(self, parent, doc):
item = doc.createElement("item")

appendTextNode (doc, item, "title", self.title)
appendTextNode (doc, item, "link", self.link)
appendTextNode (doc, item, "description", self.description)
appendTextNode (doc, item, "pubDate", self.pubDate.strftime (rfc822))
appendTextNode (doc, item, "guid", self.guid)
appendTextNode(doc, item, "title", self.title)
appendTextNode(doc, item, "link", self.link)
appendTextNode(doc, item, "description", self.description)
appendTextNode(doc, item, "pubDate", self.pubDate.strftime(rfc822))
appendTextNode(doc, item, "guid", self.guid)

parent.appendChild (item)
parent.appendChild(item)
return

class RSSChannel :
def __init__ (self):

class RSSChannel:
def __init__(self):
self.title = ""
self.link = ""
self.desc = ""
self.language = "en-us"
self.pubDate = datetime.utcnow ()
self.pubDate = datetime.utcnow()
self.lastBuildDate = self.pubDate
self.generator = "DOC Group Scoreboard RSS System"
self.managingEditor = "[email protected]"
self.webMaster = "[email protected]"
self.items = list ()

def add_item (self, item):
self.items.append (item)

def to_xml (self, parent, doc):
channel = doc.createElement ("channel")
appendTextNode (doc, channel, "title", self.title)
appendTextNode (doc, channel, "link", self.link)
appendTextNode (doc, channel, "description", self.desc)
appendTextNode (doc, channel, "language", self.language)
appendTextNode (doc, channel, "pubDate", self.pubDate.strftime (rfc822))
appendTextNode (doc, channel, "lastBuildDate", self.lastBuildDate.strftime (rfc822))
appendTextNode (doc, channel, "generator", self.generator)
appendTextNode (doc, channel, "managingEditor", self.managingEditor)
appendTextNode (doc, channel, "webMaster", self.webMaster)

parent.appendChild (channel)
self.items = list()

def add_item(self, item):
self.items.append(item)

def to_xml(self, parent, doc):
channel = doc.createElement("channel")
appendTextNode(doc, channel, "title", self.title)
appendTextNode(doc, channel, "link", self.link)
appendTextNode(doc, channel, "description", self.desc)
appendTextNode(doc, channel, "language", self.language)
appendTextNode(doc, channel, "pubDate", self.pubDate.strftime(rfc822))
appendTextNode(
doc,
channel,
"lastBuildDate",
self.lastBuildDate.strftime(rfc822))
appendTextNode(doc, channel, "generator", self.generator)
appendTextNode(doc, channel, "managingEditor", self.managingEditor)
appendTextNode(doc, channel, "webMaster", self.webMaster)

parent.appendChild(channel)
for item in self.items:
item.to_xml (channel, doc)
item.to_xml(channel, doc)


class RSS :
def __init__ (self):
self.channels = list ()
class RSS:
def __init__(self):
self.channels = list()

def add_channel (self, channel):
self.channels.append (channel)
def add_channel(self, channel):
self.channels.append(channel)

def to_xml (self, outFile):
impl = xml.dom.minidom.getDOMImplementation ()
rssdoc = impl.createDocument (None, "rss", None)
def to_xml(self, outFile):
impl = xml.dom.minidom.getDOMImplementation()
rssdoc = impl.createDocument(None, "rss", None)

top = rssdoc.documentElement
top.setAttribute ("version", "2.0")
top.setAttribute("version", "2.0")

for channel in self.channels:
channel.to_xml (top, rssdoc)
channel.to_xml(top, rssdoc)

outfile = file (opts.output, 'w')
outfile.write (rssdoc.toprettyxml (" "))
outfile = file(opts.output, 'w')
outfile.write(rssdoc.toprettyxml(" "))
outfile.close

# Clean up
rssdoc.unlink ()
rssdoc.unlink()


def parse (filename):
handler = ScoreboardHandler ()
parser = xml.sax.make_parser ()
parser.setContentHandler (handler)
def parse(filename):
handler = ScoreboardHandler()
parser = xml.sax.make_parser()
parser.setContentHandler(handler)

infile = file (filename, 'r')
parser.parse (infile)
infile.close ()
infile = file(filename, 'r')
parser.parse(infile)
infile.close()

return handler

def fetch_latest (builds):

def fetch_latest(builds):
import re
from urllib import urlopen
from urllib.request import urlopen

latest_builds = list ()
latest_builds = list()

valid_latest = re.compile ("\d\d\d\d_\d\d")
valid_latest = re.compile("\\d\\d\\d\\d_\\d\\d")

for build in builds:
try:
uri = build[1]

if opts.uri_regex != "":
uri = re.sub (opts.uri_regex[0],
opts.uri_regex[1],
uri)
if opts.uri_regex:
uri = re.sub(opts.uri_regex[0],
opts.uri_regex[1],
uri)

latest = urlopen (uri + "/latest.txt")
latest = urlopen(uri + "/latest.txt")

#Get the contents, and make sure it represents a valid latest file
string = latest.read ()
if valid_latest.match (string) != None:
latest_builds.append ((build[0],build[1],string))
# Get the contents, and make sure it represents a valid latest file
string = latest.read()
if valid_latest.match (string) is not None:
latest_builds.append((build[0], build[1], string))
else:
print "ERROR: " + build[0] + " returned an invalid latest file!"
latest.close ()
except:
print "Error: Failed to open latest file for " + build[0]
print("ERROR: " + build[0] + " returned an invalid latest file!")
latest.close()
except BaseException:
print("Error: Failed to open latest file for " + build[0])

return latest_builds

def main ():
# (opts, args) = parse_args ()

def main():
if (opts.input == "") or (opts.output == ""):
print "Error: Must supply both -i and -o arguments."
return -1
print("Error: Must supply both -i and -o arguments.")
return 1

handler = parse (opts.input)
latest = fetch_latest (handler.builds)
handler = parse(opts.input)
latest = fetch_latest(handler.builds)

## Sort in decending order of completion
latest.sort (cmp=lambda x, y: cmp(x[2], y[2]), reverse=True)
# Sort in decending order of completion
latest.sort(cmp=lambda x, y: cmp(x[2], y[2]), reverse=True)

# Prune off all but the request number of entries...
latest = latest[0:int (opts.number)]
latest = latest[0:int(opts.number)]

chan = RSSChannel ()
chan = RSSChannel()
chan.title = opts.name
chan.desc = "Build results"
chan.link = "http://www.dre.vanderbilt.edu/scoreboard"
for build in latest:
item = RSSItem ()
item = RSSItem()
item.title = build[0]
item.link = build[1] + "/index.html"
item.guid = build[1] + "/" + build[2][0:16] + "_Totals.html"
item.description = build[2]
item.pubDate = datetime (int (build[2][0:4]), # Year
int (build[2][5:7]),
int (build[2][8:10]),
int (build[2][11:13]),
int (build[2][14:16]))
chan.add_item (item)
item.pubDate = datetime(int(build[2][0:4]), # Year
int(build[2][5:7]),
int(build[2][8:10]),
int(build[2][11:13]),
int(build[2][14:16]))
chan.add_item(item)

rss = RSS ()
rss.add_channel (chan)
rss = RSS()
rss.add_channel(chan)

rss.to_xml (opts.output)
rss.to_xml(opts.output)

return 0

if __name__ == "__main__":
main ()

if __name__ == "__main__":
main()
Loading
Loading