refs #1326 add ogDeleteTree()

pull/1/head
Natalia Serrano 2025-01-10 13:35:32 +01:00
parent a68556e8c9
commit c4c53d6679
2 changed files with 32 additions and 26 deletions

View File

@ -261,30 +261,41 @@ def ogDeleteFile (disk=None, par=None, container=None, file=None):
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_GENERIC, str (e))
return
def ogDeleteTree(*args):
# Variables locales.
DIR = None
if "help" in args:
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_dir", "$FUNCNAME 1 2 /tmp/newdir")
#/**
# ogDeleteTree [ str_repo | int_ndisk int_npartition ] path_dirpath
#@brief Metafunción que borra todo un subárbol de directorios de un dispositivo.
#@see ogGetPath
#*/ ##
#ogDeleteTree (container='REPO', file='/tmp/newdir')
#ogDeleteTree (disk=1, par=2, file='/tmp/newdir')
def ogDeleteTree (disk=None, par=None, container=None, file=None):
if file is None:
raise TypeError ('missing required argument: "file"')
if container is not None:
if disk is None and par is None:
## we were given container=
src = container
else:
raise TypeError ('argument "container" can be specified along neither "disk" nor "par"')
else:
if disk is not None and par is not None:
## we were given disk= par=
src = f'{disk} {par}'
else:
## we were given nothing
raise TypeError ('either "container" or both "disk" and "par" must be specified')
f = ogGetPath (src=src, file=file)
if not f:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'{src} {file}')
return
# Comprobar que existe el directorio y borrarlo con su contenido.
DIR = ogGetPath(*args)
if not DIR:
SystemLib.ogRaiseError(
"session",
ogGlobals.OG_ERR_NOTFOUND,
f"Not found: {args}"
)
return
try:
shutil.rmtree(DIR)
shutil.rmtree (f)
except OSError as e:
SystemLib.ogRaiseError(
"session",
ogGlobals.OG_ERR_NOTFOUND,
f"{e}"
)
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, e)
return

View File

@ -654,12 +654,7 @@ def ogMountFs (disk, par):
if mntdir: return mntdir
if ogIsLocked (disk, par):
print (f'nati: ogMountFs: is locked disk ({disk}) par ({par})')
SystemLib.ogRaiseError (
[],
ogGlobals.OG_ERR_LOCKED,
f"{ogGlobals.lang.MSG_PARTITION}, {disk} {par}"
)
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_LOCKED, f'{ogGlobals.lang.MSG_PARTITION}, {disk} {par}')
return
# El camino de un dispositivo normal comienza por el carácter "/".