source: ogClient-Git/src/utils/fs.py @ 81ee4b0

Last change on this file since 81ee4b0 was 4e5b17c, checked in by Jose M. Guisado <jguisado@…>, 3 years ago

probe: detect 64 bit operating systems

OpenGnsys partition images store OS information, including
the OS name appended with "64 bits" when the OS is meant for 64 bit
machines.

The detected OS name when probing (refresh) is important, if it differs
from what's stored in the DB OpenGnsys will wipe last image restored
information when running a refresh.

See actualizaConfiguracion from legacy ogserver (ogAdmServer.c) code:

dato = dbi_result_get_uint(result, "idnombreso");
if (idsoi == dato) {

swu = false;

}
...
if (swu) {

result_update = dbi_conn_queryf(dbi->conn,
"UPDATE ordenadores_particiones SET "

" codpar=0x%s,"
" tamano=%s,"
" uso=%s,"
" idsistemafichero=%d,"
" idnombreso=%d,"
" idimagen=0,"
" idperfilsoft=0,"
" fechadespliegue=NULL"
" WHERE idordenador=%d AND numdisk=%s AND numpar=%s",

  • Property mode set to 100644
File size: 1.6 KB
Line 
1#
2# Copyright (C) 2022 Soleta Networks <info@soleta.eu>
3#
4# This program is free software: you can redistribute it and/or modify it under
5# the terms of the GNU Affero General Public License as published by the
6# Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
8
9import os
10import subprocess
11
12from subprocess import DEVNULL
13
14import psutil
15
16
17def find_mountpoint(path):
18    """
19    Returns mountpoint of a given path
20    """
21    path = os.path.abspath(path)
22    while not os.path.ismount(path):
23        path = os.path.dirname(path)
24    return path
25
26
27def mount_mkdir(source, target):
28    """
29    Mounts and creates the mountpoint directory if it's not present.
30    """
31    if not os.path.exists(target):
32        os.mkdir(target)
33    if not os.path.ismount(target):
34        return mount(source, target)
35    return False
36
37
38def mount(source, target):
39    """
40    Mounts source into target directoru using mount(8).
41
42    Return true if exit code is 0. False otherwise.
43    """
44    cmd = f'mount {source} {target}'
45    proc = subprocess.run(cmd.split(), stderr=DEVNULL)
46
47    return not proc.returncode
48
49
50def umount(target):
51    """
52    Umounts target using umount(8).
53
54    Return true if exit code is 0. False otherwise.
55    """
56    cmd = f'umount {target}'
57    proc = subprocess.run(cmd.split(), stderr=DEVNULL)
58
59    return not proc.returncode
60
61
62def get_usedperc(mountpoint):
63    """
64    Returns percetage of used filesystem as decimal number.
65    """
66    try:
67        total, used, free, perc = psutil.disk_usage(mountpoint)
68    except FileNotFoundError:
69        return '0'
70    return str(perc)
Note: See TracBrowser for help on using the repository browser.