本文整理汇总了Python中twext.python.filepath.CachingFilePath.getContent方法的典型用法代码示例。如果您正苦于以下问题:Python CachingFilePath.getContent方法的具体用法?Python CachingFilePath.getContent怎么用?Python CachingFilePath.getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twext.python.filepath.CachingFilePath
的用法示例。
在下文中一共展示了CachingFilePath.getContent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ready
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import getContent [as 别名]
def ready(self, createDatabaseConn, createDatabaseCursor):
"""
Subprocess is ready. Time to initialize the subservice.
If the database has not been created and there is a dump file,
then the dump file is imported.
"""
if self.resetSchema:
try:
createDatabaseCursor.execute(
"drop database {}".format(self.databaseName)
)
except pgdb.DatabaseError:
pass
try:
createDatabaseCursor.execute(
"create database {} with encoding 'UTF8'"
.format(self.databaseName)
)
except:
# database already exists
executeSQL = False
else:
# database does not yet exist; if dump file exists, execute it,
# otherwise execute schema
executeSQL = True
sqlToExecute = self.schema
if self.importFileName:
importFilePath = CachingFilePath(self.importFileName)
if importFilePath.exists():
sqlToExecute = importFilePath.getContent()
createDatabaseCursor.close()
createDatabaseConn.close()
if executeSQL:
connection = self.produceConnection()
cursor = connection.cursor()
cursor.execute(sqlToExecute)
connection.commit()
connection.close()
if self.shutdownDeferred is None:
# Only continue startup if we've not begun shutdown
self.subServiceFactory(
self.produceConnection, self
).setServiceParent(self)