refs #1329 add ogGetSizeParameters
parent
4062777183
commit
e266bf07c9
|
@ -12,6 +12,7 @@ import FileSystemLib
|
|||
import SystemLib
|
||||
import ogGlobals
|
||||
import FileLib
|
||||
import CacheLib
|
||||
|
||||
## ProtocolLib.ogUcastSyntax() calls ogCreateImageSyntax()
|
||||
## in ogCreateImageSyntax(), param2 may contain a pipe or may be empty
|
||||
|
@ -257,6 +258,73 @@ def ogRestoreImageSyntax (imgfile, part, tool=None, level=None):
|
|||
#@note para el tamaño de la imagen no sigue enlaces simbólicos.
|
||||
#@exception OG_ERR_FORMAT formato incorrecto.
|
||||
#*/ ##
|
||||
#SIZEDATA, SIZEREQUIRED, SIZEFREE, ISENOUGHSPACE = ogGetSizeParameters (1, 1, 'REPO', 'myimg')
|
||||
def ogGetSizeParameters (disk, par, repo, imgname, imgtype=None):
|
||||
repo = repo.upper()
|
||||
## imgtype se soporta como parametro pero se ignora
|
||||
|
||||
mntdir = FileSystemLib.ogMount (disk, par)
|
||||
if not mntdir:
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f'{disk} {par}')
|
||||
return None
|
||||
|
||||
#if [ "$IMGTYPE" == "_DIFF_" ]; then cosas
|
||||
#else:
|
||||
sizedata = None
|
||||
df_out = subprocess.run (['df', '-k'], capture_output=True, text=True).stdout
|
||||
for l in df_out.splitlines():
|
||||
if (re.search (f'{mntdir}$', l)):
|
||||
sizedata = int (l.split()[2])
|
||||
break
|
||||
if sizedata is None:
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_GENERIC, 'sizedata is None')
|
||||
return None
|
||||
|
||||
#if [ "$IMGTYPE" == "_SYNC_" -o "$IMGTYPE" == "_DIFF_" ]; then cosas
|
||||
#else:
|
||||
factorgzip=55/100
|
||||
factorlzop=65/100
|
||||
sizerequired = sizedata * factorlzop
|
||||
|
||||
#Comprobar espacio libre en el contenedor.
|
||||
sizefree = None
|
||||
if 'CACHE' == repo:
|
||||
cache_disk, cache_par = CacheLib.ogFindCache().split()
|
||||
sizefree = FileSystemLib.ogGetFreeSize (cache_disk, cache_par)
|
||||
if 'REPO' == repo:
|
||||
df_out = subprocess.run (['df', '-k'], capture_output=True, text=True).stdout
|
||||
for l in df_out.splitlines():
|
||||
if (re.search (f'{ogGlobals.OGIMG}', l)):
|
||||
sizefree = int (l.split()[3])
|
||||
break
|
||||
if sizefree is None:
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_GENERIC, 'sizefree is None')
|
||||
return None
|
||||
|
||||
# Comprobamos si existe una imagen con el mismo nombre en $REPO
|
||||
# En sincronizadas restamos tamaño de la imagen y en monoloticas de la .ant
|
||||
#case "${IMGTYPE}" in blah blah
|
||||
#*)
|
||||
imgext = 'img.ant'
|
||||
|
||||
imgdir = FileLib.ogGetParentPath (src=repo, file=f'/{imgname}')
|
||||
bn = os.path.basename (f'/{imgname}')
|
||||
imgfile = FileLib.ogGetPath (file=f'{imgdir}/{bn}.{imgext}')
|
||||
|
||||
if not imgfile:
|
||||
imgsize = 0
|
||||
else:
|
||||
ls_out = subprocess.run (['ls', '-s', imgfile], capture_output=True, text=True).stdout
|
||||
imgsize = int (ls_out.split()[0])
|
||||
|
||||
sizefree = sizefree + imgsize
|
||||
|
||||
if sizerequired < sizefree:
|
||||
isenoughspace = True
|
||||
else:
|
||||
isenoughspace = False
|
||||
|
||||
return sizedata, sizerequired, sizefree, isenoughspace
|
||||
|
||||
#/**
|
||||
# ogIsImageLocked [str_repo] path_image
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
from SystemLib import ogHelp
|
||||
from ImageLib import ogGetSizeParameters
|
||||
|
||||
parser = argparse.ArgumentParser (add_help=False)
|
||||
parser.add_argument ('disk')
|
||||
parser.add_argument ('par')
|
||||
parser.add_argument ('container')
|
||||
parser.add_argument ('imgname')
|
||||
|
||||
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||
ogHelp ('ogGetSizeParameters', 'ogGetSizeParameters num_disk num_part str_repo path_imgname', ['read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters 1 2 REPO Windows10)', 'read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters 1 6 CACHE Ubuntu16'])
|
||||
sys.exit (0)
|
||||
|
||||
args = parser.parse_args()
|
||||
sizedata, sizerequired, sizefree, isenoughspace = ogGetSizeParameters (args.disk, args.par, args.container, args.imgname)
|
||||
print (' '.join ([str(sizedata), str(sizerequired), str(sizefree), str(isenoughspace)]))
|
Loading…
Reference in New Issue