Permalink
Browse files

don't lose all the data if you write without a get

  • Loading branch information...
ralsina committed Jan 6, 2016
1 parent a52f395 commit ef2fb8129af701bb8745c629a6d609fc19d006dc
Showing with 7 additions and 3 deletions.
  1. +7 −3 nikola/state.py
@@ -51,22 +51,26 @@ def __init__(self, path):

def get(self, key):
"""Get data stored in key."""
if os.path.isfile(path):
with open(path) as inf:
self.data = json.load(inf)
return self.data.get(key)

def set(self, key, value):
"""Store value in key."""
self._read()
self.data[key] = value
self._save()

def delete(self, key):
"""Delete key and the value it contains."""
self._read()
if key in self.data:
self.data.pop(key)
self._save()

def _read(self)
if os.path.isfile(self._path):
with open(self._path) as inf:
self.data = json.load(inf)

def _save(self):
tpath = self._path + '.tmp'
with open(tpath, 'w') as outf:

0 comments on commit ef2fb81

Please sign in to comment.