91 lines
2.4 KiB
Python
91 lines
2.4 KiB
Python
import sys
|
|
import time
|
|
import subprocess
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
def main():
|
|
TIME1 = time.time()
|
|
PROG = sys.argv[0]
|
|
EXECFORMAT = f"{PROG} [int_ndisk [int_npart]] {{-1 | 0 | int_size}} [NOMOUNT]"
|
|
|
|
args = sys.argv[1:]
|
|
if args and args[-1].upper() == "NOMOUNT":
|
|
MOUNT = 0
|
|
args = args[:-1]
|
|
else:
|
|
MOUNT = 1
|
|
|
|
PARAMS = len(args)
|
|
if PARAMS == 1:
|
|
NDISK = 1
|
|
NPART = 4
|
|
SIZE = int(args[0])
|
|
elif PARAMS == 2:
|
|
NDISK = int(args[0])
|
|
NPART = 4
|
|
SIZE = int(args[1])
|
|
elif PARAMS == 3:
|
|
NDISK = int(args[0])
|
|
NPART = int(args[1])
|
|
SIZE = int(args[2])
|
|
else:
|
|
ogRaiseError("OG_ERR_FORMAT", f"{EXECFORMAT}")
|
|
|
|
if NDISK < 1 or NPART < 1:
|
|
ogRaiseError("OG_ERR_FORMAT", f"{EXECFORMAT}")
|
|
|
|
if SIZE < -1:
|
|
ogRaiseError("OG_ERR_FORMAT", f"{EXECFORMAT}")
|
|
|
|
if SIZE == 0:
|
|
print("No modificar la caché local.")
|
|
return
|
|
|
|
if SIZE == -1:
|
|
print("[10] Trabajar sin caché local.")
|
|
ogUnmountCache()
|
|
ogDeleteCache()
|
|
else:
|
|
current_cache = ogFindCache()
|
|
if current_cache and f"{NDISK} {NPART}" != current_cache:
|
|
print("[10] Detectada otra caché, eliminarla")
|
|
ogUnmountCache()
|
|
ogDeleteCache()
|
|
|
|
try:
|
|
OLDSIZE = ogGetCacheSize()
|
|
except ValueError:
|
|
OLDSIZE = 0
|
|
|
|
if SIZE <= 0:
|
|
ogRaiseError("OG_ERR_FORMAT", f"!({SIZE}>0)")
|
|
|
|
if SIZE != OLDSIZE:
|
|
print("[10] Crear partición de caché local.")
|
|
ogUnmountCache()
|
|
ogCreateCache(NDISK, NPART, SIZE)
|
|
ogUpdatePartitionTable(NDISK)
|
|
|
|
cache = ogFindCache()
|
|
if not ogIsFormated(cache) or SIZE != OLDSIZE:
|
|
print("[50] Formatear caché local.")
|
|
ogFormatCache()
|
|
|
|
print("[70] Comprobar montaje de caché local.")
|
|
if ogMountCache() != 0:
|
|
print("[80] Comprobar consistencia y volver a montar caché local.")
|
|
ogCheckFs(cache)
|
|
if ogMountCache() != 0:
|
|
sys.exit(1)
|
|
|
|
if MOUNT == 0:
|
|
print("[90] Dejar desmontada la caché local.")
|
|
ogUnmountCache()
|
|
|
|
TIME = time.time() - TIME1
|
|
print(f"[100] Duración de la operación {int(TIME // 60)}m {int(TIME % 60)}s")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|