本文整理汇总了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))