New API: check_version
This commit is contained in:
parent
e288b4c80d
commit
ebebf33558
@ -20,6 +20,63 @@ DEBUG = False # if false, don't publish error messages
|
|||||||
|
|
||||||
# Les paquets publiés:
|
# Les paquets publiés:
|
||||||
DEBIAN_PACKAGES_EXP = "/srv/packages/pool/main/s/scodoc9/scodoc9_*.deb"
|
DEBIAN_PACKAGES_EXP = "/srv/packages/pool/main/s/scodoc9/scodoc9_*.deb"
|
||||||
|
RELEASE_LOG_FILE = "/home/viennet/scodoc-releases.log"
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/scodoc-installmgr/check_version/<client_version>")
|
||||||
|
def check_version(client_version: str):
|
||||||
|
"""check version vs release
|
||||||
|
return json
|
||||||
|
{
|
||||||
|
"status": "ok",
|
||||||
|
"client_version" : "9.1.81", // la version du client
|
||||||
|
"client_version_date" : int // timestamp version
|
||||||
|
"last_version" : "9.1.82" // derniere version dispo
|
||||||
|
"last_version_date": int // timestamp derniere version
|
||||||
|
}
|
||||||
|
Le client devrait se plaindre de manque de mise à jour si
|
||||||
|
(client_version != last_version) et (now - last_version_date) > 1 jour
|
||||||
|
|
||||||
|
Si la version du client n'est pas trouvée dans RELEASE_LOG_FILE
|
||||||
|
renvoie client_version et client_version_date nulls.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
with open(RELEASE_LOG_FILE) as f:
|
||||||
|
data = [l.strip().split() for l in f]
|
||||||
|
except FileNotFoundError:
|
||||||
|
return jsonify({"status": "error 1"})
|
||||||
|
if len(data) < 1:
|
||||||
|
return jsonify({"status": "error 2"})
|
||||||
|
release_date = {k: v for v, k in data} # version : date
|
||||||
|
last_version = data[-1][1]
|
||||||
|
last_version_date_str = data[-1][0]
|
||||||
|
try:
|
||||||
|
dt = datetime.datetime.strptime(last_version_date_str, "%Y-%m-%dT%H:%M:%S%z")
|
||||||
|
except ValueError:
|
||||||
|
return jsonify({"status": "error 3"})
|
||||||
|
last_version_date = dt.timestamp()
|
||||||
|
#
|
||||||
|
client_version_date_str = release_date.get(client_version, None)
|
||||||
|
if client_version_date_str is None:
|
||||||
|
client_version = None # not found ? (client altered version ?)
|
||||||
|
client_version_date = None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
dt = datetime.datetime.strptime(
|
||||||
|
client_version_date_str, "%Y-%m-%dT%H:%M:%S%z"
|
||||||
|
)
|
||||||
|
client_version_date = dt.timestamp()
|
||||||
|
except ValueError:
|
||||||
|
return jsonify({"status": "error 4"})
|
||||||
|
return jsonify(
|
||||||
|
{
|
||||||
|
"status": "ok",
|
||||||
|
"client_version": client_version,
|
||||||
|
"client_version_date": client_version_date,
|
||||||
|
"last_version": last_version,
|
||||||
|
"last_version_date": last_version_date,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/scodoc-installmgr/last_stable_version")
|
@bp.route("/scodoc-installmgr/last_stable_version")
|
||||||
@ -42,14 +99,14 @@ def last_stable_version():
|
|||||||
last_package_filename = version_tuples[-1][-1]
|
last_package_filename = version_tuples[-1][-1]
|
||||||
package_mtime = os.path.getmtime(last_package_filename)
|
package_mtime = os.path.getmtime(last_package_filename)
|
||||||
package_version_string = ".".join([str(x) for x in last_package_version])
|
package_version_string = ".".join([str(x) for x in last_package_version])
|
||||||
return jsonify( {
|
return jsonify(
|
||||||
|
{
|
||||||
"publication_time": package_mtime, # float, time
|
"publication_time": package_mtime, # float, time
|
||||||
"version": package_version_string,
|
"version": package_version_string,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/scodoc-installmgr/upload-dump", methods=["POST"])
|
@bp.route("/scodoc-installmgr/upload-dump", methods=["POST"])
|
||||||
def upload_scodoc9():
|
def upload_scodoc9():
|
||||||
"""Réception d'un fichier de dump"""
|
"""Réception d'un fichier de dump"""
|
||||||
|
Loading…
Reference in New Issue
Block a user