Projects
Kolab:3.4
pykolab
pykolab-0.6.12-allow-auth_cache-reinitializatio...
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File pykolab-0.6.12-allow-auth_cache-reinitialization.patch of Package pykolab (Revision 71)
Currently displaying revision
71
,
Show latest
commit 10785ecebb741406b9403b1d0c32c1343b9acfd0 Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> Date: Sun Feb 16 01:46:24 2014 +0100 Allow the auth_cache database to be regenerated automatically when sqlite on the local filesystem gives errors diff --git a/pykolab/auth/ldap/auth_cache.py b/pykolab/auth/ldap/auth_cache.py index 488deac..bcf38dc 100644 --- a/pykolab/auth/ldap/auth_cache.py +++ b/pykolab/auth/ldap/auth_cache.py @@ -88,12 +88,29 @@ mapper(Entry, entry_table) def del_entry(key): db = init_db() - _entries = db.query(Entry).filter_by(key=key).delete() + + try: + _entries = db.query(Entry).filter_by(key=key).delete() + except sqlalchemy.exc.OperationalError, errmsg: + db = init_db(reinit=True) + except sqlalchemy.exc.InvalidRequest, errmsg: + db = init_db(reinit=True) + finally: + _entries = db.query(Entry).filter_by(key=key).delete() + db.commit() def get_entry(key): db = init_db() - _entries = db.query(Entry).filter_by(key=key).all() + + try: + _entries = db.query(Entry).filter_by(key=key).all() + except sqlalchemy.exc.OperationalError, errmsg: + db = init_db(reinit=True) + except sqlalchemy.exc.InvalidRequest, errmsg: + db = init_db(reinit=True) + finally: + _entries = db.query(Entry).filter_by(key=key).all() if len(_entries) == 0: return None @@ -107,7 +124,14 @@ def get_entry(key): def set_entry(key, value): db = init_db() - _entries = db.query(Entry).filter_by(key=key).all() + try: + _entries = db.query(Entry).filter_by(key=key).all() + except sqlalchemy.exc.OperationalError, errmsg: + db = init_db(reinit=True) + except sqlalchemy.exc.InvalidRequest, errmsg: + db = init_db(reinit=True) + finally: + _entries = db.query(Entry).filter_by(key=key).all() if len(_entries) == 0: db.add( @@ -129,19 +153,24 @@ def purge_entries(db): db.query(Entry).filter(Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(1))).delete() db.commit() -def init_db(): +def init_db(reinit=False): """ Returns a SQLAlchemy Session() instance. """ global db - if not db == None: + if not db == None and not reinit: return db db_uri = conf.get('ldap', 'auth_cache_uri') if db_uri == None: db_uri = 'sqlite:///%s/auth_cache.db' % (KOLAB_LIB_PATH) + if reinit: + import os + if os.path.isfile('%s/auth_cache.db' % (KOLAB_LIB_PATH)): + os.unlink('%s/auth_cache.db' % (KOLAB_LIB_PATH)) + echo = conf.debuglevel > 8 engine = create_engine(db_uri, echo=echo) metadata.create_all(engine)
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.