From: karim hamidou Date: Thu, 12 Jul 2012 08:17:46 +0000 (+0200) Subject: added creation and deletion of files X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=beda7c86c4b41b01cfc3eea9ce70b475c1a50b94;p=cagibi.git added creation and deletion of files --- diff --git a/cagibi/server.py b/cagibi/server.py index d04fc81..354ecc6 100644 --- a/cagibi/server.py +++ b/cagibi/server.py @@ -1,6 +1,7 @@ -from bottle import Bottle, route, run +from bottle import Bottle, route, run, post, request, abort import os, time import json +from config import load_config, save_config cagibi_folder = "." files_info = {} @@ -34,7 +35,23 @@ def create_file(): save_config(files_info, filename="files.json") return "Ok." else: - abort(500, "File already exists") + abort(501, "File already exists") + +@post('/delete/') +def delete_file(filename): + """Remove a file""" + filename = os.path.basename(filename) + print filename + + # FIXME: possible race condition + if os.path.exists(filename) and filename in files_info: + os.remove(filename) + del files_info[filename] + save_config(files_info, filename="files.json") + return "Ok." + else: + abort(501, "File doesn't exist or is not in database.") + @post('/update/') def update_filename(filename):