Skip to content

Commit

Permalink
Fixes #21. Read-only access now works.
Browse files Browse the repository at this point in the history
A regenerated Treant tries to apply any necessary schema updates to its
state file upon init, but when loading read-only Treants this will yield
an exception. Thus, if updating fails, the Treant now lets it slide and
will work as normal (read-only methods will work).
  • Loading branch information
dotsdl committed Nov 13, 2015
1 parent 9154e41 commit 832b2a8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions datreant/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,13 @@ def __init__(self, filename, logger=None, **kwargs):
"""
super(TreantFile, self).__init__(filename, logger=logger)

# if file does not exist, it is created
self.create(**kwargs)
# if file does not exist, it is created; if it does exist, it is updated
try:
self.create(**kwargs)
except OSError:
# in case the file is read-only; we can't update but may still want
# to use it
pass

def _open_file_r(self):
return tables.open_file(self.filename, 'r')
Expand Down

0 comments on commit 832b2a8

Please sign in to comment.