Example #1
0
 def loader():
     if os.path.exists(file_name):
         inp = file(file_name)
         data = json.load(inp)
         inp.close()
         return {name: data}
     else:
         return {}
Example #2
0
 def loader():
     if os.path.exists(file_name):
         inp = file(file_name)
         batch = json.load(inp)
         inp.close()
         return batch
     else:
         return {}
Example #3
0
def change_batch(change, file_name):
    if os.path.exists(file_name):
        # read in old data
        try:
            inp = file(file_name)
            batch = json.load(inp)
            inp.close()
        except:
            warn("Couldn't load old data")
            batch = {}
    else:
        batch = {}

    # apply changes
    change(batch)

    # writing back
    out = file(file_name, 'w')
    json.dump(batch, out)
    out.close()
Example #4
0
def load_batch(file_name):
    inp = file(file_name)
    data = json.load(inp)
    inp.close()
    return data