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

[tor-commits] [stem/master] Allow cached manual to be recreated when deleted



commit c09adaa744e7128b9281e1c70ace64207c8cfd35
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Aug 26 14:27:35 2017 -0700

    Allow cached manual to be recreated when deleted
    
    Ensuring Manual.from_cache() raises an IOError rather than a sqlite error when
    loading a file that doesn't exist. This should never arise for users when
    loading our local copy, but it's handy for cache_manual.py to handle that so we
    can delete and recreate the cache more easily.
---
 cache_manual.py | 17 +++++++++++------
 stem/manual.py  |  3 +++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/cache_manual.py b/cache_manual.py
index 7a4bd5c7..3112879a 100755
--- a/cache_manual.py
+++ b/cache_manual.py
@@ -39,15 +39,20 @@ if __name__ == '__main__':
   print('Current stem commit: %s' % stem_commit)
   print('')
 
-  cached_manual = stem.manual.Manual.from_cache()
+  try:
+    cached_manual = stem.manual.Manual.from_cache()
+  except IOError:
+    cached_manual = None  # local copy has been deleted
+
   latest_manual = stem.manual.Manual.from_remote()
 
-  if cached_manual == latest_manual:
-    print('Manual information is already up to date, nothing to do.')
-    sys.exit(0)
+  if cached_manual:
+    if cached_manual == latest_manual:
+      print('Manual information is already up to date, nothing to do.')
+      sys.exit(0)
 
-  print('Differences detected...\n')
-  print(stem.manual._manual_differences(cached_manual, latest_manual))
+    print('Differences detected...\n')
+    print(stem.manual._manual_differences(cached_manual, latest_manual))
 
   latest_manual.man_commit = man_commit
   latest_manual.stem_commit = stem_commit
diff --git a/stem/manual.py b/stem/manual.py
index 0e2ea8d8..a4590578 100644
--- a/stem/manual.py
+++ b/stem/manual.py
@@ -360,6 +360,9 @@ class Manual(object):
 
   @staticmethod
   def _from_sqlite_cache(path):
+    if not os.path.exists(path):
+      raise IOError("%s doesn't exist" % path)
+
     with sqlite3.connect(path) as conn:
       name, synopsis, description, man_commit, stem_commit = conn.execute('SELECT name, synopsis, description, man_commit, stem_commit FROM metadata').fetchone()
 



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