[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Recaching manual if schema is out of date



commit 8ecb75a957fbb721e0053597bb0b6ab40a990f63
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue Aug 29 10:51:42 2017 -0700

    Recaching manual if schema is out of date
---
 cache_manual.py               |   3 +++
 stem/cached_tor_manual.sqlite | Bin 217088 -> 217088 bytes
 stem/manual.py                |  20 +++++++++++++++++++-
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/cache_manual.py b/cache_manual.py
index 3112879a..1022648b 100755
--- a/cache_manual.py
+++ b/cache_manual.py
@@ -41,6 +41,9 @@ 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
   except IOError:
     cached_manual = None  # local copy has been deleted
 
diff --git a/stem/cached_tor_manual.sqlite b/stem/cached_tor_manual.sqlite
index 81d0b230..bc50d083 100644
Binary files a/stem/cached_tor_manual.sqlite and b/stem/cached_tor_manual.sqlite differ
diff --git a/stem/manual.py b/stem/manual.py
index e520f2f8..21eb68ee 100644
--- a/stem/manual.py
+++ b/stem/manual.py
@@ -97,6 +97,22 @@ CATEGORY_SECTIONS = OrderedDict((
 ))
 
 
+class SchemeMismatch(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
+  """
+
+  def __init__(self, message, database_schema, library_schema):
+    super(SchemeMismatch, self).__init__(message)
+    self.database_schema = database_schema
+    self.library_schema = library_schema
+
+
 def query(query, *param):
   """
   Performs the given query on our sqlite manual cache. This database should
@@ -339,6 +355,7 @@ class Manual(object):
     self.config_options = config_options
     self.man_commit = None
     self.stem_commit = None
+    self.schema = None
 
   @staticmethod
   def from_cache(path = None):
@@ -384,7 +401,7 @@ class Manual(object):
         raise IOError('Failed to read database metadata from %s: %s' % (path, exc))
 
       if schema != SCHEMA_VERSION:
-        raise IOError("Stem's current manual schema version is %s, but %s was version %s" % (SCHEMA_VERSION, path, schema))
+        raise SchemeMismatch("Stem's current manual schema version is %s, but %s was version %s" % (SCHEMA_VERSION, path, schema), schema, SCHEMA_VERSION)
 
       commandline = dict(conn.execute('SELECT name, description FROM commandline').fetchall())
       signals = dict(conn.execute('SELECT name, description FROM signals').fetchall())
@@ -399,6 +416,7 @@ class Manual(object):
       manual = Manual(name, synopsis, description, commandline, signals, files, config_options)
       manual.man_commit = man_commit
       manual.stem_commit = stem_commit
+      manual.schema = schema
 
       return manual
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits