Fix mujson_mgr.py crash when MUDB_FILE doesn't exist
This commit is contained in:
parent
84fd119f26
commit
490ae12128
1 changed files with 8 additions and 4 deletions
|
@ -16,15 +16,19 @@ class MuJsonLoader(object):
|
||||||
self.json = None
|
self.json = None
|
||||||
|
|
||||||
def load(self, path):
|
def load(self, path):
|
||||||
with open(path, 'rb+') as f:
|
l = "[]"
|
||||||
self.json = json.loads(f.read().decode('utf8'))
|
try:
|
||||||
|
with open(path, 'rb+') as f:
|
||||||
|
l = f.read().decode('utf8')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.json = json.loads(l)
|
||||||
|
|
||||||
def save(self, path):
|
def save(self, path):
|
||||||
if self.json:
|
if self.json:
|
||||||
output = json.dumps(self.json, sort_keys=True, indent=4, separators=(',', ': '))
|
output = json.dumps(self.json, sort_keys=True, indent=4, separators=(',', ': '))
|
||||||
with open(path, 'r+') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(output)
|
f.write(output)
|
||||||
f.truncate()
|
|
||||||
|
|
||||||
|
|
||||||
class MuMgr(object):
|
class MuMgr(object):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue