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


Python DB.dbexists方法代码示例

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


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

示例1: do

# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import dbexists [as 别名]
    def do(self, args):
        """Proceeds to the creation of an instance"""

        # TODO Remove these ugly lines, but I'm lazy to rewrite the variables in this method...
        class Bunch:
            __init__ = lambda self, **kw: setattr(self, '__dict__', kw)
        args = Bunch(**args)

        engine = args.engine
        version = args.version
        name = self.Wp.generateInstanceName(version, integration=args.integration, suffix=args.suffix, identifier=args.identifier)

        # Wording version
        versionNice = version
        if version == 'master':
            versionNice = self.C.get('wording.master')

        # Generating names
        if args.integration:
            fullname = self.C.get('wording.integration') + ' ' + versionNice + ' ' + self.C.get('wording.%s' % engine)
        else:
            fullname = self.C.get('wording.stable') + ' ' + versionNice + ' ' + self.C.get('wording.%s' % engine)

        # Append the suffix
        if args.suffix:
            fullname += ' ' + args.suffix.replace('-', ' ').replace('_', ' ').title()

        # Create the instance
        logging.info('Creating instance %s...' % name)
        kwargs = {
            'name': name,
            'version': version,
            'integration': args.integration
        }
        try:
            M = self.Wp.create(**kwargs)
        except CreateException as e:
            logging.error('Error creating %s:\n  %s' % (name, e))
            return False
        except Exception as e:
            logging.exception('Error creating %s:\n  %s' % (name, e))
            return False

        # Run the install script
        if args.install:

            # Checking database
            dbname = re.sub(r'[^a-zA-Z0-9]', '', name).lower()[:28]
            db = DB(engine, self.C.get('db.%s' % engine))
            dropDb = False
            if db.dbexists(dbname):
                logging.info('Database already exists (%s)' % dbname)
                dropDb = yesOrNo('Do you want to remove it?')

            # Install
            kwargs = {
                'engine': engine,
                'dbname': dbname,
                'dropDb': dropDb,
                'fullname': fullname,
                'dataDir': self.Wp.getPath(name, 'data')
            }
            try:
                M.install(**kwargs)
            except InstallException as e:
                logging.warning('Error while installing %s:\n  %s' % (name, e))
                return False
            except Exception as e:
                logging.exception('Error while installing %s:\n  %s' % (name, e))
                return False

            # Running scripts
            if M.isInstalled() and type(args.run) == list:
                for script in args.run:
                    logging.info('Running script \'%s\'' % (script))
                    try:
                        M.runScript(script)
                    except Exception as e:
                        logging.warning('Error while running the script \'%s\':\  %s' % (script, e))
开发者ID:rajeshtaneja,项目名称:mdk,代码行数:81,代码来源:create.py


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