Configuration: _getframe(0) so that GuiAutoImport can run standalone

(stack not deep enough to go one deeper)
fpdb_import: Everleaf plumbing back in place.
GuiAutoImport.py: run standalone.
This commit is contained in:
Matt Turnbull 2009-03-05 01:12:15 +00:00
parent 7049a959ec
commit 75dcf002f9
4 changed files with 54 additions and 25 deletions

View File

@ -609,7 +609,7 @@ class Config:
def execution_path(self, filename):
"""Join the fpdb path to filename."""
return os.path.join(os.path.dirname(inspect.getfile(sys._getframe(1))), filename)
return os.path.join(os.path.dirname(inspect.getfile(sys._getframe(0))), filename)
if __name__== "__main__":
c = Config()

View File

@ -26,7 +26,8 @@ import os
import sys
import time
import fpdb_import
from optparse import OptionParser
import Configuration
class GuiAutoImport (threading.Thread):
def __init__(self, settings, config):
@ -134,7 +135,8 @@ class GuiAutoImport (threading.Thread):
self.pipe_to_hud = subprocess.Popen(command, bufsize = bs, stdin = subprocess.PIPE,
universal_newlines=True)
else:
command = self.config.execution_path('HUD_main.py')
# command = os.path.join(os.getcwd(), 'HUD_main.py') # clearly doesn't work if you run from somewhere else.
command = self.config.execution_path('HUD_main.py') # Hi Ray. Sorry about this, kludging.
bs = 1
self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE,
universal_newlines=True)
@ -214,18 +216,39 @@ if __name__== "__main__":
def destroy(*args): # call back for terminating the main eventloop
gtk.main_quit()
settings = {}
settings['db-host'] = "192.168.1.100"
settings['db-user'] = "mythtv"
settings['db-password'] = "mythtv"
settings['db-databaseName'] = "fpdb"
settings['hud-defaultInterval'] = 10
settings['hud-defaultPath'] = 'C:/Program Files/PokerStars/HandHistory/nutOmatic'
settings['callFpdbHud'] = True
# settings = {}
# settings['db-host'] = "192.168.1.100"
# settings['db-user'] = "mythtv"
# settings['db-password'] = "mythtv"
# settings['db-databaseName'] = "fpdb"
# settings['hud-defaultInterval'] = 10
# settings['hud-defaultPath'] = 'C:/Program Files/PokerStars/HandHistory/nutOmatic'
# settings['callFpdbHud'] = True
i = GuiAutoImport(settings)
main_window = gtk.Window()
main_window.connect("destroy", destroy)
main_window.add(i.mainVBox)
main_window.show()
gtk.main()
parser = OptionParser()
parser.add_option("-q", "--quiet", action="store_false", dest="gui", default=True, help="don't start gui")
(options, sys.argv) = parser.parse_args()
config = Configuration.Config()
# db = fpdb_db.fpdb_db()
settings = {}
if os.name == 'nt': settings['os'] = 'windows'
else: settings['os'] = 'linuxmac'
settings.update(config.get_db_parameters('fpdb'))
settings.update(config.get_tv_parameters())
settings.update(config.get_import_parameters())
settings.update(config.get_default_paths())
if(options.gui == True):
i = GuiAutoImport(settings, config)
main_window = gtk.Window()
main_window.connect('destroy', destroy)
main_window.add(i.mainVBox)
main_window.show()
gtk.main()
else:
pass

View File

@ -95,6 +95,7 @@ class HandHistoryConverter(threading.Thread):
self.maxseats = 10
def __str__(self):
#TODO : I got rid of most of the hhdir stuff.
tmp = "HandHistoryConverter: '%s'\n" % (self.sitename)
tmp = tmp + "\thhbase: '%s'\n" % (self.hhbase)
tmp = tmp + "\thhdir: '%s'\n" % (self.hhdir)
@ -143,13 +144,18 @@ class HandHistoryConverter(threading.Thread):
if gametype is None:
return
hand = None
if gametype[1] in ("hold", "omaha"):
hand = Hand.HoldemOmahaHand(self, self.sitename, gametype, handtext)
elif gametype[1] in ("razz","stud","stud8"):
hand = Hand.StudHand(self, self.sitename, gametype, handtext)
hand.writeHand(self.out_fh)
if hand:
hand.writeHand(self.out_fh)
else:
logging.info("Unrecognised game type: %s" % gametype[1])
# 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 :)
def processFile(self):

View File

@ -118,7 +118,6 @@ class Importer:
def addBulkImportImportFileOrDir(self, inputPath,filter = "passthrough"):
"""Add a file or directory for bulk import"""
# Bulk import never monitors
# if directory, add all files in it. Otherwise add single file.
# TODO: only add sane files?
if os.path.isdir(inputPath):
@ -133,6 +132,7 @@ class Importer:
#dirlist is a hash of lists:
#dirlist{ 'PokerStars' => ["/path/to/import/", "filtername"] }
def addImportDirectory(self,dir,monitor = False, site = "default", filter = "passthrough"):
#gets called by GuiAutoImport.
#This should really be using os.walk
#http://docs.python.org/library/os.html
if os.path.isdir(dir):
@ -237,12 +237,12 @@ class Importer:
hhbase = os.path.expanduser(hhbase)
hhdir = os.path.join(hhbase,site)
try:
ofile = os.path.join(hhdir, file.split(os.path.sep)[-2]+"-"+os.path.basename(file))
out_path = os.path.join(hhdir, file.split(os.path.sep)[-2]+"-"+os.path.basename(file))
except:
ofile = os.path.join(hhdir, "x"+strftime("%d-%m-%y")+os.path.basename(file))
out_fh = open(ofile, 'w') # TODO: seek to previous place in input and append output
in_fh =
conv = EverleafToFpdb.Everleaf(in_fh = file, out_fh = out_fh)
out_path = os.path.join(hhdir, "x"+strftime("%d-%m-%y")+os.path.basename(file))
#out_fh = open(ofile, 'w') # TODO: seek to previous place in input and append output
conv = EverleafToFpdb.Everleaf(in_path = file, out_path = out_path)
conv.join()
elif filter == "FulltiltToFpdb":
print "converting ", file
conv = FulltiltToFpdb.FullTilt(in_fh = file, out_fh = out_fh)