本文整理汇总了Python中WMCore.WMInit.WMInit.checkDatabaseContents方法的典型用法代码示例。如果您正苦于以下问题:Python WMInit.checkDatabaseContents方法的具体用法?Python WMInit.checkDatabaseContents怎么用?Python WMInit.checkDatabaseContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WMCore.WMInit.WMInit
的用法示例。
在下文中一共展示了WMInit.checkDatabaseContents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestInit
# 需要导入模块: from WMCore.WMInit import WMInit [as 别名]
# 或者: from WMCore.WMInit.WMInit import checkDatabaseContents [as 别名]
class TestInit(object):
"""
A set of initialization steps used in many tests.
Test can call the methods from this class to
initialize their default environment so to
minimize code duplication.
"""
def __init__(self, testClassName = "Unknown Class"):
self.testClassName = testClassName
self.testDir = None
self.currModules = []
global hasDatabase
self.hasDatabase = hasDatabase
if self.hasDatabase:
self.init = WMInit()
self.deleteTmp = True
def __del__(self):
if self.deleteTmp:
self.delWorkDir()
self.attemptToCloseDBConnections()
def delWorkDir(self):
if self.testDir != None:
try:
shutil.rmtree( self.testDir )
except:
# meh, if it fails, I guess something weird happened
pass
def setLogging(self, logLevel = logging.INFO):
"""
Sets logging parameters
"""
# remove old logging instances.
return
logger1 = logging.getLogger()
logger2 = logging.getLogger(self.testClassName)
for logger in [logger1, logger2]:
for handler in logger.handlers:
handler.close()
logger.removeHandler(handler)
self.init.setLogging(self.testClassName, self.testClassName,
logExists = False, logLevel = logLevel)
def generateWorkDir(self, config = None, deleteOnDestruction = True, setTmpDir = False):
self.testDir = tempfile.mkdtemp()
if config:
config.section_("General")
config.General.workDir = self.testDir
os.environ['TESTDIR'] = self.testDir
if os.getenv('WMCORE_KEEP_DIRECTORIES', False):
deleteOnDestruction = True
logging.info("Generated testDir - %s" % self.testDir)
if setTmpDir:
os.environ['TMPDIR'] = self.testDir
self.deleteTmp = deleteOnDestruction
return self.testDir
def getBackendFromDbURL(self, dburl):
dialectPart = dburl.split(":")[0]
if dialectPart == 'mysql':
return 'MySQL'
elif dialectPart == 'oracle':
return 'Oracle'
elif dialectPart == 'http':
return 'CouchDB'
else:
raise RuntimeError("Unrecognized dialect %s" % dialectPart)
def setDatabaseConnection(self, connectUrl=None, socket=None, destroyAllDatabase = False):
"""
Set up the database connection by retrieving the environment
parameters.
The destroyAllDatabase option is for testing ONLY. Never flip that switch
on in any other instance where you don't know what you're doing.
"""
if not self.hasDatabase:
return
config = self.getConfiguration(connectUrl=connectUrl, socket=socket)
self.coreConfig = config
self.init.setDatabaseConnection(config.CoreDatabase.connectUrl,
config.CoreDatabase.dialect,
config.CoreDatabase.socket)
if trashDatabases or destroyAllDatabase:
self.clearDatabase()
# Have to check whether or not database is empty
# If the database is not empty when we go to set the schema, abort!
try:
result = self.init.checkDatabaseContents()
except OperationalError:
logging.debug("Error checking DB contents, assume DB does not exist")
return
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from WMCore.WMInit import WMInit [as 别名]
# 或者: from WMCore.WMInit.WMInit import checkDatabaseContents [as 别名]
class TestInit:
"""
A set of initialization steps used in many tests.
Test can call the methods from this class to
initialize their default environment so to
minimize code duplication.
"""
def __init__(self, testClassName = "Unknown Class"):
self.testClassName = testClassName
self.testDir = None
self.currModules = []
global hasDatabase
self.hasDatabase = hasDatabase
if self.hasDatabase:
self.init = WMInit()
self.deleteTmp = True
def __del__(self):
if self.deleteTmp:
self.delWorkDir()
self.attemptToCloseDBConnections()
def delWorkDir(self):
if (self.testDir != None):
try:
shutil.rmtree( self.testDir )
except:
# meh, if it fails, I guess something weird happened
pass
def setLogging(self, logLevel = logging.INFO):
"""
Sets logging parameters
"""
# remove old logging instances.
return
logger1 = logging.getLogger()
logger2 = logging.getLogger(self.testClassName)
for logger in [logger1, logger2]:
for handler in logger.handlers:
handler.close()
logger.removeHandler(handler)
self.init.setLogging(self.testClassName, self.testClassName,
logExists = False, logLevel = logLevel)
def generateWorkDir(self, config = None, deleteOnDestruction = True, setTmpDir = False):
self.testDir = tempfile.mkdtemp()
if config:
config.section_("General")
config.General.workDir = self.testDir
os.environ['TESTDIR'] = self.testDir
if os.getenv('WMCORE_KEEP_DIRECTORIES', False):
deleteOnDestruction = True
logging.info("Generated testDir - %s" % self.testDir)
if setTmpDir:
os.environ['TMPDIR'] = self.testDir
self.deleteTmp = deleteOnDestruction
return self.testDir
def getBackendFromDbURL(self, dburl):
dialectPart = dburl.split(":")[0]
if dialectPart == 'mysql':
return 'MySQL'
elif dialectPart == 'sqlite':
return 'SQLite'
elif dialectPart == 'oracle':
return 'Oracle'
elif dialectPart == 'http':
return 'CouchDB'
else:
raise RuntimeError, "Unrecognized dialect %s" % dialectPart
def setDatabaseConnection(self, connectUrl=None, socket=None, destroyAllDatabase = False):
"""
Set up the database connection by retrieving the environment
parameters.
The destroyAllDatabase option is for testing ONLY. Never flip that switch
on in any other instance where you don't know what you're doing.
"""
if not self.hasDatabase:
return
config = self.getConfiguration(connectUrl=connectUrl, socket=socket)
self.coreConfig = config
self.init.setDatabaseConnection(config.CoreDatabase.connectUrl,
config.CoreDatabase.dialect,
config.CoreDatabase.socket)
if trashDatabases or destroyAllDatabase:
self.clearDatabase()
# Have to check whether or not database is empty
# If the database is not empty when we go to set the schema, abort!
result = self.init.checkDatabaseContents()
if len(result) > 0:
msg = "Database not empty, cannot set schema !\n"
#.........这里部分代码省略.........