当前位置: 首页>>代码示例>>Python>>正文


Python WMInit.setSchema方法代码示例

本文整理汇总了Python中WMCore.WMInit.WMInit.setSchema方法的典型用法代码示例。如果您正苦于以下问题:Python WMInit.setSchema方法的具体用法?Python WMInit.setSchema怎么用?Python WMInit.setSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WMCore.WMInit.WMInit的用法示例。


在下文中一共展示了WMInit.setSchema方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testB_Database

# 需要导入模块: from WMCore.WMInit import WMInit [as 别名]
# 或者: from WMCore.WMInit.WMInit import setSchema [as 别名]
    def testB_Database(self):
        """
        _Database_

        Testing the database stuff.
        """

        init = WMInit()
        url     = os.environ.get("DATABASE")
        dialect = os.environ.get("DIALECT")
        sock    = os.environ.get("DBSOCK", None)

        init.setDatabaseConnection(url, dialect, sock)

        try:
            # Initial clear should work
            myThread = threading.currentThread()
            init.clearDatabase()

            # Clear one after another should work
            init.setSchema(modules = ['WMCore.WMBS'])
            init.clearDatabase()
            init.setSchema(modules = ['WMCore.WMBS'])
            init.clearDatabase()

            # Clear non-existant DB should work
            # Drop the database, and then make sure the database gets recreated
            a = myThread.dbi.engine.url.database
            dbName = myThread.dbi.processData("SELECT DATABASE() AS dbname")[0].fetchall()[0][0]
            myThread.dbi.processData("DROP DATABASE %s" % dbName)
            dbName = myThread.dbi.processData("SELECT DATABASE() AS dbname")[0].fetchall()[0][0]
            self.assertEqual(dbName, None)
            init.clearDatabase()
            dbName = myThread.dbi.processData("SELECT DATABASE() AS dbname")[0].fetchall()[0][0]
            self.assertEqual(dbName, a)


            init.setSchema(modules = ['WMCore.WMBS'])
            myThread.transaction.begin()
            myThread.transaction.processData("SELECT * FROM wmbs_job")
            init.clearDatabase()
            dbName = myThread.dbi.processData("SELECT DATABASE() AS dbname")[0].fetchall()[0][0]
            self.assertEqual(dbName, a)
            myThread.transaction.begin()
            init.setSchema(modules = ['WMCore.WMBS'])
            myThread.transaction.commit()
        except:
            init.clearDatabase()
            raise

        init.clearDatabase()        

        return        
开发者ID:stuartw,项目名称:WMCore,代码行数:55,代码来源:WMInit_t.py

示例2: __init__

# 需要导入模块: from WMCore.WMInit import WMInit [as 别名]
# 或者: from WMCore.WMInit.WMInit import setSchema [as 别名]

#.........这里部分代码省略.........
                    return
                
                query = "DROP TABLE IF EXISTS `%s`" % ("`,`".join(allTables))
                formatter.sql = query
                formatter.execute()

                formatter.sql = "SET foreign_key_checks = 1"
                formatter.execute()
                
            elif (dialect == 'SQLite'):
                formatter.sql = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"
                result = formatter.execute()

                for oneTable in result:
                    # sqlite stores some magic in the database
                    if ( oneTable[0].startswith('sqlite_') ):
                        continue
                    query = "DROP TABLE IF EXISTS %s" % oneTable[0]
                    failCount = 0
                    for x in range(5):
                        try:
                            formatter.sql = query
                            formatter.execute()
                        except Exception:
                            # sleep a sec and try again
                            failCount = failCount + 1
                            if (failCount == 5):
                                raise
                            else:
                                print "Attempting to wait before clearing SQLite database again"
                                time.sleep(1)
                            
      
            elif (dialect == 'Oracle'):
                print "Rookie, fix blowing away oracle in TestInit. thanks"
                pass
            else:
                raise RuntimeError, "This dialect is unsupported by trashDatabases"
            pass
        else:
            pass
        
    def setDatabaseConnection(self, connectUrl=None, socket=None):
        """
        Set up the database connection by retrieving the environment
        parameters.
        """
        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:
            # we are going to own ths database.
            #  ...but the code isn't ready yet
            self.eraseEverythingInDatabase()
            pass
        

    def setSchema(self, customModules = [], useDefault = True, params = None):
        """
        Creates the schema in the database for the default 
        tables/services: trigger, message service, threadpool.
       
        Developers can add their own modules to it using the array
        customModules which should follow the proper naming convention.

        if useDefault is set to False, it will not instantiate the
        schemas in the defaultModules array.
        """
        if not self.hasDatabase:
            return 
        defaultModules = ["WMCore.WMBS"]
        if not useDefault:
            defaultModules = []

        # filter out unique modules
        modules = {}
        for module in (defaultModules + customModules):
            modules[module] = 'done'
            
        try:
            self.init.setSchema(modules.keys(), params = params)
        except Exception, ex:
            try:
                self.clearDatabase(modules = modules.keys())
            except:
                pass
            raise ex
            
        # store the list of modules we've added to the DB
        modules = {}
        for module in (defaultModules + customModules + self.currModules):
            modules[module] = 'done'

        self.currModules = modules.keys()
        return
开发者ID:zhiwenuil,项目名称:WMCore,代码行数:104,代码来源:TestInit.py

示例3: TestInit

# 需要导入模块: from WMCore.WMInit import WMInit [as 别名]
# 或者: from WMCore.WMInit.WMInit import setSchema [as 别名]

#.........这里部分代码省略.........
        """
        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
        if len(result) > 0:
            msg = "Database not empty, cannot set schema !\n"
            msg += str(result)
            logging.error(msg)
            raise TestInitException(msg)

        return

    def setSchema(self, customModules = [], useDefault = True, params = None):
        """
        Creates the schema in the database for the default
        tables/services: trigger, message service, threadpool.

        Developers can add their own modules to it using the array
        customModules which should follow the proper naming convention.

        if useDefault is set to False, it will not instantiate the
        schemas in the defaultModules array.
        """
        if not self.hasDatabase:
            return
        defaultModules = ["WMCore.WMBS"]
        if not useDefault:
            defaultModules = []

        # filter out unique modules
        modules = {}
        for module in (defaultModules + customModules):
            modules[module] = 'done'

        try:
            self.init.setSchema(modules.keys(), params = params)
        except Exception as ex:
            print(traceback.format_exc())
            raise ex

        # store the list of modules we've added to the DB
        modules = {}
        for module in (defaultModules + customModules + self.currModules):
            modules[module] = 'done'
开发者ID:alexanderrichards,项目名称:WMCore,代码行数:69,代码来源:TestInit.py

示例4: __init__

# 需要导入模块: from WMCore.WMInit import WMInit [as 别名]
# 或者: from WMCore.WMInit.WMInit import setSchema [as 别名]

#.........这里部分代码省略.........
                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" 
            msg += str(result) 
            logging.error(msg) 
            raise TestInitException(msg) 

        return

    def setSchema(self, customModules = [], useDefault = True, params = None):
        """
        Creates the schema in the database for the default 
        tables/services: trigger, message service, threadpool.
       
        Developers can add their own modules to it using the array
        customModules which should follow the proper naming convention.

        if useDefault is set to False, it will not instantiate the
        schemas in the defaultModules array.
        """
        if not self.hasDatabase:
            return 
        defaultModules = ["WMCore.WMBS"]
        if not useDefault:
            defaultModules = []

        # filter out unique modules
        modules = {}
        for module in (defaultModules + customModules):
            modules[module] = 'done'

        try:
            self.init.setSchema(modules.keys(), params = params)
        except Exception, ex:
            print traceback.format_exc()
            raise ex
            
        # store the list of modules we've added to the DB
        modules = {}
        for module in (defaultModules + customModules + self.currModules):
            modules[module] = 'done'

        self.currModules = modules.keys()

        return
开发者ID:stuartw,项目名称:WMCore,代码行数:104,代码来源:TestInit.py


注:本文中的WMCore.WMInit.WMInit.setSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。