[stem/master] Let library read multiple schemas

commit a937507c68e82e655243b898256789072480b6f1 Author: Damian Johnson <atagar@torproject.org> Date: Tue Aug 29 13:26:24 2017 -0700 Let library read multiple schemas We'll probably want to provide backward compatability with prior minor version releases, but not development commits. Changing the exception so we can provide a tuple of what we support rather than just a single schema version. --- cache_manual.py | 12 ++++++++---- stem/manual.py | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cache_manual.py b/cache_manual.py index 1022648b..0d07fa5f 100755 --- a/cache_manual.py +++ b/cache_manual.py @@ -41,11 +41,15 @@ if __name__ == '__main__': try: cached_manual = stem.manual.Manual.from_cache() - except stem.manual.SchemeMismatch as exc: - print('Cached database schema is out of date (was %s, but current version is %s)' % (exc.database_schema, exc.library_schema)) - cached_manual = None + db_schema = cached_manual.schema + except stem.manual.SchemaMismatch as exc: + cached_manual, db_schema = None, exc.database_schema except IOError: - cached_manual = None # local copy has been deleted + cached_manual, db_schema = None, None # local copy has been deleted + + if db_schema != stem.manual.SCHEMA_VERSION: + print('Cached database schema is out of date (was %s, but current version is %s)' % (exc.database_schema, stem.manual.SCHEMA_VERSION)) + cached_manual = None latest_manual = stem.manual.Manual.from_remote() diff --git a/stem/manual.py b/stem/manual.py index 366b0ea9..290688e6 100644 --- a/stem/manual.py +++ b/stem/manual.py @@ -108,18 +108,18 @@ CATEGORY_SECTIONS = OrderedDict(( )) -class SchemeMismatch(IOError): +class SchemaMismatch(IOError): """ Database schema doesn't match what Stem supports. .. versionadded:: 1.6.0 :var int database_schema: schema of the database - :var int library_schema: schema of the library + :var tuple supported_schemas: schemas library supports """ def __init__(self, message, database_schema, library_schema): - super(SchemeMismatch, self).__init__(message) + super(SchemaMismatch, self).__init__(message) self.database_schema = database_schema self.library_schema = library_schema @@ -410,7 +410,7 @@ class Manual(object): schema = conn.execute('SELECT version FROM schema').fetchone()[0] if schema != SCHEMA_VERSION: - raise SchemeMismatch("Stem's current manual schema version is %s, but %s was version %s" % (SCHEMA_VERSION, path, schema), schema, SCHEMA_VERSION) + raise SchemaMismatch("Stem's current manual schema version is %s, but %s was version %s" % (SCHEMA_VERSION, path, schema), schema, (SCHEMA_VERSION,)) name, synopsis, description, man_commit, stem_commit = conn.execute('SELECT name, synopsis, description, man_commit, stem_commit FROM metadata').fetchone() except sqlite3.OperationalError as exc:
participants (1)
-
atagar@torproject.org