gettext-ify HandHistoryConverter.py

This commit is contained in:
steffen123 2010-08-14 18:51:42 +02:00
parent fd5e2156b5
commit c87c0f0f9d

View File

@ -123,7 +123,7 @@ Otherwise, finish at EOF.
starttime = time.time() starttime = time.time()
if not self.sanityCheck(): if not self.sanityCheck():
log.warning("Failed sanity check") log.warning(_("Failed sanity check"))
return return
try: try:
@ -131,14 +131,14 @@ Otherwise, finish at EOF.
self.numErrors = 0 self.numErrors = 0
if self.follow: if self.follow:
#TODO: See how summary files can be handled on the fly (here they should be rejected as before) #TODO: See how summary files can be handled on the fly (here they should be rejected as before)
log.info("Tailing '%s'" % self.in_path) log.info(_("Tailing '%s'") % self.in_path)
for handText in self.tailHands(): for handText in self.tailHands():
try: try:
self.processHand(handText) self.processHand(handText)
self.numHands += 1 self.numHands += 1
except FpdbParseError, e: except FpdbParseError, e:
self.numErrors += 1 self.numErrors += 1
log.warning("HHC.start(follow): processHand failed: Exception msg: '%s'" % e) log.warning(_("HHC.start(follow): processHand failed: Exception msg: '%s'") % e)
log.debug(handText) log.debug(handText)
else: else:
handsList = self.allHandsAsList() handsList = self.allHandsAsList()
@ -152,22 +152,22 @@ Otherwise, finish at EOF.
self.processedHands.append(self.processHand(handText)) self.processedHands.append(self.processHand(handText))
except FpdbParseError, e: except FpdbParseError, e:
self.numErrors += 1 self.numErrors += 1
log.warning("HHC.start(): processHand failed: Exception msg: '%s'" % e) log.warning(_("HHC.start(): processHand failed: Exception msg: '%s'") % e)
log.debug(handText) log.debug(handText)
self.numHands = len(handsList) self.numHands = len(handsList)
endtime = time.time() endtime = time.time()
log.info("Read %d hands (%d failed) in %.3f seconds" % (self.numHands, self.numErrors, endtime - starttime)) log.info(_("Read %d hands (%d failed) in %.3f seconds") % (self.numHands, self.numErrors, endtime - starttime))
else: else:
self.parsedObjectType = "Summary" self.parsedObjectType = "Summary"
summaryParsingStatus = self.readSummaryInfo(handsList) summaryParsingStatus = self.readSummaryInfo(handsList)
endtime = time.time() endtime = time.time()
if summaryParsingStatus : if summaryParsingStatus :
log.info("Summary file '%s' correctly parsed (took %.3f seconds)" % (self.in_path, endtime - starttime)) log.info(_("Summary file '%s' correctly parsed (took %.3f seconds)") % (self.in_path, endtime - starttime))
else : else :
log.warning("Error converting summary file '%s' (took %.3f seconds)" % (self.in_path, endtime - starttime)) log.warning(_("Error converting summary file '%s' (took %.3f seconds)") % (self.in_path, endtime - starttime))
except IOError, ioe: except IOError, ioe:
log.exception("Error converting '%s'" % self.in_path) log.exception(_("Error converting '%s'") % self.in_path)
finally: finally:
if self.out_fh != sys.stdout: if self.out_fh != sys.stdout:
self.out_fh.close() self.out_fh.close()
@ -198,7 +198,7 @@ which it expects to find at self.re_TailSplitHands -- see for e.g. Everleaf.py.
time.sleep(interval) time.sleep(interval)
fd.seek(where) fd.seek(where)
else: else:
log.debug("%s changed inode numbers from %d to %d" % (self.in_path, fd_results[1], st_results[1])) log.debug(_("%s changed inode numbers from %d to %d") % (self.in_path, fd_results[1], st_results[1]))
fd = codecs.open(self.in_path, 'r', self.codepage) fd = codecs.open(self.in_path, 'r', self.codepage)
fd.seek(where) fd.seek(where)
else: else:
@ -243,17 +243,17 @@ which it expects to find at self.re_TailSplitHands -- see for e.g. Everleaf.py.
self.obs = self.obs.strip() self.obs = self.obs.strip()
self.obs = self.obs.replace('\r\n', '\n') self.obs = self.obs.replace('\r\n', '\n')
if self.starsArchive == True: if self.starsArchive == True:
log.debug("Converting starsArchive format to readable") log.debug(_("Converting starsArchive format to readable"))
m = re.compile('^Hand #\d+', re.MULTILINE) m = re.compile('^Hand #\d+', re.MULTILINE)
self.obs = m.sub('', self.obs) self.obs = m.sub('', self.obs)
if self.ftpArchive == True: if self.ftpArchive == True:
log.debug("Converting ftpArchive format to readable") log.debug(_("Converting ftpArchive format to readable"))
m = re.compile('^\*\*\*\*\*\*+\s#\s\d+\s\*\*\*\*\*+$', re.MULTILINE) m = re.compile('^\*\*\*\*\*\*+\s#\s\d+\s\*\*\*\*\*+$', re.MULTILINE)
self.obs = m.sub('', self.obs) self.obs = m.sub('', self.obs)
if self.obs is None or self.obs == "": if self.obs is None or self.obs == "":
log.info("Read no hands.") log.info(_("Read no hands."))
return [] return []
return re.split(self.re_SplitHands, self.obs) return re.split(self.re_SplitHands, self.obs)
@ -281,13 +281,13 @@ which it expects to find at self.re_TailSplitHands -- see for e.g. Everleaf.py.
elif gametype['base'] == 'draw': elif gametype['base'] == 'draw':
hand = Hand.DrawHand(self.config, self, self.sitename, gametype, handText) hand = Hand.DrawHand(self.config, self, self.sitename, gametype, handText)
else: else:
log.info("Unsupported game type: %s" % gametype) log.info(_("Unsupported game type: %s" % gametype))
if hand: if hand:
#hand.writeHand(self.out_fh) #hand.writeHand(self.out_fh)
return hand return hand
else: else:
log.info("Unsupported game type: %s" % gametype) log.info(_("Unsupported game type: %s" % gametype))
# TODO: pity we don't know the HID at this stage. Log the entire hand? # TODO: pity we don't know the HID at this stage. Log the entire hand?
# From the log we can deduce that it is the hand after the one before :) # From the log we can deduce that it is the hand after the one before :)
@ -390,7 +390,7 @@ or None if we fail to get the info """
sane = True sane = True
if self.in_path != '-' and self.out_path == self.in_path: if self.in_path != '-' and self.out_path == self.in_path:
print "HH Sanity Check: output and input files are the same, check config" print _("HH Sanity Check: output and input files are the same, check config")
sane = False sane = False
@ -425,7 +425,7 @@ or None if we fail to get the info """
if self.filetype == "text": if self.filetype == "text":
if self.in_path == '-': if self.in_path == '-':
# read from stdin # read from stdin
log.debug("Reading stdin with %s" % self.codepage) # is this necessary? or possible? or what? log.debug(_("Reading stdin with %s") % self.codepage) # is this necessary? or possible? or what?
in_fh = codecs.getreader('cp1252')(sys.stdin) in_fh = codecs.getreader('cp1252')(sys.stdin)
else: else:
for kodec in self.__listof(self.codepage): for kodec in self.__listof(self.codepage):
@ -440,7 +440,7 @@ or None if we fail to get the info """
except: except:
pass pass
else: else:
print "unable to read file with any codec in list!", self.in_path print _("unable to read file with any codec in list!"), self.in_path
self.obs = "" self.obs = ""
elif self.filetype == "xml": elif self.filetype == "xml":
doc = xml.dom.minidom.parse(filename) doc = xml.dom.minidom.parse(filename)
@ -594,13 +594,13 @@ def get_out_fh(out_path, parameters):
try: try:
os.makedirs(out_dir) os.makedirs(out_dir)
except: # we get a WindowsError here in Windows.. pretty sure something else for Linux :D except: # we get a WindowsError here in Windows.. pretty sure something else for Linux :D
log.error("Unable to create output directory %s for HHC!" % out_dir) log.error(_("Unable to create output directory %s for HHC!") % out_dir)
print "*** ERROR: UNABLE TO CREATE OUTPUT DIRECTORY", out_dir print _("*** ERROR: UNABLE TO CREATE OUTPUT DIRECTORY"), out_dir
else: else:
log.info("Created directory '%s'" % out_dir) log.info(_("Created directory '%s'") % out_dir)
try: try:
return(codecs.open(out_path, 'w', 'utf8')) return(codecs.open(out_path, 'w', 'utf8'))
except: except:
log.error("out_path %s couldn't be opened" % (out_path)) log.error(_("out_path %s couldn't be opened") % (out_path))
else: else:
return(sys.stdout) return(sys.stdout)