本文整理汇总了Python中sqlobject.connectionForURI函数的典型用法代码示例。如果您正苦于以下问题:Python connectionForURI函数的具体用法?Python connectionForURI怎么用?Python connectionForURI使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connectionForURI函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
def setup():
global memconn, realconn, sqlhub
if not env_supports.sqlobject:
raise SkipTest
from sqlobject import connectionForURI, sqlhub
realconn = connectionForURI(conf.HEAVY_DSN)
memconn = connectionForURI("sqlite:/:memory:")
示例2: connection
def connection(self):
config = self.config()
if config is not None:
assert config.get('database'), (
"No database variable found in config file %s"
% self.options.config_file)
return sqlobject.connectionForURI(config['database'])
elif getattr(self.options, 'connection_uri', None):
return sqlobject.connectionForURI(self.options.connection_uri)
else:
return None
示例3: __init__
def __init__(self, dburi='sqlite:/:memory:'):
super(WebApi, self).__init__()
# Guest api endpoints
self.get('/api/token/<token>', callback=self.api_get_guest)
self.put('/api/token/<token>', callback=self.api_edit_guest)
self.post('/api/token/<token>', callback=self.api_new_guest)
self.post('/api/token', callback=self.api_new_event)
# Event api endpoints
self.get('/api/token/<token>/event', callback=self.api_get_event)
self.put('/api/token/<token>/event', callback=self.api_edit_event)
# Chat api endpoints
self.get('/api/token/<token>/chat', callback=self.api_get_chat)
self.post('/api/token/<token>/chat', callback=self.api_new_message)
self.get('/api/token/<token>/chat/<msgid>', callback=self.api_get_message)
self.put('/api/token/<token>/chat/<msgid>', callback=self.api_edit_message)
self.delete('/api/token/<token>/chat/<msgid>', callback=self.api_del_message)
# Static files
self.get('/', callback=self.get_static('index.html'))
self.get('/event', callback=self.get_static('event.html'))
for f in ['inviter.js', 'histogram.js', 'frontend.js', 'style.css', 'spinner.gif']:
self.get('/' + f, callback=self.get_static(f))
# Create tables that do not exist
self.db= so.connectionForURI(dburi)
Event.createTable(True, connection=self.db)
Guest.createTable(True, connection=self.db)
ChatMsg.createTable(True, connection=self.db)
示例4: create
def create(path, dbName = 'scenarios.db', debug = False):
if isConnected():
disconnect()
campaignConfigurationPath = os.path.join(os.path.abspath(path), 'campaignConfiguration.py')
if not os.path.exists(campaignConfigurationPath):
raise 'File campaignConfiguration.py does not exist in path %s.' % path
campaignConfiguration = imp.load_module('foo',
file(campaignConfigurationPath),
'foo', ('.py', 'r', imp.PY_SOURCE))
dbPath = os.path.join(os.path.abspath(path), dbName)
if os.path.exists(dbPath):
raise 'Database already exists!'
__Vars.dbPath = dbPath
connectionString = 'sqlite:' + dbPath + '?timeout=1000000'
__Vars.connection = sqlobject.connectionForURI(connectionString)
sqlobject.sqlhub.processConnection = __Vars.connection
__accessDB(__setPragma, __Vars.connection)
for parameter in campaignConfiguration.parameters:
Scenario.Scenario.sqlmeta.addColumn(parameter)
Scenario.Scenario.createTable()
Scenario.Scenario._connection.debug = debug
Parameters.createTable()
campaignConfiguration.createCampaign()
Parameters(campaign = campaignConfiguration.parameters)
if debug:
print 'Database %s successfully created.' % dbPath
示例5: addParametersTable
def addParametersTable(path, dbName = 'scenarios.db', debug = False):
if isConnected():
disconnect()
campaignConfigurationPath = os.path.join(os.path.abspath(path), 'campaignConfiguration.py')
if not os.path.exists(campaignConfigurationPath):
raise 'File campaignConfiguration.py does not exist in path %s.' % path
campaignConfiguration = imp.load_module('foo',
file(campaignConfigurationPath),
'foo', ('.py', 'r', imp.PY_SOURCE))
dbPath = os.path.join(os.path.abspath(path), dbName)
if not os.path.exists(dbPath):
raise 'Database not found!'
__Vars.dbPath = dbPath
connectionString = 'sqlite:' + dbPath
__Vars.connection = sqlobject.connectionForURI(connectionString)
curs = __Vars.connection.getConnection().cursor()
curs.execute('PRAGMA synchronous = OFF') # SQLite specific
curs.close()
sqlobject.sqlhub.processConnection = __Vars.connection
for parameter in campaignConfiguration.parameters:
Scenario.Scenario.sqlmeta.addColumn(parameter)
Scenario.Scenario._connection.debug = debug
Parameters.createTable()
Parameters(campaign = campaignConfiguration.parameters)
if debug:
print 'Parameters table successfully added to %s.' % dbPath
示例6: connect
def connect(path, dbName = 'scenarios.db', debug = False):
dbPath = os.path.join(os.path.abspath(path), dbName)
if isConnected():
if dbPath == __Vars.dbPath:
return
else:
disconnect()
if not os.path.exists(dbPath):
raise 'Database not found!'
__Vars.dbPath = dbPath
connectionString = 'sqlite:' + dbPath + '?timeout=1000000'
__Vars.connection = sqlobject.connectionForURI(connectionString)
sqlobject.sqlhub.processConnection = __Vars.connection
__accessDB(__setPragma, __Vars.connection)
Scenario.Scenario._connection.debug = debug
parameters = Parameters.get(1)
for parameter in parameters.campaign:
Scenario.Scenario.sqlmeta.addColumn(parameter)
if debug:
print 'Connection to database %s established.' % dbPath
示例7: getDB
def getDB():
global connection
if connection is not None:
return connection
connection = sqlobject.connectionForURI(settings.Connection_String)
return connection
示例8: initdb
def initdb(config):
dbfile = os.path.abspath(config.get("app", "db_params"))
conn = connectionForURI("%s:%s" % (config.get("app", "db_type"), dbfile))
sqlhub.processConnection = conn
Message.createTable(ifNotExists=True)
ModemLog.createTable(ifNotExists=True)
MessageState.createTable(ifNotExists=True)
示例9: main
def main():
sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
SERVER='kirsikka'
DOMAIN='mirror.kapsi.fi'
Usage.createTable()
for i in Usage.select():
print unicode(i)
示例10: attempt_database_upgrade
def attempt_database_upgrade(oLogHandler=None):
"""Attempt to upgrade the database, going via a temporary memory copy."""
oTempConn = connectionForURI("sqlite:///:memory:")
oLogger = Logger('attempt upgrade')
if oLogHandler:
oLogger.addHandler(oLogHandler)
(bOK, aMessages) = create_memory_copy(oTempConn, oLogHandler)
if bOK:
oLogger.info("Copied database to memory, performing upgrade.")
if len(aMessages) > 0:
oLogger.info("Messages reported: %s", aMessages)
(bOK, aMessages) = create_final_copy(oTempConn, oLogHandler)
if bOK:
oLogger.info("Everything seems to have gone OK")
if len(aMessages) > 0:
oLogger.info("Messages reported %s", aMessages)
return True
else:
oLogger.critical("Unable to perform upgrade.")
if len(aMessages) > 0:
oLogger.error("Errors reported: %s", aMessages)
oLogger.critical("!!YOUR DATABASE MAY BE CORRUPTED!!")
else:
oLogger.error("Unable to create memory copy. Database not upgraded.")
if len(aMessages) > 0:
oLogger.error("Errors reported %s", aMessages)
return False
示例11: main
def main(repos, revision):
"""
Main function.
"""
import pysvn
import os.path
client = pysvn.Client()
diff = client.diff_summarize(repos,
revision1=pysvn.Revision(pysvn.opt_revision_kind.number, revision - 1),
revision2=pysvn.Revision(pysvn.opt_revision_kind.number, revision))
conn = sqlobject.connectionForURI(DATABASE_URI)
sqlobject.sqlhub.processConnection = conn
#PythonScore.createTable()
func = lambda f: os.path.splitext(f.path)[-1] == ".py"
for entry in filter(func, diff):
path = os.path.join(repos, entry.path)
score, old_score, credit = process_file(path)
info = client.info(path)
PythonScore(username=info['commit_author'], pathname=path, revision="1",
score=score, old_score=old_score, credit=credit)
示例12: __init__
def __init__(self):
""" Create table on load if table doesnt exist """
self.logger = logging.getLogger('htpc.settings')
self.logger.debug('Connecting to database: ' + htpc.DB)
sqlhub.processConnection = connectionForURI('sqlite:' + htpc.DB)
Setting.createTable(ifNotExists=True)
self.updatebl()
示例13: create_connection
def create_connection(file_name):
if os.path.exists(file_name):
os.unlink(file_name)
_scheme = 'sqlite:' + file_name
conn = connectionForURI(_scheme)
sqlhub.processConnection = conn
return conn
示例14: connectDatabase
def connectDatabase(dbFileName, createIfNeeded=True):
"""Connect to database and create it if needed
@param dbFileName: path to database file
@type dbFileName: str
@param createIfNeeded: Indicate if database must be created if it does not exists (default True)
@type createIfNeeded: bool"""
dbFileName=os.path.abspath(dbFileName)
if sys.platform == 'win32':
connectionString = 'sqlite:/'+ dbFileName[0] +'|' + dbFileName[2:]
else:
connectionString = 'sqlite:' + dbFileName
connection = connectionForURI(connectionString)
sqlhub.processConnection = connection
if not os.path.exists(dbFileName):
if createIfNeeded:
print "Creating database"
createTables()
# Set database version according to current yokadi release
Config(name=DB_VERSION_KEY, value=str(DB_VERSION), system=True, desc="Database schema release number")
else:
print "Database file (%s) does not exist or is not readable. Exiting" % dbFileName
sys.exit(1)
# Check version
version = getVersion()
if version != DB_VERSION:
tui.error("Your database version is %d but Yokadi wants version %d." \
% (version, DB_VERSION))
print "Please, run the %s/update.py script to migrate your database prior to running Yokadi" % \
os.path.abspath(utils.shareDirPath())
sys.exit(1)
示例15: _sqliteCreateDB
def _sqliteCreateDB(self, dbpath, model):
model = models.Model()
'''
Creates/syncs an sqlite DB at location dbpath.
Requires python 2.5 for sqlite3 module.
'''
try:
import sqlobject
except Exception:
print 'Python sqlite import failed.'
return False
if os.path.exists(dbpath):
os.remove(dbpath)
print 'Attempting connection to', dbpath + '...'
connectionpath = 'sqlite://' + dbpath
connection = sqlobject.connectionForURI(connectionpath)
sqlobject.sqlhub.processConnection = connection
transaction = connection.transaction()
print 'Vars:', dir(model)
for table in dir(model): #FIXME: is there a better way to do this?
if table[0] == '_':
continue
Table = getattr(model, table)
Table.createTable()
transaction.commit(close = True)
return dbpath