本文整理匯總了Python中db.DB.dbexists方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.dbexists方法的具體用法?Python DB.dbexists怎麽用?Python DB.dbexists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db.DB
的用法示例。
在下文中一共展示了DB.dbexists方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: install
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import dbexists [as 別名]
def install(self, dbname=None, engine=None, dataDir=None, fullname=None, dropDb=False):
"""Launch the install script of an Instance"""
if self.isInstalled():
raise InstallException('Instance already installed!')
if dataDir == None or not os.path.isdir(dataDir):
raise InstallException('Cannot install instance without knowing where the data directory is')
if dbname == None:
dbname = re.sub(r'[^a-zA-Z0-9]', '', self.identifier).lower()[:28]
if engine == None:
engine = C.get('defaultEngine')
if fullname == None:
fullname = self.identifier.replace('-', ' ').replace('_', ' ').title()
fullname = fullname + ' ' + C.get('wording.%s' % engine)
logging.info('Creating database...')
db = DB(engine, C.get('db.%s' % engine))
if db.dbexists(dbname):
if dropDb:
db.dropdb(dbname)
db.createdb(dbname)
else:
raise InstallException('Cannot install an instance on an existing database (%s)' % dbname)
else:
db.createdb(dbname)
db.selectdb(dbname)
# Defining wwwroot.
wwwroot = '%s://%s/' % (C.get('scheme'), C.get('host'))
if C.get('path') != '' and C.get('path') != None:
wwwroot = wwwroot + C.get('path') + '/'
wwwroot = wwwroot + self.identifier
logging.info('Installing %s...' % self.identifier)
cli = 'admin/cli/install.php'
params = (wwwroot, dataDir, engine, dbname, C.get('db.%s.user' % engine), C.get('db.%s.passwd' % engine), C.get('db.%s.host' % engine), fullname, self.identifier, C.get('login'), C.get('passwd'))
args = '--wwwroot="%s" --dataroot="%s" --dbtype="%s" --dbname="%s" --dbuser="%s" --dbpass="%s" --dbhost="%s" --fullname="%s" --shortname="%s" --adminuser="%s" --adminpass="%s" --allow-unstable --agree-license --non-interactive' % params
result = self.cli(cli, args, stdout=None, stderr=None)
if result[0] != 0:
raise InstallException('Error while running the install, please manually fix the problem.\n- Command was: %s %s %s' % (C.get('php'), cli, args))
configFile = os.path.join(self.path, 'config.php')
os.chmod(configFile, 0666)
try:
self.addConfig('sessioncookiepath', '/%s/' % self.identifier)
except InstallException:
logging.warning('Could not append $CFG->sessioncookiepath to config.php')
self.reload()
示例2: install
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import dbexists [as 別名]
def install(self, dbname=None, engine=None, dataDir=None, fullname=None, dropDb=False):
"""Launch the install script of an Instance"""
if self.isInstalled():
raise InstallException("Instance already installed!")
if dataDir == None or not os.path.isdir(dataDir):
raise InstallException("Cannot install instance without knowing where the data directory is")
if dbname == None:
dbname = re.sub(r"[^a-zA-Z0-9]", "", self.identifier).lower()[:28]
if engine == None:
engine = C.get("defaultEngine")
if fullname == None:
fullname = self.identifier.replace("-", " ").replace("_", " ").title()
fullname = fullname + " " + C.get("wording.%s" % engine)
logging.info("Creating database...")
db = DB(engine, C.get("db.%s" % engine))
if db.dbexists(dbname):
if dropDb:
db.dropdb(dbname)
db.createdb(dbname)
else:
raise InstallException("Cannot install an instance on an existing database (%s)" % dbname)
else:
db.createdb(dbname)
db.selectdb(dbname)
# Defining wwwroot.
wwwroot = "%s://%s/" % (C.get("scheme"), C.get("host"))
if C.get("path") != "" and C.get("path") != None:
wwwroot = wwwroot + C.get("path") + "/"
wwwroot = wwwroot + self.identifier
logging.info("Installing %s..." % self.identifier)
cli = "admin/cli/install.php"
params = (
wwwroot,
dataDir,
engine,
dbname,
C.get("db.%s.user" % engine),
C.get("db.%s.passwd" % engine),
C.get("db.%s.host" % engine),
fullname,
self.identifier,
C.get("login"),
C.get("passwd"),
)
args = (
'--wwwroot="%s" --dataroot="%s" --dbtype="%s" --dbname="%s" --dbuser="%s" --dbpass="%s" --dbhost="%s" --fullname="%s" --shortname="%s" --adminuser="%s" --adminpass="%s" --allow-unstable --agree-license --non-interactive'
% params
)
result = self.cli(cli, args, stdout=None, stderr=None)
if result[0] != 0:
raise InstallException(
"Error while running the install, please manually fix the problem.\n- Command was: %s %s %s"
% (C.get("php"), cli, args)
)
configFile = os.path.join(self.path, "config.php")
os.chmod(configFile, 0666)
try:
self.addConfig("sessioncookiepath", "/%s/" % self.identifier)
except InstallException:
logging.warning("Could not append $CFG->sessioncookiepath to config.php")
self.reload()
示例3: restore
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import dbexists [as 別名]
def restore(self, destination=None):
"""Restores the backup"""
identifier = self.get("identifier")
if not identifier:
raise Exception("Identifier is invalid! Cannot proceed.")
Wp = Workplace()
if destination == None:
destination = self.get("backup_origin")
if not destination:
raise Exception("Wrong path to perform the restore!")
if os.path.isdir(destination):
raise BackupDirectoryExistsException("Destination directory already exists!")
# Restoring database
if self.get("installed") and os.path.isfile(self.sqlfile):
dbname = self.get("dbname")
dbo = DB(self.get("dbtype"), C.get("db.%s" % self.get("dbtype")))
if dbo.dbexists(dbname):
raise BackupDBExistsException("Database already exists!")
# Copy tree to destination
try:
logging.info("Restoring instance directory")
copy_tree(self.path, destination, preserve_symlinks=1)
M = Wp.get(identifier)
chmodRecursive(Wp.getPath(identifier, "data"), 0777)
except Exception as e:
raise Exception("Error while restoring directory\n%s\nto %s. Exception: %s" % (self.path, destination, e))
# Restoring database
if self.get("installed") and os.path.isfile(self.sqlfile):
logging.info("Restoring database")
content = ""
f = open(self.sqlfile, "r")
for l in f:
content += l
queries = content.split(";\n")
content = None
logging.info("%d queries to execute" % (len(queries)))
dbo.createdb(dbname)
dbo.selectdb(dbname)
done = 0
for query in queries:
if len(query.strip()) == 0:
continue
try:
dbo.execute(query)
except:
logging.error("Query failed! You will have to fix this mually. %s", query)
done += 1
if done % 500 == 0:
logging.debug("%d queries done" % done)
logging.info("%d queries done" % done)
dbo.close()
# Restoring symbolic link
linkDir = os.path.join(Wp.www, identifier)
wwwDir = Wp.getPath(identifier, "www")
if os.path.islink(linkDir):
os.remove(linkDir)
if os.path.isfile(linkDir) or os.path.isdir(linkDir): # No elif!
logging.warning("Could not create symbolic link. Please manually create: ln -s %s %s" % (wwwDir, linkDir))
else:
os.symlink(wwwDir, linkDir)
return M
示例4: restore
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import dbexists [as 別名]
def restore(self, destination = None):
"""Restores the backup"""
identifier = self.get('identifier')
if not identifier:
raise Exception('Identifier is invalid! Cannot proceed.')
Wp = Workplace()
if destination == None:
destination = self.get('backup_origin')
if not destination:
raise Exception('Wrong path to perform the restore!')
if os.path.isdir(destination):
raise BackupDirectoryExistsException('Destination directory already exists!')
# Restoring database
if self.get('installed') and os.path.isfile(self.sqlfile):
dbname = self.get('dbname')
dbo = DB(self.get('dbtype'), C.get('db.%s' % self.get('dbtype')))
if dbo.dbexists(dbname):
raise BackupDBExistsException('Database already exists!')
# Copy tree to destination
try:
debug('Restoring instance directory')
copy_tree(self.path, destination, preserve_symlinks = 1)
M = Wp.get(identifier)
chmodRecursive(Wp.getPath(identifier, 'data'), 0777)
except Exception as e:
raise Exception('Error while restoring directory\n%s\nto %s. Exception: %s' % (self.path, destination, e))
# Restoring database
if self.get('installed') and os.path.isfile(self.sqlfile):
debug('Restoring database')
content = ''
f = open(self.sqlfile, 'r')
for l in f:
content += l
queries = content.split(';\n')
content = None
debug("%d queries to execute" % (len(queries)))
dbo.createdb(dbname)
dbo.selectdb(dbname)
done = 0
for query in queries:
if len(query.strip()) == 0: continue
try:
dbo.execute(query)
except:
debug('Query failed! You will have to fix this mually.')
debug(query)
done += 1
if done % 500 == 0:
debug("%d queries done" % done)
debug('%d queries done' % done)
dbo.close()
# Restoring symbolic link
linkDir = os.path.join(Wp.www, identifier)
wwwDir = Wp.getPath(identifier, 'www')
if os.path.islink(linkDir):
os.remove(linkDir)
if os.path.isfile(linkDir) or os.path.isdir(linkDir): # No elif!
debug('Could not create symbolic link')
debug('Please manually create: ln -s %s %s' % (wwwDir, linkDir))
else:
os.symlink(wwwDir, linkDir)
return M