|
@@ -11,13 +11,27 @@ def resp(app, data=None, code=200, headers=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_history(history, target='/opt/stackbrew/history.json'):
|
|
def save_history(history, target='/opt/stackbrew/history.json'):
|
|
|
- with open(target, 'w') as f:
|
|
|
|
|
- f.write(json.dumps(history))
|
|
|
|
|
|
|
+ save = []
|
|
|
|
|
+ for k in history.iterkeys():
|
|
|
|
|
+ url, ref, dfile = k # unpack
|
|
|
|
|
+ save.append({
|
|
|
|
|
+ 'url': url,
|
|
|
|
|
+ 'ref': ref,
|
|
|
|
|
+ 'dfile': dfile,
|
|
|
|
|
+ 'img': history[k]
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ with open(target, 'w') as f:
|
|
|
|
|
+ f.write(json.dumps(save))
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_history(target='/opt/stackbrew/history.json'):
|
|
def load_history(target='/opt/stackbrew/history.json'):
|
|
|
- try:
|
|
|
|
|
- with open(target, 'r') as f:
|
|
|
|
|
- return json.loads(f.read())
|
|
|
|
|
- except IOError:
|
|
|
|
|
- return {}
|
|
|
|
|
|
|
+ history = {}
|
|
|
|
|
+ try:
|
|
|
|
|
+ with open(target, 'r') as f:
|
|
|
|
|
+ savefile = json.loads(f.read())
|
|
|
|
|
+ for item in savefile:
|
|
|
|
|
+ history[(item['url'], item['ref'], item['dfile'])] = item['img']
|
|
|
|
|
+ return history
|
|
|
|
|
+ except IOError:
|
|
|
|
|
+ return {}
|