gettextify fpdb_import.py

This commit is contained in:
steffen123 2010-08-16 02:57:03 +02:00
parent 2115b57142
commit 7a5340f2d8

View File

@ -35,8 +35,19 @@ log = logging.getLogger("importer")
import pygtk import pygtk
import gtk import gtk
# fpdb/FreePokerTools modules import locale
lang=locale.getdefaultlocale()[0][0:2]
if lang=="en":
def _(string): return string
else:
import gettext
try:
trans = gettext.translation("fpdb", localedir="locale", languages=[lang])
trans.install()
except IOError:
def _(string): return string
# fpdb/FreePokerTools modules
import Database import Database
import Configuration import Configuration
import Exceptions import Exceptions
@ -46,14 +57,14 @@ import Exceptions
try: try:
import MySQLdb import MySQLdb
except ImportError: except ImportError:
log.debug("Import database module: MySQLdb not found") log.debug(_("Import database module: MySQLdb not found"))
else: else:
mysqlLibFound = True mysqlLibFound = True
try: try:
import psycopg2 import psycopg2
except ImportError: except ImportError:
log.debug("Import database module: psycopg2 not found") log.debug(_("Import database module: psycopg2 not found"))
else: else:
import psycopg2.extensions import psycopg2.extensions
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
@ -164,9 +175,9 @@ class Importer:
self.siteIds[site] = result[0][0] self.siteIds[site] = result[0][0]
else: else:
if len(result) == 0: if len(result) == 0:
log.error("Database ID for %s not found" % site) log.error(_("Database ID for %s not found") % site)
else: else:
log.error("[ERROR] More than 1 Database ID found for %s - Multiple currencies not implemented yet" % site) log.error(_("[ERROR] More than 1 Database ID found for %s - Multiple currencies not implemented yet") % site)
# Called from GuiBulkImport to add a file or directory. # Called from GuiBulkImport to add a file or directory.
@ -202,7 +213,7 @@ class Importer:
#print " adding file ", file #print " adding file ", file
self.addImportFile(os.path.join(dir, file), site, filter) self.addImportFile(os.path.join(dir, file), site, filter)
else: else:
log.warning("Attempted to add non-directory: '%s' as an import directory" % str(dir)) log.warning(_("Attempted to add non-directory: '%s' as an import directory") % str(dir))
def runImport(self): def runImport(self):
""""Run full import on self.filelist. This is called from GuiBulkImport.py""" """"Run full import on self.filelist. This is called from GuiBulkImport.py"""
@ -212,7 +223,7 @@ class Importer:
# Initial setup # Initial setup
start = datetime.datetime.now() start = datetime.datetime.now()
starttime = time() starttime = time()
log.info("Started at %s -- %d files to import. indexes: %s" % (start, len(self.filelist), self.settings['dropIndexes'])) log.info(_("Started at %s -- %d files to import. indexes: %s") % (start, len(self.filelist), self.settings['dropIndexes']))
if self.settings['dropIndexes'] == 'auto': if self.settings['dropIndexes'] == 'auto':
self.settings['dropIndexes'] = self.calculate_auto2(self.database, 12.0, 500.0) self.settings['dropIndexes'] = self.calculate_auto2(self.database, 12.0, 500.0)
if 'dropHudCache' in self.settings and self.settings['dropHudCache'] == 'auto': if 'dropHudCache' in self.settings and self.settings['dropHudCache'] == 'auto':
@ -221,7 +232,7 @@ class Importer:
if self.settings['dropIndexes'] == 'drop': if self.settings['dropIndexes'] == 'drop':
self.database.prepareBulkImport() self.database.prepareBulkImport()
else: else:
log.debug("No need to drop indexes.") log.debug(_("No need to drop indexes."))
#print "dropInd =", self.settings['dropIndexes'], " dropHudCache =", self.settings['dropHudCache'] #print "dropInd =", self.settings['dropIndexes'], " dropHudCache =", self.settings['dropHudCache']
if self.settings['threads'] <= 0: if self.settings['threads'] <= 0:
@ -240,10 +251,10 @@ class Importer:
(totstored, totdups, totpartial, toterrors) = self.importFiles(self.database, self.writeq) (totstored, totdups, totpartial, toterrors) = self.importFiles(self.database, self.writeq)
if self.writeq.empty(): if self.writeq.empty():
print "writers finished already" print _("writers finished already")
pass pass
else: else:
print "waiting for writers to finish ..." print _("waiting for writers to finish ...")
#for t in threading.enumerate(): #for t in threading.enumerate():
# print " "+str(t) # print " "+str(t)
#self.writeq.join() #self.writeq.join()
@ -253,17 +264,17 @@ class Importer:
while gtk.events_pending(): # see http://faq.pygtk.org/index.py?req=index for more hints (3.7) while gtk.events_pending(): # see http://faq.pygtk.org/index.py?req=index for more hints (3.7)
gtk.main_iteration(False) gtk.main_iteration(False)
sleep(0.5) sleep(0.5)
print " ... writers finished" print _(" ... writers finished")
# Tidying up after import # Tidying up after import
if self.settings['dropIndexes'] == 'drop': if self.settings['dropIndexes'] == 'drop':
self.database.afterBulkImport() self.database.afterBulkImport()
else: else:
print "No need to rebuild indexes." print _("No need to rebuild indexes.")
if 'dropHudCache' in self.settings and self.settings['dropHudCache'] == 'drop': if 'dropHudCache' in self.settings and self.settings['dropHudCache'] == 'drop':
self.database.rebuild_hudcache() self.database.rebuild_hudcache()
else: else:
print "No need to rebuild hudcache." print _("No need to rebuild hudcache.")
self.database.analyzeDB() self.database.analyzeDB()
endtime = time() endtime = time()
return (totstored, totdups, totpartial, toterrors, endtime-starttime) return (totstored, totdups, totpartial, toterrors, endtime-starttime)
@ -288,7 +299,7 @@ class Importer:
toterrors += errors toterrors += errors
for i in xrange( self.settings['threads'] ): for i in xrange( self.settings['threads'] ):
print "sending finish msg qlen =", q.qsize() print _("sending finish msg qlen ="), q.qsize()
db.send_finish_msg(q) db.send_finish_msg(q)
return (totstored, totdups, totpartial, toterrors) return (totstored, totdups, totpartial, toterrors)
@ -414,9 +425,9 @@ class Importer:
# Load filter, process file, pass returned filename to import_fpdb_file # Load filter, process file, pass returned filename to import_fpdb_file
if self.settings['threads'] > 0 and self.writeq is not None: if self.settings['threads'] > 0 and self.writeq is not None:
log.info("Converting " + file + " (" + str(q.qsize()) + ")") log.info(_("Converting ") + file + " (" + str(q.qsize()) + ")")
else: else:
log.info("Converting " + file) log.info(_("Converting ") + file)
hhbase = self.config.get_import_parameters().get("hhArchiveBase") hhbase = self.config.get_import_parameters().get("hhArchiveBase")
hhbase = os.path.expanduser(hhbase) hhbase = os.path.expanduser(hhbase)
hhdir = os.path.join(hhbase,site) hhdir = os.path.join(hhbase,site)
@ -452,7 +463,7 @@ class Importer:
if self.callHud and hand.dbid_hands != 0: if self.callHud and hand.dbid_hands != 0:
to_hud.append(hand.dbid_hands) to_hud.append(hand.dbid_hands)
else: # TODO: Treat empty as an error, or just ignore? else: # TODO: Treat empty as an error, or just ignore?
log.error("Hand processed but empty") log.error(_("Hand processed but empty"))
# Call hudcache update if not in bulk import mode # Call hudcache update if not in bulk import mode
# FIXME: Need to test for bulk import that isn't rebuilding the cache # FIXME: Need to test for bulk import that isn't rebuilding the cache
@ -465,10 +476,10 @@ class Importer:
#pipe the Hands.id out to the HUD #pipe the Hands.id out to the HUD
for hid in to_hud: for hid in to_hud:
try: try:
print "fpdb_import: sending hand to hud", hand.dbid_hands, "pipe =", self.caller.pipe_to_hud print _("fpdb_import: sending hand to hud"), hand.dbid_hands, "pipe =", self.caller.pipe_to_hud
self.caller.pipe_to_hud.stdin.write("%s" % (hid) + os.linesep) self.caller.pipe_to_hud.stdin.write("%s" % (hid) + os.linesep)
except IOError, e: except IOError, e:
log.error("Failed to send hand to HUD: %s" % e) log.error(_("Failed to send hand to HUD: %s") % e)
errors = getattr(hhc, 'numErrors') errors = getattr(hhc, 'numErrors')
stored = getattr(hhc, 'numHands') stored = getattr(hhc, 'numHands')
@ -479,7 +490,7 @@ class Importer:
# TODO: appropriate response? # TODO: appropriate response?
return (0, 0, 0, 1, time() - ttime) return (0, 0, 0, 1, time() - ttime)
else: else:
log.warning("Unknown filter filter_name:'%s' in filter:'%s'" %(filter_name, filter)) log.warning(_("Unknown filter filter_name:'%s' in filter:'%s'") %(filter_name, filter))
return (0, 0, 0, 1, time() - ttime) return (0, 0, 0, 1, time() - ttime)
ttime = time() - ttime ttime = time() - ttime
@ -490,11 +501,11 @@ class Importer:
def printEmailErrorMessage(self, errors, filename, line): def printEmailErrorMessage(self, errors, filename, line):
traceback.print_exc(file=sys.stderr) traceback.print_exc(file=sys.stderr)
print "Error No.",errors,", please send the hand causing this to fpdb-main@lists.sourceforge.net so we can fix the problem." print (_("Error No.%s please send the hand causing this to fpdb-main@lists.sourceforge.net so we can fix the problem.") % errors)
print "Filename:", filename print _("Filename:"), filename
print "Here is the first line of the hand so you can identify it. Please mention that the error was a ValueError:" print _("Here is the first line of the hand so you can identify it. Please mention that the error was a ValueError:")
print self.hand[0] print self.hand[0]
print "Hand logged to hand-errors.txt" print _("Hand logged to hand-errors.txt")
logfile = open('hand-errors.txt', 'a') logfile = open('hand-errors.txt', 'a')
for s in self.hand: for s in self.hand:
logfile.write(str(s) + "\n") logfile.write(str(s) + "\n")
@ -502,4 +513,4 @@ class Importer:
logfile.close() logfile.close()
if __name__ == "__main__": if __name__ == "__main__":
print "CLI for fpdb_import is now available as CliFpdb.py" print _("CLI for fpdb_import is now available as CliFpdb.py")