Selaa lähdekoodia

Save history to a JSON file (so restarting the app doesn't lose us the image cache)

Joffrey F 11 vuotta sitten
vanhempi
sitoutus
337146f224
2 muutettua tiedostoa jossa 15 lisäystä ja 1 poistoa
  1. 2 1
      stackbrew/app.py
  2. 13 0
      stackbrew/lib/utils.py

+ 2 - 1
stackbrew/app.py

@@ -13,7 +13,7 @@ config = None
 with open('./config.json') as config_file:
     config = json.load(config_file)
 data = db.DbManager(config['db_url'], debug=config['debug'])
-history = {}
+history = utils.load_history()
 brew.logger = app.logger
 brew.set_loglevel('DEBUG' if config['debug'] else 'INFO')
 
@@ -60,6 +60,7 @@ def build_task():
     builder.build_repo_list()
     builder.history = history
     builder.build_all(callback=summary.handle_build_result)
+    utils.save_history()
     if config['push']:
         builder.push_all()
 

+ 13 - 0
stackbrew/lib/utils.py

@@ -8,3 +8,16 @@ def resp(app, data=None, code=200, headers=None):
         headers['Content-Type'] = 'application/json'
         data = json.dumps(data)
     return app.make_response((data, code, headers))
+
+
+def save_history(history, target='/opt/stackbrew/history.json'):
+	with open(target, 'w') as f:
+		f.write(json.dumps(history))
+
+
+def load_history(target='/opt/stackbrew/history.json'):
+	try:
+		with open(target, 'r') as f:
+			return json.loads(f.read())
+	except IOError:
+		return {}