- 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 # Standard Library modules
import Configuration import Configuration
import traceback import traceback
import sys
import xml.dom.minidom import xml.dom.minidom
from xml.dom.minidom import Node from xml.dom.minidom import Node
from HandHistoryConverter import HandHistoryConverter from HandHistoryConverter import HandHistoryConverter
@ -50,8 +51,7 @@ from HandHistoryConverter import HandHistoryConverter
class CarbonPoker(HandHistoryConverter): class CarbonPoker(HandHistoryConverter):
def __init__(self, config, filename): def __init__(self, config, filename):
print "Initialising Carbon Poker converter class" print "Initialising Carbon Poker converter class"
HandHistoryConverter.__init__(self, config, filename) # Call super class init HandHistoryConverter.__init__(self, config, filename, "Carbon") # Call super class init
self.sitename = "Carbon"
self.setFileType("xml") self.setFileType("xml")
def readSupportedGames(self): def readSupportedGames(self):
@ -68,8 +68,23 @@ class CarbonPoker(HandHistoryConverter):
def readAction(self): def readAction(self):
pass 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__": if __name__ == "__main__":
c = Configuration.Config() c = Configuration.Config()
e = CarbonPoker(c, "regression-test-files/carbon-poker/Niagara Falls (15245216).xml") e = CarbonPoker(c, "regression-test-files/carbon-poker/Niagara Falls (15245216).xml")
e.processFile()
print str(e) print str(e)

View File

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

View File

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