refs #1326 add ogDeleteTree()
parent
a68556e8c9
commit
c4c53d6679
|
@ -261,30 +261,41 @@ def ogDeleteFile (disk=None, par=None, container=None, file=None):
|
||||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_GENERIC, str (e))
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_GENERIC, str (e))
|
||||||
return
|
return
|
||||||
|
|
||||||
def ogDeleteTree(*args):
|
|
||||||
# Variables locales.
|
#/**
|
||||||
DIR = None
|
# ogDeleteTree [ str_repo | int_ndisk int_npartition ] path_dirpath
|
||||||
if "help" in args:
|
#@brief Metafunción que borra todo un subárbol de directorios de un dispositivo.
|
||||||
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_dir", "$FUNCNAME 1 2 /tmp/newdir")
|
#@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
|
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:
|
try:
|
||||||
shutil.rmtree(DIR)
|
shutil.rmtree (f)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
SystemLib.ogRaiseError(
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, e)
|
||||||
"session",
|
|
||||||
ogGlobals.OG_ERR_NOTFOUND,
|
|
||||||
f"{e}"
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -654,12 +654,7 @@ def ogMountFs (disk, par):
|
||||||
if mntdir: return mntdir
|
if mntdir: return mntdir
|
||||||
|
|
||||||
if ogIsLocked (disk, par):
|
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
|
return
|
||||||
|
|
||||||
# El camino de un dispositivo normal comienza por el carácter "/".
|
# El camino de un dispositivo normal comienza por el carácter "/".
|
||||||
|
|
Loading…
Reference in New Issue