Don't make folders or files for Stars format HHs.
This commit is contained in:
parent
97ec91c165
commit
c33575911d
|
@ -69,6 +69,7 @@ out_path (default '-' = sys.stdout)
|
|||
follow : whether to tail -f the input"""
|
||||
|
||||
self.config = config
|
||||
self.import_parameters = self.config.get_import_parameters()
|
||||
#log = Configuration.get_logger("logging.conf", "parser", log_dir=self.config.dir_log)
|
||||
log.info("HandHistory init - %s subclass, in_path '%s'; out_path '%s'" % (self.sitename, in_path, out_path) )
|
||||
|
||||
|
@ -87,28 +88,8 @@ follow : whether to tail -f the input"""
|
|||
|
||||
if in_path == '-':
|
||||
self.in_fh = sys.stdin
|
||||
self.out_fh = get_out_fh(out_path, self.import_parameters)
|
||||
|
||||
if out_path == '-':
|
||||
self.out_fh = sys.stdout
|
||||
else:
|
||||
# TODO: out_path should be sanity checked.
|
||||
out_dir = os.path.dirname(self.out_path)
|
||||
if not os.path.isdir(out_dir) and out_dir != '':
|
||||
try:
|
||||
os.makedirs(out_dir)
|
||||
except: # we get a WindowsError here in Windows.. pretty sure something else for Linux :D
|
||||
log.error("Unable to create output directory %s for HHC!" % out_dir)
|
||||
print "*** ERROR: UNABLE TO CREATE OUTPUT DIRECTORY", out_dir
|
||||
# TODO: pop up a box to allow person to choose output directory?
|
||||
# TODO: shouldn't that be done when we startup, actually?
|
||||
else:
|
||||
log.info("Created directory '%s'" % out_dir)
|
||||
try:
|
||||
self.out_fh = codecs.open(self.out_path, 'w', 'utf8')
|
||||
except:
|
||||
log.error("out_path %s couldn't be opened" % (self.out_path))
|
||||
else:
|
||||
log.debug("out_path %s opened as %s" % (self.out_path, self.out_fh))
|
||||
self.follow = follow
|
||||
self.compiledPlayers = set()
|
||||
self.maxseats = 10
|
||||
|
@ -531,3 +512,28 @@ def getSiteHhc(config, sitename):
|
|||
hhcName = config.supported_sites[sitename].converter
|
||||
hhcModule = __import__(hhcName)
|
||||
return getattr(hhcModule, hhcName[:-6])
|
||||
|
||||
def get_out_fh(out_path, parameters):
|
||||
if out_path == '-':
|
||||
return(sys.stdout)
|
||||
elif parameters['saveStarsHH']:
|
||||
# TODO: out_path should be sanity checked.
|
||||
out_dir = os.path.dirname(self.out_path)
|
||||
if not os.path.isdir(out_dir) and out_dir != '':
|
||||
try:
|
||||
os.makedirs(out_dir)
|
||||
except: # we get a WindowsError here in Windows.. pretty sure something else for Linux :D
|
||||
log.error("Unable to create output directory %s for HHC!" % out_dir)
|
||||
print "*** ERROR: UNABLE TO CREATE OUTPUT DIRECTORY", out_dir
|
||||
# TODO: pop up a box to allow person to choose output directory?
|
||||
# TODO: shouldn't that be done when we startup, actually?
|
||||
else:
|
||||
log.info("Created directory '%s'" % out_dir)
|
||||
try:
|
||||
return(codecs.open(self.out_path, 'w', 'utf8'))
|
||||
except:
|
||||
log.error("out_path %s couldn't be opened" % (self.out_path))
|
||||
else:
|
||||
log.debug("out_path %s opened as %s" % (self.out_path, self.out_fh))
|
||||
else:
|
||||
return(sys.stdout)
|
|
@ -997,23 +997,24 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt")
|
|||
return response
|
||||
|
||||
def validate_config(self):
|
||||
hhbase = self.config.get_import_parameters().get("hhArchiveBase")
|
||||
hhbase = os.path.expanduser(hhbase)
|
||||
#hhdir = os.path.join(hhbase,site)
|
||||
hhdir = hhbase
|
||||
if not os.path.isdir(hhdir):
|
||||
diapath = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Setup hh dir")
|
||||
diastring = "WARNING: Unable to find output hh directory %s\n\n Press YES to create this directory, or NO to select a new one." % hhdir
|
||||
diapath.format_secondary_text(diastring)
|
||||
response = diapath.run()
|
||||
diapath.destroy()
|
||||
if response == gtk.RESPONSE_YES:
|
||||
try:
|
||||
os.makedirs(hhdir)
|
||||
except:
|
||||
self.warning_box("WARNING: Unable to create hand output directory. Importing is not likely to work until this is fixed.")
|
||||
elif response == gtk.RESPONSE_NO:
|
||||
self.select_hhArchiveBase()
|
||||
if self.config.get_import_parameters().get('saveStarsHH'):
|
||||
hhbase = self.config.get_import_parameters().get("hhArchiveBase")
|
||||
hhbase = os.path.expanduser(hhbase)
|
||||
#hhdir = os.path.join(hhbase,site)
|
||||
hhdir = hhbase
|
||||
if not os.path.isdir(hhdir):
|
||||
diapath = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Setup hh dir")
|
||||
diastring = "WARNING: Unable to find output hh directory %s\n\n Press YES to create this directory, or NO to select a new one." % hhdir
|
||||
diapath.format_secondary_text(diastring)
|
||||
response = diapath.run()
|
||||
diapath.destroy()
|
||||
if response == gtk.RESPONSE_YES:
|
||||
try:
|
||||
os.makedirs(hhdir)
|
||||
except:
|
||||
self.warning_box("WARNING: Unable to create hand output directory. Importing is not likely to work until this is fixed.")
|
||||
elif response == gtk.RESPONSE_NO:
|
||||
self.select_hhArchiveBase()
|
||||
|
||||
def select_hhArchiveBase(self, widget=None):
|
||||
fc = gtk.FileChooserDialog(title="Select HH Output Directory", parent=None, action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=(gtk.STOCK_OPEN,gtk.RESPONSE_OK), backend=None)
|
||||
|
|
Loading…
Reference in New Issue
Block a user