Mercurial > p > roundup > code
comparison roundup/backends/back_sqlite.py @ 6804:25d08e15e3b4
issue2551224 - Replace dbm db for sessions/otks when using sqlite
Generate new sqlite db's for storing one time keys and session and
other ephemeral data.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 25 Jul 2022 15:30:36 -0400 |
| parents | 39189dd94f2c |
| children | 3f60a71b0812 |
comparison
equal
deleted
inserted
replaced
| 6803:db437dd13ed5 | 6804:25d08e15e3b4 |
|---|---|
| 10 | 10 |
| 11 import os, marshal, shutil, time, logging | 11 import os, marshal, shutil, time, logging |
| 12 | 12 |
| 13 from roundup import hyperdb, date, password | 13 from roundup import hyperdb, date, password |
| 14 from roundup.backends import rdbms_common | 14 from roundup.backends import rdbms_common |
| 15 from roundup.backends.sessions_dbm import Sessions, OneTimeKeys | 15 from roundup.backends.sessions_sqlite import Sessions, OneTimeKeys |
| 16 from roundup.anypy.strings import uany2s | 16 from roundup.anypy.strings import uany2s |
| 17 | 17 |
| 18 sqlite_version = None | 18 sqlite_version = None |
| 19 try: | 19 try: |
| 20 import sqlite3 as sqlite | 20 import sqlite3 as sqlite |
| 126 # starting from about half a second | 126 # starting from about half a second |
| 127 time_to_sleep = 0.01 * (2 << min(5, count)) | 127 time_to_sleep = 0.01 * (2 << min(5, count)) |
| 128 time.sleep(time_to_sleep) | 128 time.sleep(time_to_sleep) |
| 129 return 1 | 129 return 1 |
| 130 | 130 |
| 131 def sql_open_connection(self): | 131 def sql_open_connection(self, dbname=None): |
| 132 """Open a standard, non-autocommitting connection. | 132 """Open a standard, non-autocommitting connection. |
| 133 | 133 |
| 134 pysqlite will automatically BEGIN TRANSACTION for us. | 134 pysqlite will automatically BEGIN TRANSACTION for us. |
| 135 """ | 135 """ |
| 136 # make sure the database directory exists | 136 # make sure the database directory exists |
| 137 # database itself will be created by sqlite if needed | 137 # database itself will be created by sqlite if needed |
| 138 if not os.path.isdir(self.config.DATABASE): | 138 if not os.path.isdir(self.config.DATABASE): |
| 139 os.makedirs(self.config.DATABASE) | 139 os.makedirs(self.config.DATABASE) |
| 140 | 140 |
| 141 db = os.path.join(self.config.DATABASE, 'db') | 141 if dbname: |
| 142 db = os.path.join(self.config.DATABASE, 'db-' + dbname) | |
| 143 else: | |
| 144 db = os.path.join(self.config.DATABASE, 'db') | |
| 142 logging.getLogger('roundup.hyperdb').info('open database %r' % db) | 145 logging.getLogger('roundup.hyperdb').info('open database %r' % db) |
| 143 # set timeout (30 second default is extraordinarily generous) | 146 # set timeout (30 second default is extraordinarily generous) |
| 144 # for handling locked database | 147 # for handling locked database |
| 145 if sqlite_version == 1: | 148 if sqlite_version == 1: |
| 146 conn = sqlite.connect(db=db) | 149 conn = sqlite.connect(db=db) |
