mirror of
https://github.com/moparisthebest/xeps
synced 2024-12-22 07:38:52 -05:00
Create a XML file of the XEP table for bots.
This commit is contained in:
parent
f5d79146a5
commit
2d3924c53f
56
gen.py
56
gen.py
@ -65,9 +65,12 @@ def executeCommand( cmd ):
|
|||||||
error, desc = commands.getstatusoutput( cmd )
|
error, desc = commands.getstatusoutput( cmd )
|
||||||
return error, desc + "\n" + "executed cmd: " + cmd
|
return error, desc + "\n" + "executed cmd: " + cmd
|
||||||
|
|
||||||
|
## creates a HTML table (for the human reader) and XML table (for bots)
|
||||||
class XEPTable:
|
class XEPTable:
|
||||||
def __init__(self, filename):
|
def __init__(self, filename, shortXMLfilename):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
self.shortXMLfilename = shortXMLfilename
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.tableFile = parse(filename)
|
self.tableFile = parse(filename)
|
||||||
except:
|
except:
|
||||||
@ -89,13 +92,25 @@ class XEPTable:
|
|||||||
</tr>''')
|
</tr>''')
|
||||||
self.tableFile.getElementsByTagName("table")[0].appendChild(header.getElementsByTagName("tr")[0])
|
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):
|
def save(self):
|
||||||
f = open(self.filename, "wb")
|
f = open(self.filename, "wb")
|
||||||
self.tableFile.getElementsByTagName("table")[0].normalize()
|
self.tableFile.getElementsByTagName("table")[0].normalize()
|
||||||
f.write(self.tableFile.toxml())
|
f.write(self.tableFile.toxml())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
f = open(self.shortXMLfilename, "wb")
|
||||||
|
self.tableFile.getElementsByTagName("xeps")[0].normalize()
|
||||||
|
f.write(self.tableFile.toxml())
|
||||||
|
f.close()
|
||||||
|
|
||||||
def setXEP(self, info):
|
def setXEP(self, info):
|
||||||
|
## set for HTML table
|
||||||
rows = self.tableFile.getElementsByTagName("tr")
|
rows = self.tableFile.getElementsByTagName("tr")
|
||||||
xeprow = 0
|
xeprow = 0
|
||||||
for row in rows:
|
for row in rows:
|
||||||
@ -130,6 +145,43 @@ class XEPTable:
|
|||||||
col = parseString("<td valign='top'>" + info.getDate() + "</td>")
|
col = parseString("<td valign='top'>" + info.getDate() + "</td>")
|
||||||
xeprow.appendChild(col.getElementsByTagName("td")[0])
|
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 ):
|
def filebase( filename ):
|
||||||
return os.path.splitext(os.path.basename(filename))[0]
|
return os.path.splitext(os.path.basename(filename))[0]
|
||||||
@ -255,7 +307,7 @@ def buildXEP( filename ):
|
|||||||
else:
|
else:
|
||||||
print "Building " + filename + " (FAST MODE)"
|
print "Building " + filename + " (FAST MODE)"
|
||||||
|
|
||||||
x = XEPTable(CONFIGPATH + "/extensions.xml")
|
x = XEPTable(CONFIGPATH + "/extensions.xml", XEPPATH + "/xeps.xml")
|
||||||
xinfo = XEPInfo(xepfilepath, False)
|
xinfo = XEPInfo(xepfilepath, False)
|
||||||
x.setXEP( xinfo )
|
x.setXEP( xinfo )
|
||||||
x.save()
|
x.save()
|
||||||
|
@ -49,8 +49,9 @@ class XEPInfo:
|
|||||||
titleNode = (headerNode.getElementsByTagName("title")[0])
|
titleNode = (headerNode.getElementsByTagName("title")[0])
|
||||||
self.title = getText(titleNode.childNodes)
|
self.title = getText(titleNode.childNodes)
|
||||||
self.nr = getText((headerNode.getElementsByTagName("number")[0]).childNodes)
|
self.nr = getText((headerNode.getElementsByTagName("number")[0]).childNodes)
|
||||||
|
self.shortname = getText((headerNode.getElementsByTagName("shortname")[0]).childNodes)
|
||||||
abstractNode = (headerNode.getElementsByTagName("abstract")[0])
|
abstractNode = (headerNode.getElementsByTagName("abstract")[0])
|
||||||
abstract = getText(abstractNode.childNodes)
|
self.abstract = getText(abstractNode.childNodes)
|
||||||
statusNode = (headerNode.getElementsByTagName("status")[0])
|
statusNode = (headerNode.getElementsByTagName("status")[0])
|
||||||
self.status = getText(statusNode.childNodes)
|
self.status = getText(statusNode.childNodes)
|
||||||
self.type = getText((headerNode.getElementsByTagName("type")[0]).childNodes)
|
self.type = getText((headerNode.getElementsByTagName("type")[0]).childNodes)
|
||||||
@ -80,6 +81,12 @@ class XEPInfo:
|
|||||||
def getTitle(self):
|
def getTitle(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
def getShortname(self):
|
||||||
|
return self.shortname
|
||||||
|
|
||||||
|
def getAbstract(self):
|
||||||
|
return self.abstract
|
||||||
|
|
||||||
def getStatus(self):
|
def getStatus(self):
|
||||||
return self.status
|
return self.status
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user