1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-12-21 23:28:51 -05:00

Create a XML file of the XEP table for bots.

This commit is contained in:
Tobias Markmann 2010-10-08 00:56:23 +02:00
parent f5d79146a5
commit 2d3924c53f
2 changed files with 63 additions and 4 deletions

58
gen.py
View File

@ -65,9 +65,12 @@ def executeCommand( cmd ):
error, desc = commands.getstatusoutput( cmd )
return error, desc + "\n" + "executed cmd: " + cmd
## creates a HTML table (for the human reader) and XML table (for bots)
class XEPTable:
def __init__(self, filename):
def __init__(self, filename, shortXMLfilename):
self.filename = filename
self.shortXMLfilename = shortXMLfilename
try:
self.tableFile = parse(filename)
except:
@ -88,14 +91,26 @@ class XEPTable:
<th align='left'>Date</th>
</tr>''')
self.tableFile.getElementsByTagName("table")[0].appendChild(header.getElementsByTagName("tr")[0])
try:
self.botsFile = parse(shortXMLfilename)
except:
impl = getDOMImplementation()
self.tableFile = impl.createDocument(None, "xeps", None)
def save(self):
f = open(self.filename, "wb")
self.tableFile.getElementsByTagName("table")[0].normalize()
f.write(self.tableFile.toxml())
f.close()
f = open(self.shortXMLfilename, "wb")
self.tableFile.getElementsByTagName("xeps")[0].normalize()
f.write(self.tableFile.toxml())
f.close()
def setXEP(self, info):
## set for HTML table
rows = self.tableFile.getElementsByTagName("tr")
xeprow = 0
for row in rows:
@ -130,6 +145,43 @@ class XEPTable:
col = parseString("<td valign='top'>" + info.getDate() + "</td>")
xeprow.appendChild(col.getElementsByTagName("td")[0])
## set for bots file
xeps = self.botsFile.getElementsByTagName("xep")
xep = 0
for xeps_xep in xeps:
if xeps_xep.getElementsByTagName("number")[0].firstChild.data == info.getNr():
xep = xeps_xep
break
if xep == 0:
xep = self.botsFile.createElement("xep")
self.botsFile.getElementsByTagName("xeps")[0].appendChild(xep)
self.botsFile.getElementsByTagName("xeps")[0].appendChild(self.botsFile.createTextNode('''
'''))
else:
while(xep.hasChildNodes()):
xep.removeChild(xep.firstChild)
child = parseString("<number>" + info.getNr() + "</number>")
xep.appendChild(child.getElementsByTagName("number"))
child = parseString("<name>" + info.getTitle() + "</name>")
xep.appendChild(child.getElementsByTagName("name"))
child = parseString("<type>" + info.getType() + "</type>")
xep.appendChild(child.getElementsByTagName("type"))
child = parseString("<status>" + info.getStatus() + "</status>")
xep.appendChild(child.getElementsByTagName("status"))
child = parseString("<updated>" + info.getDate() + "</updated>")
xep.appendChild(child.getElementsByTagName("updated"))
child = parseString("<shortname>" + info.getShortname() + "</shortname>")
xep.appendChild(child.getElementsByTagName("shortname"))
child = parseString("<abstract>" + info.getAbstract() + "</abstract>")
xep.appendChild(child.getElementsByTagName("abstract"))
def filebase( filename ):
return os.path.splitext(os.path.basename(filename))[0]
@ -255,7 +307,7 @@ def buildXEP( filename ):
else:
print "Building " + filename + " (FAST MODE)"
x = XEPTable(CONFIGPATH + "/extensions.xml")
x = XEPTable(CONFIGPATH + "/extensions.xml", XEPPATH + "/xeps.xml")
xinfo = XEPInfo(xepfilepath, False)
x.setXEP( xinfo )
x.save()

View File

@ -49,8 +49,9 @@ class XEPInfo:
titleNode = (headerNode.getElementsByTagName("title")[0])
self.title = getText(titleNode.childNodes)
self.nr = getText((headerNode.getElementsByTagName("number")[0]).childNodes)
self.shortname = getText((headerNode.getElementsByTagName("shortname")[0]).childNodes)
abstractNode = (headerNode.getElementsByTagName("abstract")[0])
abstract = getText(abstractNode.childNodes)
self.abstract = getText(abstractNode.childNodes)
statusNode = (headerNode.getElementsByTagName("status")[0])
self.status = getText(statusNode.childNodes)
self.type = getText((headerNode.getElementsByTagName("type")[0]).childNodes)
@ -80,6 +81,12 @@ class XEPInfo:
def getTitle(self):
return self.title
def getShortname(self):
return self.shortname
def getAbstract(self):
return self.abstract
def getStatus(self):
return self.status