This commit is contained in:
Cayo Puigdefabregas 2024-11-15 10:45:26 +01:00
parent eac898964f
commit ea8bf99f28

View file

@ -28,22 +28,6 @@ SNAPSHOT_BASE = {
} }
## Legacy Functions ##
def convert_to_legacy_snapshot(snapshot):
snapshot["sid"] = str(uuid.uuid4()).split("-")[1]
snapshot["software"] = "workbench-script"
snapshot["version"] = "dev"
snapshot["schema_api"] = "1.0.0"
snapshot["settings_version"] = "No Settings Version (NaN)"
snapshot["timestamp"] = snapshot["timestamp"].replace(" ", "T")
snapshot["data"]["smart"] = snapshot["data"]["disks"]
snapshot["data"].pop("disks")
snapshot.pop("erase")
snapshot.pop("token_hash")
## End Legacy Functions ##
## Utility Functions ## ## Utility Functions ##
def logs(f): def logs(f):
@ -71,6 +55,34 @@ def exec_cmd_erase(cmd):
## End Utility functions ## ## End Utility functions ##
## Legacy Functions ##
def convert_to_legacy_snapshot(snapshot):
snapshot["sid"] = str(uuid.uuid4()).split("-")[1]
snapshot["software"] = "workbench-script"
snapshot["version"] = "dev"
snapshot["schema_api"] = "1.0.0"
snapshot["settings_version"] = "No Settings Version (NaN)"
snapshot["timestamp"] = snapshot["timestamp"].replace(" ", "T")
snapshot["data"]["smart"] = snapshot["data"]["disks"]
snapshot["data"].pop("disks")
snapshot.pop("erase")
snapshot.pop("token_hash")
lshw = 'sudo lshw -xml'
hwinfo = 'sudo hwinfo --reallyall'
dmidecode = 'sudo dmidecode'
lspci = 'sudo lspci -vv'
data = {
'lshw': exec_cmd(lshw) or "{}",
'hwinfo': exec_cmd(hwinfo),
'lspci': exec_cmd(lspci)
}
snapshot['data'].update(data)
## End Legacy Functions ##
## Command Functions ## ## Command Functions ##
## Erase Functions ## ## Erase Functions ##
@ -241,37 +253,19 @@ def smartctl(all_disks, disk=None):
return data_list return data_list
@logs
def inxi():
filename = "hw.json"
command = 'sudo inxi'
options = '-a -x 3 -f -m -n --edid -G -E -M -A -B -D --output json --output-file'
cmd = f"{command} {options} {filename}"
exec_cmd(cmd)
with open(filename) ad f:
data = f.read()
rm = f"rm -f {filename}"
os.popen(rm).read()
return data
## End Command Functions ## ## End Command Functions ##
# TODO permitir selección # TODO permitir selección
# TODO permitir que vaya más rápido # TODO permitir que vaya más rápido
def get_data(all_disks): def get_data(all_disks):
lshw = 'sudo lshw -xml'
hwinfo = 'sudo hwinfo --reallyall'
dmidecode = 'sudo dmidecode' dmidecode = 'sudo dmidecode'
lspci = 'sudo lspci -vv' inxi = "sudo inxi -afmnGEMABD -x 3 --edid --output json --output-file print"
data = { data = {
'lshw': exec_cmd(lshw) or "{}",
'disks': smartctl(all_disks), 'disks': smartctl(all_disks),
'hwinfo': exec_cmd(hwinfo),
'dmidecode': exec_cmd(dmidecode), 'dmidecode': exec_cmd(dmidecode),
'lspci': exec_cmd(lspci) 'inxi': exec_cmd(inxi)
'inxi': exec_inxi()
} }
return data return data