~stefanor/ibid/logfile-visibility-567576

« back to all changes in this revision

Viewing changes to ibid/core.py

  • Committer: Tarmac
  • Author(s): Stefano Rivera
  • Date: 2010-08-15 17:40:53 UTC
  • mfrom: (945.2.2 fast-sqlite-create)
  • Revision ID: ibid-lp-lander@rivera.za.net-20100815174053-cjmh6gtuo2m2yyes
Turn off SQLite synchronous writes during ibid-setup
Author: Stefano Rivera
Approved by: Stefano Rivera

Show diffs side-by-side

added added

removed removed

Lines of Context:
295
295
def regexp(pattern, item):
296
296
    return re.search(pattern, item, re.I) and True or False
297
297
 
298
 
def sqlite_creator(database):
 
298
def sqlite_creator(database, synchronous=True):
299
299
    from pysqlite2 import dbapi2 as sqlite
300
300
    def connect():
301
301
        connection = sqlite.connect(database)
302
302
        connection.create_function('regexp', 2, regexp)
 
303
        if not synchronous:
 
304
            connection.execute('PRAGMA synchronous = OFF')
 
305
        connection.execute('PRAGMA foreign_keys=ON')
303
306
        return connection
304
307
    return connect
305
308
 
306
309
class DatabaseManager(dict):
307
310
 
308
 
    def __init__(self, check_schema_versions=True):
 
311
    def __init__(self, check_schema_versions=True, sqlite_synchronous=True):
309
312
        self.log = logging.getLogger('core.databases')
 
313
        self.sqlite_synchronous = sqlite_synchronous
310
314
        for database in ibid.config.databases.keys():
311
315
            self.load(database)
312
316
 
324
328
        if uri.startswith('sqlite:///'):
325
329
            engine = create_engine('sqlite:///',
326
330
                creator=sqlite_creator(join(ibid.options['base'],
327
 
                    expanduser(uri.replace('sqlite:///', '', 1)))),
 
331
                        expanduser(uri.replace('sqlite:///', '', 1))),
 
332
                    self.sqlite_synchronous),
328
333
                encoding='utf-8', convert_unicode=True,
329
334
                assert_unicode=True, echo=echo
330
335
            )