Add sanity check function, creates ~/.fpdb/HandHistories/<sitename> if it doens't exist.

Fixes hhbase and hhdir interpretation.
This commit is contained in:
Worros 2008-11-09 12:58:46 +10:00
parent 328bba2d23
commit f3224f87cc

View File

@ -18,6 +18,8 @@
import Configuration import Configuration
import sys import sys
import traceback import traceback
import os
import os.path
import xml.dom.minidom import xml.dom.minidom
from xml.dom.minidom import Node from xml.dom.minidom import Node
@ -31,7 +33,8 @@ class HandHistoryConverter:
self.doc = None # For XML based HH files self.doc = None # For XML based HH files
self.file = file self.file = file
self.hhbase = self.c.get_import_parameters().get("hhArchiveBase") self.hhbase = self.c.get_import_parameters().get("hhArchiveBase")
self.hhdir = self.hhbase + sitename self.hhbase = os.path.expanduser(self.hhbase)
self.hhdir = os.path.join(self.hhbase,sitename)
def __str__(self): def __str__(self):
tmp = "HandHistoryConverter: '%s'\n" % (self.sitename) tmp = "HandHistoryConverter: '%s'\n" % (self.sitename)
@ -48,12 +51,35 @@ class HandHistoryConverter:
def readBlinds(self): abstract def readBlinds(self): abstract
def readAction(self): abstract def readAction(self): abstract
def sanityCheck(self):
sane = False
base_w = False
#Check if hhbase exists and is writable
#Note: Will not try to create the base HH directory
if not (os.access(self.hhbase, os.W_OK) and os.path.isdir(self.hhbase)):
print "HH Sanity Check: Directory hhbase '" + self.hhbase + "' doesn't exist or is not writable"
else:
#Check if hhdir exists and is writable
if not os.path.isdir(self.hhdir):
# In first pass, dir may not exist. Attempt to create dir
print "Creating directory: '%s'" % (self.hhdir)
os.mkdir(self.hhdir)
sane = True
elif os.access(self.hhdir, os.W_OK):
sane = True
else:
print "HH Sanity Check: Directory hhdir '" + self.hhdir + "' or its parent directory are not writable"
return sane
# Functions not necessary to implement in sub class # Functions not necessary to implement in sub class
def setFileType(self, filetype = "text"): def setFileType(self, filetype = "text"):
self.filetype = filetype self.filetype = filetype
def processFile(self): def processFile(self):
if not self.sanityCheck():
print "Cowardly refusing to continue after failed sanity check"
return
self.readFile(self.file) self.readFile(self.file)
def readFile(self, filename): def readFile(self, filename):