Skip to content

Commit

Permalink
Default location for the json file database is no in the user home di…
Browse files Browse the repository at this point in the history
…rectory.
  • Loading branch information
JasperVanDenBosch committed Feb 16, 2015
1 parent f182f74 commit d625bec
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions niprov/jsonfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from niprov.filesystem import Filesystem
from jsonserializing import JsonSerializer
import os


class JsonFile(object):
Expand All @@ -9,6 +10,7 @@ class JsonFile(object):
def __init__(self, filesys=Filesystem(), json=JsonSerializer()):
self.filesys = filesys
self.json = json
self.datafile = os.path.expanduser(os.path.join('~','provenance.json'))

def add(self, record):
"""Add the provenance for one file to storage.
Expand All @@ -19,7 +21,7 @@ def add(self, record):
current = self.all()
current.append(record)
jsonstr = self.json.serializeList(current)
with open('provenance.json', 'w') as fp:
with open(self.datafile, 'w') as fp:
fp.write(jsonstr)

def all(self):
Expand All @@ -29,7 +31,7 @@ def all(self):
list: List of provenance for known files.
"""
try:
jsonstr = self.filesys.read('provenance.json')
jsonstr = self.filesys.read(self.datafile)
except IOError:
return []
return self.json.deserializeList(jsonstr)
Expand Down

0 comments on commit d625bec

Please sign in to comment.