本文整理汇总了Python中sqlobject.connectionForURI函数的典型用法代码示例。如果您正苦于以下问题:Python connectionForURI函数的具体用法?Python connectionForURI怎么用?Python connectionForURI使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connectionForURI函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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:")
开发者ID:JamesX88,项目名称:tes,代码行数:9,代码来源:test_generate_sqlobject.py
示例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
开发者ID:sqlobject,项目名称:sqlobject,代码行数:11,代码来源:command.py
示例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)
开发者ID:hnez,项目名称:SpaceInviter,代码行数:32,代码来源:inviter.py
示例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
开发者ID:openwns,项目名称:wrowser,代码行数:35,代码来源:Database.py
示例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
开发者ID:openwns,项目名称:wrowser,代码行数:34,代码来源:Database.py
示例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
开发者ID:openwns,项目名称:wrowser,代码行数:27,代码来源:Database.py
示例7: getDB
def getDB():
global connection
if connection is not None:
return connection
connection = sqlobject.connectionForURI(settings.Connection_String)
return connection
开发者ID:1n5aN1aC,项目名称:rainmeter-pi,代码行数:7,代码来源:database.py
示例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)
开发者ID:SEL-Columbia,项目名称:localsms,代码行数:7,代码来源:db.py
示例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)
开发者ID:annttu,项目名称:accesslogparser,代码行数:7,代码来源:model.py
示例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
开发者ID:drnlm,项目名称:sutekh-test,代码行数:27,代码来源:DatabaseUpgrade.py
示例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)
开发者ID:codecollision,项目名称:DropboxToFlickr,代码行数:26,代码来源:huLint.py
示例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()
开发者ID:scith,项目名称:htpc-manager_ynh,代码行数:7,代码来源:settings.py
示例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
开发者ID:navyad,项目名称:python-labs,代码行数:7,代码来源:sqlwrapper.py
示例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)
开发者ID:ryanakca,项目名称:yokadi,代码行数:35,代码来源:db.py
示例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
开发者ID:BZZYTGTD,项目名称:snappy,代码行数:26,代码来源:backend.py
示例16: test_connection_override
def test_connection_override():
sqlhub.processConnection = connectionForURI('sqlite:///db1')
class SOTestSO13(SQLObject):
_connection = connectionForURI('sqlite:///db2')
assert SOTestSO13._connection.uri() == 'sqlite:///db2'
del sqlhub.processConnection
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:8,代码来源:test_basic.py
示例17: set_connection
def set_connection(scheme):
"""
Sets the databases connection.
Examples:
postgres://[email protected]/mypl_archive
postgres://[email protected]/mypl_archive
"""
sqlhub.processConnection = connectionForURI(scheme)
开发者ID:hudora,项目名称:myPLfrontend,代码行数:8,代码来源:sqladapter.py
示例18: _check_if_is_same_dir
def _check_if_is_same_dir(self, entry, path):
con_str = "sqlite://" + CATALOGDIR + entry
conn = connectionForURI(con_str)
metadircount = MetaDir.select(MetaDir.q.target == path,
connection = conn).count()
if metadircount > 0:
return MetaDir.select(MetaDir.q.target == path,
connection = conn)[0].target == path
开发者ID:godlike64,项目名称:indexor,代码行数:8,代码来源:dbmanager.py
示例19: getConnection
def getConnection(**kw):
name = getConnectionURI()
conn = sqlobject.connectionForURI(name, **kw)
if conftest.option.show_sql:
conn.debug = True
if conftest.option.show_sql_output:
conn.debugOutput = True
return conn
开发者ID:Antexa,项目名称:htpc_ynh,代码行数:8,代码来源:dbtest.py
示例20: _connect
def _connect(self, database_uri):
"""
Connect to the database
Argument:
* a different uri to connect to another database than the one in the config.py file (ie: for unittest)
"""
sqlobject.sqlhub.processConnection = sqlobject.connectionForURI(database_uri) if database_uri else sqlobject.connectionForURI(DATABASE_ACCESS)
开发者ID:Psycojoker,项目名称:holygrail,代码行数:8,代码来源:holygrail.py
注:本文中的sqlobject.connectionForURI函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论