Add a /clean
route
Add a route to clean temporary downloaded files (actually deletes all temporary folders created by cozyweboob).
This commit is contained in:
parent
5faf0eec15
commit
c793e56769
@ -54,6 +54,11 @@ It exposes a couple of routes:
|
||||
|
||||
* the `/retrieve` route, which supports `POST` method and a single `path` `POST`
|
||||
parameter which is the path to the previously downloaded file to retrieve.
|
||||
Note that this route will not delete the temporary file whose content has
|
||||
been retrieved, and you should delete it manually.
|
||||
|
||||
* the `/clean` route, which will delete all temporary downloaded files. This
|
||||
route will return a JSON list of deleted folders.
|
||||
|
||||
**IMPORTANT:** Note this small webserver is **not** production ready and only
|
||||
here as a proof of concept and to be used in a controlled development
|
||||
|
24
server.py
24
server.py
@ -4,6 +4,7 @@ HTTP server wrapper around weboob
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from bottle import post, request, route, run, static_file
|
||||
@ -40,6 +41,29 @@ def retrieve_view():
|
||||
download=True)
|
||||
|
||||
|
||||
@route("/clean")
|
||||
def clean_view():
|
||||
"""
|
||||
Delete all the temporary downloaded files. These are the
|
||||
"cozyweboob-*-tmp" folders in your system tmp dir.
|
||||
"""
|
||||
sys_tmp_dir = tempfile.gettempdir()
|
||||
tmp_dirs = [
|
||||
x
|
||||
for x in os.listdir(sys_tmp_dir)
|
||||
if os.path.isdir(os.path.join(sys_tmp_dir, x))
|
||||
]
|
||||
removed_dirs = []
|
||||
for tmp_dir in tmp_dirs:
|
||||
if tmp_dir.startswith("cozyweboob-") and tmp_dir.endswith("-tmp"):
|
||||
tmp_dir = os.path.join(sys_tmp_dir, tmp_dir)
|
||||
removed_dirs.append(tmp_dir)
|
||||
shutil.rmtree(tmp_dir)
|
||||
return {
|
||||
"removed_dirs": removed_dirs
|
||||
}
|
||||
|
||||
|
||||
@route("/list")
|
||||
def list_view():
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user