This commit is contained in:
unknown 2009-11-03 15:29:05 -05:00
parent a5de7c9b6b
commit 51da6fb687

View File

@ -182,14 +182,15 @@ class Importer:
if os.path.isdir(inputPath): if os.path.isdir(inputPath):
for subdir in os.walk(inputPath): for subdir in os.walk(inputPath):
for file in subdir[2]: for file in subdir[2]:
self.addImportFile(os.path.join(subdir[0], file), site=site, filter=filter) self.addImportFile(os.path.join(subdir[0], file), site=site,
filter=filter)
else: else:
self.addImportFile(inputPath, site=site, filter=filter) self.addImportFile(inputPath, site=site, filter=filter)
#Add a directory of files to filelist #Add a directory of files to filelist
#Only one import directory per site supported. #Only one import directory per site supported.
#dirlist is a hash of lists: #dirlist is a hash of lists:
#dirlist{ 'PokerStars' => ["/path/to/import/", "filtername"] } #dirlist{ 'PokerStars' => ["/path/to/import/", "filtername"] }
def addImportDirectory(self,dir,monitor = False, site = "default", filter = "passthrough"): def addImportDirectory(self,dir,monitor=False, site="default", filter="passthrough"):
#gets called by GuiAutoImport. #gets called by GuiAutoImport.
#This should really be using os.walk #This should really be using os.walk
#http://docs.python.org/library/os.html #http://docs.python.org/library/os.html
@ -203,7 +204,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: '" + str(dir) + "' as an import directory") 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"""
@ -250,6 +251,9 @@ class Importer:
#self.writeq.join() #self.writeq.join()
#using empty() might be more reliable: #using empty() might be more reliable:
while not self.writeq.empty() and len(threading.enumerate()) > 1: while not self.writeq.empty() and len(threading.enumerate()) > 1:
# TODO: Do we need to actually tell the progress indicator to move, or is it already moving, and we just need to process events...
while gtk.events_pending(): # see http://faq.pygtk.org/index.py?req=index for more hints (3.7)
gtk.main_iteration(False)
sleep(0.5) sleep(0.5)
print " ... writers finished" print " ... writers finished"
@ -418,9 +422,9 @@ class Importer:
obj = getattr(mod, filter_name, None) obj = getattr(mod, filter_name, None)
if callable(obj): if callable(obj):
hhc = obj(in_path = file, out_path = out_path, index = 0) # Index into file 0 until changeover hhc = obj(in_path = file, out_path = out_path, index = 0) # Index into file 0 until changeover
if(hhc.getStatus() and self.NEWIMPORT == False): if hhc.getStatus() and self.NEWIMPORT == False:
(stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(db, out_path, site, q) (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(db, out_path, site, q)
elif (hhc.getStatus() and self.NEWIMPORT == True): elif hhc.getStatus() and self.NEWIMPORT == True:
#This code doesn't do anything yet #This code doesn't do anything yet
handlist = hhc.getProcessedHands() handlist = hhc.getProcessedHands()
self.pos_in_file[file] = hhc.getLastCharacterRead() self.pos_in_file[file] = hhc.getLastCharacterRead()
@ -458,7 +462,7 @@ class Importer:
loc = self.pos_in_file[file] loc = self.pos_in_file[file]
#size = os.path.getsize(file) #size = os.path.getsize(file)
#print "loc =", loc, 'size =', size #print "loc =", loc, 'size =', size
except: except IndexError:
pass pass
# Read input file into class and close file # Read input file into class and close file
inputFile.seek(loc) inputFile.seek(loc)
@ -481,14 +485,14 @@ class Importer:
if not stored: if not stored:
if duplicates: if duplicates:
for line_no in xrange(len(self.lines)): for line_no in xrange(len(self.lines)):
if self.lines[line_no].find("Game #")!=-1: if self.lines[line_no].find("Game #") != -1:
final_game_line=self.lines[line_no] final_game_line = self.lines[line_no]
handsId=fpdb_simple.parseSiteHandNo(final_game_line) handsId=fpdb_simple.parseSiteHandNo(final_game_line)
else: else:
print "failed to read a single hand from file:", inputFile print "failed to read a single hand from file:", inputFile
handsId=0 handsId = 0
#todo: this will cause return of an unstored hand number if the last hand was error #todo: this will cause return of an unstored hand number if the last hand was error
self.handsId=handsId self.handsId = handsId
return (stored, duplicates, partial, errors, ttime) return (stored, duplicates, partial, errors, ttime)
# end def import_fpdb_file # end def import_fpdb_file
@ -508,13 +512,13 @@ class Importer:
#print "DEBUG: import_fpdb_file: failed on lines[0]: '%s' '%s' '%s' '%s' " %( file, site, lines, loc) #print "DEBUG: import_fpdb_file: failed on lines[0]: '%s' '%s' '%s' '%s' " %( file, site, lines, loc)
return (0,0,0,1,0,0) return (0,0,0,1,0,0)
if firstline.find("Tournament Summary")!=-1: if "Tournament Summary" in firstline:
print "TODO: implement importing tournament summaries" print "TODO: implement importing tournament summaries"
#self.faobs = readfile(inputFile) #self.faobs = readfile(inputFile)
#self.parseTourneyHistory() #self.parseTourneyHistory()
return (0,0,0,1,0,0) return (0,0,0,1,0,0)
category=fpdb_simple.recogniseCategory(firstline) category = fpdb_simple.recogniseCategory(firstline)
startpos = 0 startpos = 0
stored = 0 #counter stored = 0 #counter
@ -524,24 +528,23 @@ class Importer:
ttime = 0 ttime = 0
handsId = 0 handsId = 0
for i in xrange (len(lines)): for i in xrange(len(lines)):
if (len(lines[i])<2): #Wierd way to detect for '\r\n' or '\n' if len(lines[i]) < 2: #Wierd way to detect for '\r\n' or '\n'
endpos=i endpos = i
hand=lines[startpos:endpos] hand = lines[startpos:endpos]
if (len(hand[0])<2): if len(hand[0]) < 2:
hand=hand[1:] hand=hand[1:]
if len(hand) < 3:
if (len(hand)<3):
pass pass
#TODO: This is ugly - we didn't actually find the start of the #TODO: This is ugly - we didn't actually find the start of the
# hand with the outer loop so we test again... # hand with the outer loop so we test again...
else: else:
isTourney=fpdb_simple.isTourney(hand[0]) isTourney = fpdb_simple.isTourney(hand[0])
if not isTourney: if not isTourney:
hand = fpdb_simple.filterAnteBlindFold(hand) hand = fpdb_simple.filterAnteBlindFold(hand)
self.hand=hand self.hand = hand
try: try:
handsId = fpdb_parse_logic.mainParser( self.settings, self.siteIds[site] handsId = fpdb_parse_logic.mainParser( self.settings, self.siteIds[site]
@ -553,7 +556,7 @@ class Importer:
if self.callHud: if self.callHud:
#print "call to HUD here. handsId:",handsId #print "call to HUD here. handsId:",handsId
#pipe the Hands.id out to the HUD #pipe the Hands.id out to the HUD
print "sending hand to hud", handsId, "pipe =", self.caller.pipe_to_hud print "fpdb_import: sending hand to hud", handsId, "pipe =", self.caller.pipe_to_hud
self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep) self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep)
except Exceptions.DuplicateError: except Exceptions.DuplicateError:
duplicates += 1 duplicates += 1