From fe2d8789c1b1ba6fab743ea7ff9d16c4306e46e3 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Fri, 15 Jul 2011 16:44:46 +0800 Subject: begin to write segment.py --- lib/utils.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/utils.py') diff --git a/lib/utils.py b/lib/utils.py index b2e6f10..156fbaf 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -1,3 +1,4 @@ +import os import json #Utils @@ -17,8 +18,18 @@ def write_file(outfile, data): #JSON Load/Store def load_status(infile): - return json.loads(read_file(infile)) + data = '{}' + if os.access(infile, os.R_OK): + data = read_file(infile) + + return json.loads(data) def store_status(outfile, obj): write_file(outfile, json.dumps(obj)) return + +#test case +if __name__ == '__main__': + obj = load_status('/tmp/test.status') + print(obj) + store_status('/tmp/test.status', obj) -- cgit