Merge branch 'master' of git://git.assembla.com/free_poker_tools

This commit is contained in:
Worros 2009-06-17 10:18:31 +08:00
commit d247b32b1b
7 changed files with 80 additions and 38 deletions

View File

@ -250,6 +250,7 @@ class Config:
self.default_config_path = self.get_default_config_path() self.default_config_path = self.get_default_config_path()
if file != None: # configuration file path has been passed if file != None: # configuration file path has been passed
file = os.path.expanduser(file)
if not os.path.exists(file): if not os.path.exists(file):
print "Configuration file %s not found. Using defaults." % (file) print "Configuration file %s not found. Using defaults." % (file)
sys.stderr.write("Configuration file %s not found. Using defaults." % (file)) sys.stderr.write("Configuration file %s not found. Using defaults." % (file))

View File

@ -28,6 +28,7 @@ import time
import fpdb_import import fpdb_import
from optparse import OptionParser from optparse import OptionParser
import Configuration import Configuration
import string
class GuiAutoImport (threading.Thread): class GuiAutoImport (threading.Thread):
def __init__(self, settings, config): def __init__(self, settings, config):
@ -157,21 +158,15 @@ class GuiAutoImport (threading.Thread):
widget.set_label(u' _Stop Autoimport ') widget.set_label(u' _Stop Autoimport ')
if self.pipe_to_hud is None: if self.pipe_to_hud is None:
if os.name == 'nt': if os.name == 'nt':
command = "python HUD_main.py" + " %s" % (self.database) command = "python HUD_main.py" + " " + self.settings['cl_options']
bs = 0 # windows is not happy with line buffing here bs = 0 # windows is not happy with line buffing here
self.pipe_to_hud = subprocess.Popen(command, bufsize = bs, stdin = subprocess.PIPE, self.pipe_to_hud = subprocess.Popen(command, bufsize = bs, stdin = subprocess.PIPE,
universal_newlines=True) universal_newlines=True)
else: else:
command = os.path.join(sys.path[0], 'HUD_main.py') command = os.path.join(sys.path[0], 'HUD_main.py')
#command = self.config.execution_path('HUD_main.py') # Hi Ray. Sorry about this, kludging. cl = [command, ] + string.split(self.settings['cl_options'])
bs = 1 self.pipe_to_hud = subprocess.Popen(cl, bufsize = 1, stdin = subprocess.PIPE,
self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE,
universal_newlines=True) universal_newlines=True)
# self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE,
# universal_newlines=True)
# command = command + " %s" % (self.database)
# print "command = ", command
# self.pipe_to_hud = os.popen(command, 'w')
# Add directories to importer object. # Add directories to importer object.
for site in self.input_settings: for site in self.input_settings:

View File

@ -29,12 +29,20 @@ Main for FreePokerTools HUD.
# Standard Library modules # Standard Library modules
import sys import sys
# redirect the stderr
errorfile = open('HUD-error.txt', 'w', 0)
sys.stderr = errorfile
import os import os
import Options
(options, sys.argv) = Options.fpdb_options()
print "HUD: dbname =", options.dbname
print "HUD: config =", options.config
print "HUD: logging =", options.errorsToConsole
if not options.errorsToConsole:
print "Note: error output is being diverted to fpdb-error-log.txt and HUD-error.txt. Any major error will be reported there _only_."
errorFile = open('fpdb-error-log.txt', 'w', 0)
sys.stderr = errorFile
import thread import thread
import time import time
import string import string
@ -59,7 +67,7 @@ class HUD_main(object):
def __init__(self, db_name = 'fpdb'): def __init__(self, db_name = 'fpdb'):
self.db_name = db_name self.db_name = db_name
self.config = Configuration.Config() self.config = Configuration.Config(file=options.config, dbname=options.dbname)
self.hud_dict = {} self.hud_dict = {}
# a thread to read stdin # a thread to read stdin
@ -198,17 +206,12 @@ class HUD_main(object):
self.db_connection.connection.rollback() self.db_connection.connection.rollback()
if __name__== "__main__": if __name__== "__main__":
sys.stderr.write("HUD_main starting\n")
# database name can be passed on command line sys.stderr.write("HUD_main starting\n")
try: sys.stderr.write("Using db name = %s\n" % (options.dbname))
db_name = sys.argv[1]
except:
db_name = 'fpdb'
sys.stderr.write("Using db name = %s\n" % (db_name))
# start the HUD_main object # start the HUD_main object
hm = HUD_main(db_name = db_name) hm = HUD_main(db_name = options.dbname)
# start the event loop # start the event loop
gtk.main() gtk.main()

View File

@ -43,7 +43,7 @@ import Configuration
import Stats import Stats
import Mucked import Mucked
import Database import Database
import HUD_main #import HUD_main
def importName(module_name, name): def importName(module_name, name):
"""Import a named object 'name' from module 'module_name'.""" """Import a named object 'name' from module 'module_name'."""

45
pyfpdb/Options.py Normal file
View File

@ -0,0 +1,45 @@
#!/usr/bin/python
#Copyright 2008 Ray E. Barker
#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
from optparse import OptionParser
def fpdb_options():
"""Process command line options for fpdb and HUD_main."""
parser = OptionParser()
parser.add_option("-x", "--errorsToConsole",
action="store_true",
help="If passed error output will go to the console rather than .")
parser.add_option("-d", "--databaseName",
dest="dbname", default="fpdb",
help="Overrides the default database name")
parser.add_option("-c", "--configFile",
dest="config", default=None,
help="Specifies a configuration file.")
(options, sys.argv) = parser.parse_args()
return (options, sys.argv)
if __name__== "__main__":
(options, sys.argv) = fpdb_options()
print "errorsToConsole =", options.errorsToConsole
print "database name =", options.dbname
print "config file =", options.config
print "press enter to end"
sys.stdin.readline()

View File

@ -17,15 +17,11 @@
import os import os
import sys import sys
from optparse import OptionParser import Options
import string
cl_options = string.join(sys.argv[1:])
parser = OptionParser() (options, sys.argv) = Options.fpdb_options()
parser.add_option("-x", "--errorsToConsole", action="store_true",
help="If passed error output will go to the console rather than .")
parser.add_option("-d", "--databaseName", dest="dbname", default="fpdb",
help="Overrides the default database name")
(options, sys.argv) = parser.parse_args()
if not options.errorsToConsole: if not options.errorsToConsole:
print "Note: error output is being diverted to fpdb-error-log.txt and HUD-error.txt. Any major error will be reported there _only_." print "Note: error output is being diverted to fpdb-error-log.txt and HUD-error.txt. Any major error will be reported there _only_."
@ -356,6 +352,7 @@ class fpdb:
else: else:
self.settings['os']="windows" self.settings['os']="windows"
self.settings.update({'cl_options': cl_options})
self.settings.update(self.config.get_db_parameters()) self.settings.update(self.config.get_db_parameters())
self.settings.update(self.config.get_tv_parameters()) self.settings.update(self.config.get_tv_parameters())
self.settings.update(self.config.get_import_parameters()) self.settings.update(self.config.get_import_parameters())
@ -486,7 +483,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt")
def __init__(self): def __init__(self):
self.threads=[] self.threads=[]
self.db=None self.db=None
self.config = Configuration.Config(dbname=options.dbname) self.config = Configuration.Config(file=options.config, dbname=options.dbname)
self.load_profile() self.load_profile()
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

View File

@ -21,7 +21,8 @@ import fpdb_simple
import fpdb_save_to_db import fpdb_save_to_db
#parses a holdem hand #parses a holdem hand
def mainParser(backend, db, cursor, siteID, category, hand, config): def mainParser(settings, db, cursor, siteID, category, hand, config):
backend = settings['db-backend']
category = fpdb_simple.recogniseCategory(hand[0]) category = fpdb_simple.recogniseCategory(hand[0])
base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud" base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud"
@ -141,7 +142,7 @@ def mainParser(backend, db, cursor, siteID, category, hand, config):
if base == "hold": if base == "hold":
result = fpdb_save_to_db.tourney_holdem_omaha( result = fpdb_save_to_db.tourney_holdem_omaha(
config, backend, db, cursor, base, category, siteTourneyNo, buyin config, settings, db, cursor, base, category, siteTourneyNo, buyin
, fee, knockout, entries, prizepool, tourneyStartTime , fee, knockout, entries, prizepool, tourneyStartTime
, payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo , payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo
, gametypeID, handStartTime, names, playerIDs, startCashes , gametypeID, handStartTime, names, playerIDs, startCashes
@ -150,7 +151,7 @@ def mainParser(backend, db, cursor, siteID, category, hand, config):
, actionNos, hudImportData, maxSeats, tableName, seatNos) , actionNos, hudImportData, maxSeats, tableName, seatNos)
elif base == "stud": elif base == "stud":
result = fpdb_save_to_db.tourney_stud( result = fpdb_save_to_db.tourney_stud(
config, backend, db, cursor, base, category, siteTourneyNo config, settings, db, cursor, base, category, siteTourneyNo
, buyin, fee, knockout, entries, prizepool, tourneyStartTime , buyin, fee, knockout, entries, prizepool, tourneyStartTime
, payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo , payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo
, gametypeID, handStartTime, names, playerIDs, startCashes , gametypeID, handStartTime, names, playerIDs, startCashes
@ -162,7 +163,7 @@ def mainParser(backend, db, cursor, siteID, category, hand, config):
else: else:
if base == "hold": if base == "hold":
result = fpdb_save_to_db.ring_holdem_omaha( result = fpdb_save_to_db.ring_holdem_omaha(
config, backend, db, cursor, base, category, siteHandNo config, settings, db, cursor, base, category, siteHandNo
, gametypeID, handStartTime, names, playerIDs , gametypeID, handStartTime, names, playerIDs
, startCashes, positions, cardValues, cardSuits , startCashes, positions, cardValues, cardSuits
, boardValues, boardSuits, winnings, rakes , boardValues, boardSuits, winnings, rakes
@ -170,7 +171,7 @@ def mainParser(backend, db, cursor, siteID, category, hand, config):
, hudImportData, maxSeats, tableName, seatNos) , hudImportData, maxSeats, tableName, seatNos)
elif base == "stud": elif base == "stud":
result = fpdb_save_to_db.ring_stud( result = fpdb_save_to_db.ring_stud(
config, backend, db, cursor, base, category, siteHandNo, gametypeID config, settings, db, cursor, base, category, siteHandNo, gametypeID
, handStartTime, names, playerIDs, startCashes, antes , handStartTime, names, playerIDs, startCashes, antes
, cardValues, cardSuits, winnings, rakes, actionTypes, allIns , cardValues, cardSuits, winnings, rakes, actionTypes, allIns
, actionAmounts, actionNos, hudImportData, maxSeats, tableName , actionAmounts, actionNos, hudImportData, maxSeats, tableName