add audit_data
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
package : comi-apps-to-update-on-wapt-server
|
package : comi-apps-to-update-on-wapt-server
|
||||||
version : 0-10
|
version : 0-13
|
||||||
architecture : all
|
architecture : all
|
||||||
section : base
|
section : base
|
||||||
priority : optional
|
priority : optional
|
||||||
|
|||||||
122
all/setup.py
122
all/setup.py
@@ -3,6 +3,46 @@ from setuphelpers import *
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
from waptpackage import HostCapabilities
|
||||||
|
from waptpackage import WaptRemoteRepo
|
||||||
|
from waptpackage import PackageVersion
|
||||||
|
|
||||||
|
all_package = {}
|
||||||
|
|
||||||
|
dict_host_capa = {
|
||||||
|
"ubuntu22frx64": HostCapabilities(
|
||||||
|
architecture="x64",
|
||||||
|
language="fr",
|
||||||
|
os="ubuntu",
|
||||||
|
packages_locales=["fr", "en", "es", "de", "it"],
|
||||||
|
tags=["debian", "debian_based", "linux", "unix", "debian11", "ubuntu-22"],
|
||||||
|
os_version="11",
|
||||||
|
),
|
||||||
|
"ubuntu20frx64": HostCapabilities(
|
||||||
|
architecture="x64",
|
||||||
|
language="fr",
|
||||||
|
os="ubuntu",
|
||||||
|
packages_locales=["fr", "en", "es", "de", "it"],
|
||||||
|
tags=["debian", "debian_based", "linux", "unix", "debian11", "ubuntu-20"],
|
||||||
|
os_version="11",
|
||||||
|
),
|
||||||
|
"debian11frx64": HostCapabilities(
|
||||||
|
architecture="x64",
|
||||||
|
language="fr",
|
||||||
|
os="debian",
|
||||||
|
packages_locales=["fr", "en", "es", "de", "it"],
|
||||||
|
tags=["debian-bullseye", "debian", "debian_based", "linux", "unix", "debian11", "debian-11"],
|
||||||
|
os_version="11",
|
||||||
|
),
|
||||||
|
"win10x64fr": HostCapabilities(
|
||||||
|
architecture="x64",
|
||||||
|
language="fr",
|
||||||
|
os="windows",
|
||||||
|
packages_locales=["fr", "en", "es", "de", "it"],
|
||||||
|
tags=["windows-10", "win-10", "w-10", "windows10", "win10", "w10", "windows", "win", "w"],
|
||||||
|
os_version="10.0.19043",
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def install():
|
def install():
|
||||||
@@ -25,45 +65,55 @@ def audit():
|
|||||||
print("suppression de l'ancienne version du fichier json")
|
print("suppression de l'ancienne version du fichier json")
|
||||||
remove_file(app_to_update_json_path)
|
remove_file(app_to_update_json_path)
|
||||||
|
|
||||||
|
store = WaptRemoteRepo(name="main", url="https://wapt.tranquil.it/wapt", timeout=4, verify_cert=False)
|
||||||
|
localstore = WaptRemoteRepo(name="main", url="https://srvwapt.comitari.fr/wapt", timeout=4, verify_cert=False)
|
||||||
# Download JSON data from the URL
|
# Download JSON data from the URL
|
||||||
json_data = download_json_from_url("https://wapt.tranquil.it/store/packages_list")
|
online_package_list = {}
|
||||||
if json_data is None:
|
local_package_list = {}
|
||||||
return "ERROR"
|
for hc in dict_host_capa:
|
||||||
online_dict = {}
|
online_package_version = {}
|
||||||
transformed_package_dict = {}
|
for packageentry in store.packages():
|
||||||
app_to_update_list = []
|
if dict_host_capa[hc].is_matching_package(packageentry):
|
||||||
|
if not packageentry.package in online_package_version:
|
||||||
|
online_package_version[packageentry.package] = "0"
|
||||||
|
if PackageVersion(online_package_version[packageentry.package]) < PackageVersion(packageentry.version):
|
||||||
|
online_package_version[packageentry.package] = packageentry.version
|
||||||
|
online_package_list[hc] = online_package_version
|
||||||
|
|
||||||
# Transform data from JSON into a dictionary
|
for hc in dict_host_capa:
|
||||||
for element in json_data:
|
local_package_version = {}
|
||||||
online_dict[element[0].replace("tis-", "comi-")] = element[1]
|
for packageentry in localstore.packages():
|
||||||
|
if dict_host_capa[hc].is_matching_package(packageentry):
|
||||||
|
if not packageentry.package in local_package_version:
|
||||||
|
local_package_version[packageentry.package] = "0"
|
||||||
|
if PackageVersion(local_package_version[packageentry.package]) < PackageVersion(packageentry.version):
|
||||||
|
local_package_version[packageentry.package] = packageentry.version
|
||||||
|
local_package_list[hc] = local_package_version
|
||||||
|
|
||||||
# Assuming WAPT.list() returns a list of dictionaries containing package data
|
list_app_to_update = []
|
||||||
local_package_dict = json.loads(wgets("https://%s:%s@%s/api/v3/packages" % (wapt_user, wapt_password, wapt_url)))
|
for hc in dict_host_capa:
|
||||||
# count the number of packages in the WAPT repository
|
for app in local_package_list[hc]:
|
||||||
print("Nombre de paquets dans le dépôt WAPT : " + str(len(local_package_dict)))
|
if "-" in app:
|
||||||
|
if "tis-" + app.split("-", 1)[1] in online_package_list[hc]:
|
||||||
# Transform package data into a dictionary
|
if PackageVersion(local_package_list[hc][app]) < PackageVersion(online_package_list[hc]["tis-" + app.split("-", 1)[1]]):
|
||||||
for element in local_package_dict["result"]:
|
print(
|
||||||
transformed_package_dict[element["package"]] = element["version"]
|
f'{app} new version detected from {local_package_list[hc][app]} to {online_package_list[hc]["tis-"+app.split("-", 1)[1]]} for {hc}'
|
||||||
|
)
|
||||||
# Compare versions and find packages that need to be updated
|
list_app_to_update.append(
|
||||||
for key in online_dict:
|
{
|
||||||
if key in transformed_package_dict:
|
"package": app,
|
||||||
if Version(online_dict[key]) > Version(transformed_package_dict[key]):
|
"old_version": local_package_list[hc][app],
|
||||||
print(f"{key} doit etre mis a jour de la version {transformed_package_dict[key]} vers la version {online_dict[key]}")
|
"new_version": online_package_list[hc]["tis-" + app.split("-", 1)[1]],
|
||||||
app_to_update_list.append({"new_package": key, "new_version": online_dict[key], "old_version": transformed_package_dict[key]})
|
}
|
||||||
|
)
|
||||||
|
WAPT.write_audit_data_if_changed("apps_to_upgrade", "list", list_app_to_update, max_count=3)
|
||||||
|
|
||||||
with open(app_to_update_json_path, "w") as json_file:
|
with open(app_to_update_json_path, "w") as json_file:
|
||||||
json.dump(app_to_update_list, json_file)
|
json.dump(list_app_to_update, json_file)
|
||||||
|
|
||||||
|
if not list_app_to_update:
|
||||||
|
print("your repository seems up to date")
|
||||||
return "OK"
|
return "OK"
|
||||||
|
else:
|
||||||
|
print("you need to update some packages")
|
||||||
def download_json_from_url(url):
|
return "WARNING"
|
||||||
try:
|
|
||||||
response = requests.get(url, verify=False)
|
|
||||||
response.raise_for_status() # Raise an exception for unsuccessful responses
|
|
||||||
json_data = response.json()
|
|
||||||
return json_data
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
print(f"Error downloading JSON from URL: {e}")
|
|
||||||
return None
|
|
||||||
|
|||||||
Reference in New Issue
Block a user