New API: check_version
This commit is contained in:
parent
e288b4c80d
commit
ebebf33558
@ -19,7 +19,64 @@ UPLOAD_LOG_FILENAME = os.path.join(DIR, "upload-dump-log.json")
|
|||||||
DEBUG = False # if false, don't publish error messages
|
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")
|
||||||
@ -29,11 +86,11 @@ def last_stable_version():
|
|||||||
"""
|
"""
|
||||||
# LAST_RELEASE_TAG=$(curl "$GITEA_RELEASE_URL" | jq ".[].tag_name" | tr -d -c "0-9.\n" | sort --version-sort | tail -1)
|
# LAST_RELEASE_TAG=$(curl "$GITEA_RELEASE_URL" | jq ".[].tag_name" | tr -d -c "0-9.\n" | sort --version-sort | tail -1)
|
||||||
debs = glob.glob(DEBIAN_PACKAGES_EXP)
|
debs = glob.glob(DEBIAN_PACKAGES_EXP)
|
||||||
version_tuples = [] # (9,1,81)
|
version_tuples = [] # (9,1,81)
|
||||||
for filename in debs:
|
for filename in debs:
|
||||||
m = re.match(r".*scodoc9_9\.([0-9]{1,2})\.([0-9]{1,3})-1_amd64.deb", filename)
|
m = re.match(r".*scodoc9_9\.([0-9]{1,2})\.([0-9]{1,3})-1_amd64.deb", filename)
|
||||||
if m:
|
if m:
|
||||||
version_tuples.append( (9, int(m.group(1)), int(m.group(2)), filename) )
|
version_tuples.append((9, int(m.group(1)), int(m.group(2)), filename))
|
||||||
|
|
||||||
if len(version_tuples) == 0:
|
if len(version_tuples) == 0:
|
||||||
return "?.?.?"
|
return "?.?.?"
|
||||||
@ -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
|
{
|
||||||
"version" : package_version_string,
|
"publication_time": package_mtime, # float, time
|
||||||
|
"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"""
|
||||||
@ -83,8 +140,8 @@ def upload_scodoc9():
|
|||||||
"sco_subversion": request.form.get("sco_subversion", ""),
|
"sco_subversion": request.form.get("sco_subversion", ""),
|
||||||
"dump_filename": fulltime + "_" + clean_deptname + ".gz",
|
"dump_filename": fulltime + "_" + clean_deptname + ".gz",
|
||||||
"dump_size": len(data),
|
"dump_size": len(data),
|
||||||
"message" : request.form.get("message", ""),
|
"message": request.form.get("message", ""),
|
||||||
"request_url" : request.form.get("request_url", ""),
|
"request_url": request.form.get("request_url", ""),
|
||||||
"remote_addr": remote_addr,
|
"remote_addr": remote_addr,
|
||||||
"remote_host": remote_host,
|
"remote_host": remote_host,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user