- change HH object init call.
- override carbon readFile function and hack so minidom can read it
This commit is contained in:
Worros 2008-11-09 10:46:14 +10:00
parent 7df572895b
commit 328bba2d23
3 changed files with 36 additions and 10 deletions

View File

@ -21,6 +21,7 @@
# Standard Library modules
import Configuration
import traceback
import sys
import xml.dom.minidom
from xml.dom.minidom import Node
from HandHistoryConverter import HandHistoryConverter
@ -50,8 +51,7 @@ from HandHistoryConverter import HandHistoryConverter
class CarbonPoker(HandHistoryConverter):
def __init__(self, config, filename):
print "Initialising Carbon Poker converter class"
HandHistoryConverter.__init__(self, config, filename) # Call super class init
self.sitename = "Carbon"
HandHistoryConverter.__init__(self, config, filename, "Carbon") # Call super class init
self.setFileType("xml")
def readSupportedGames(self):
@ -68,8 +68,23 @@ class CarbonPoker(HandHistoryConverter):
def readAction(self):
pass
# Override read function as xml.minidom barfs on the Carbon layout
# This is pretty dodgy
def readFile(self, filename):
print "Carbon: Reading file: '%s'" %(filename)
infile=open(filename, "rU")
self.obs = infile.read()
infile.close()
self.obs = "<CarbonHHFile>\n" + self.obs + "</CarbonHHFile>"
try:
doc = xml.dom.minidom.parseString(self.obs)
self.doc = doc
except:
traceback.print_exc(file=sys.stderr)
if __name__ == "__main__":
c = Configuration.Config()
e = CarbonPoker(c, "regression-test-files/carbon-poker/Niagara Falls (15245216).xml")
e.processFile()
print str(e)

View File

@ -22,7 +22,7 @@ from HandHistoryConverter import HandHistoryConverter
class Everleaf(HandHistoryConverter):
def __init__(self, config, file):
print "Initialising Everleaf converter class"
HandHistoryConverter.__init__(self, config, file) # Call super class init.
HandHistoryConverter.__init__(self, config, file, "Everleaf") # Call super class init.
self.sitename = "Everleaf"
self.setFileType("text")
@ -44,5 +44,6 @@ class Everleaf(HandHistoryConverter):
if __name__ == "__main__":
c = Configuration.Config()
e = Everleaf(c, "regression-test-files/everleaf/Speed_Kuala.txt")
e.processFile()
print str(e)

View File

@ -15,21 +15,30 @@
#In the "official" distribution you can find the license in
#agpl-3.0.txt in the docs folder of the package.
import Configuration
import sys
import traceback
import xml.dom.minidom
from xml.dom.minidom import Node
class HandHistoryConverter:
def __init__(self, config, file):
def __init__(self, config, file, sitename):
print "HandHistory init called"
self.c = config
self.sitename = ""
self.sitename = sitename
self.obs = "" # One big string
self.filetype = "text"
self.doc = None # For XML based HH files
self.file = file
self.hhbase = self.c.get_import_parameters().get("hhArchiveBase")
self.hhdir = self.hhbase + sitename
def __str__(self):
tmp = "HandHistoryConverter: '%s'\n" % (self.sitename)
tmp = tmp + "\thhbase: %s\n" % (self.hhbase)
tmp = tmp + "\tfiletype: %s\n" % (self.filetype)
tmp = tmp + "\thhbase: '%s'\n" % (self.hhbase)
tmp = tmp + "\thhdir: '%s'\n" % (self.hhdir)
tmp = tmp + "\tfiletype: '%s'\n" % (self.filetype)
tmp = tmp + "\tinfile: '%s'\n" % (self.file)
return tmp
# Functions to be implemented in the inheriting class
@ -45,14 +54,15 @@ class HandHistoryConverter:
self.filetype = filetype
def processFile(self):
self.readFile()
self.readFile(self.file)
def readFile(self, filename):
"""Read file"""
print "Reading file: '%s'" %(filename)
if(self.filetype == "text"):
infile=open(filename, "rU")
self.obs = readfile(inputFile)
inputFile.close()
self.obs = infile.read()
infile.close()
elif(self.filetype == "xml"):
try:
doc = xml.dom.minidom.parse(filename)