p132 - fixed tv to new importer. added CliFpdb as initial CLI importer interface. fixed fpdb.printEmailError

This commit is contained in:
steffen123
2008-10-10 04:14:26 +01:00
parent acb4160969
commit 4cc0eb539e
5 changed files with 156 additions and 9 deletions
+83
View File
@@ -0,0 +1,83 @@
#!/usr/bin/python
#Copyright 2008 Steffen Jobbagy-Felso
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, version 3 of the License.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU Affero General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#In the "official" distribution you can find the license in
#agpl-3.0.txt in the docs folder of the package.
import os
import sys
import fpdb_simple
from optparse import OptionParser
try:
import MySQLdb
except:
diaSQLLibMissing = gtk.Dialog(title="Fatal Error - SQL interface library missing", parent=None, flags=0, buttons=(gtk.STOCK_QUIT,gtk.RESPONSE_OK))
print "Please note that the CLI importer only works with MySQL, if you use PostgreSQL this error is expected."
import fpdb_import
import fpdb_db
# def __init__(self, db, settings, debug=True):
# """Constructor for table_viewer"""
# self.debug=debug
# #print "start of table_viewer constructor"
# self.db=db
# self.cursor=db.cursor
# self.settings=settings
if __name__ == "__main__":
failOnError=False
quiet=False
#process CLI parameters
parser = OptionParser()
parser.add_option("-c", "--handCount", default="0", type="int",
help="Number of hands to import (default 0 means unlimited)")
parser.add_option("-d", "--database", default="fpdb", help="The MySQL database to use (default fpdb)")
parser.add_option("-e", "--errorFile", default="failed.txt",
help="File to store failed hands into. (default: failed.txt) Not implemented.")
parser.add_option("-f", "--inputFile", "--file", "--inputfile", default="stdin",
help="The file you want to import (remember to use quotes if necessary)")
parser.add_option("-m", "--minPrint", "--status", default="50", type="int",
help="How often to print a one-line status report (0 means never, default is 50)")
parser.add_option("-p", "--password", help="The password for the MySQL user")
parser.add_option("-q", "--quiet", action="store_true",
help="If this is passed it doesn't print a total at the end nor the opening line. Note that this purposely does NOT change --minPrint")
parser.add_option("-s", "--server", default="localhost",
help="Hostname/IP of the MySQL server (default localhost)")
parser.add_option("-u", "--user", default="fpdb", help="The MySQL username (default fpdb)")
parser.add_option("-x", "--failOnError", action="store_true",
help="If this option is passed it quits when it encounters any error")
(options, sys.argv) = parser.parse_args()
settings={'imp-callFpdbHud':False, 'db-backend':2}
#self.inputFile=options.inputFile
#self.server=options.server
#self.database=options.database
#self.user=options.user
#self.password=options.password
#self.quiet=False
#self.failOnError=False
#self.minPrint=0
#self.handCount=0
importer = fpdb_import.Importer()
importer.import_file_dict(options, settings)
+1 -1
View File
@@ -257,7 +257,7 @@ class GuiTableViewer (threading.Thread):
self.handCount=0
self.importer = fpdb_import.Importer()
self.last_read_hand_id=importer.import_file_dict(self, self.settings)
self.last_read_hand_id=self.importer.import_file_dict(self, self.settings)
#end def table_viewer.import_clicked
def all_clicked(self, widget, data):
+5 -4
View File
@@ -36,7 +36,6 @@ import os
import datetime
import fpdb_simple
import fpdb_parse_logic
from optparse import OptionParser
from time import time
class Importer:
@@ -72,6 +71,7 @@ class Importer:
self.callHud = value
def import_file_dict(self, options, settings):
self.options=options
starttime = time()
last_read_hand=0
if (options.inputFile=="stdin"):
@@ -136,7 +136,8 @@ class Importer:
if not isTourney:
fpdb_simple.filterAnteBlindFold(site,hand)
hand=fpdb_simple.filterCrap(site, hand, isTourney)
self.hand=hand
try:
handsId=fpdb_parse_logic.mainParser(self.db, self.cursor, site, category, hand)
self.db.commit()
@@ -203,9 +204,9 @@ class Importer:
def printEmailErrorMessage(self, errors, filename, line):
print "Error No.",errors,", please send the hand causing this to steffen@sycamoretest.info so I can fix it."
print "Filename:",options.inputFile
print "Filename:", self.options.inputFile
print "Here is the first line so you can identify it. Please mention that the error was a ValueError:"
print hand[0]
print self.hand[0]
if __name__ == "__main__":