add warning_box func to fpdb, add validate_config func, checks existence of hhArchiveBase, pops up warnings if not present

hhc traps errors creating folders, need to learn how to make it fail properly afterwards.
This commit is contained in:
Eric Blade 2009-09-09 18:20:50 -05:00
parent 6238e2f896
commit 2397a59483
2 changed files with 43 additions and 3 deletions

View File

@ -82,13 +82,21 @@ follow : whether to tail -f the input"""
# 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 != '':
log.info("Creating directory '%s'" % 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', 'cp1252')
log.debug("out_path %s opened as %s" % (self.out_path, self.out_fh))
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()

View File

@ -425,6 +425,8 @@ class fpdb:
# Database connected to successfully, load queries to pass on to other classes
self.db.connection.rollback()
self.validate_config()
def not_implemented(self, widget, data=None):
print "todo: called unimplemented menu entry (users: pls ignore this)"#remove this once more entries are implemented
@ -544,6 +546,36 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt")
self.load_profile()
sys.stderr.write("fpdb starting ...")
def warning_box(self, str, diatitle="FPDB WARNING"):
diaWarning = gtk.Dialog(title=diatitle, parent=None, flags=0, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK))
label = gtk.Label(str)
diaWarning.vbox.add(label)
label.show()
response = diaWarning.run()
diaWarning.destroy()
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. 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.warning_box("UNIMPLEMENTED: selection of HH directory not yet implemented, please edit your HUD_config.xml file and set hhArchiveBase to a valid directory")
def main(self):
gtk.main()
return 0