refs #1101 add ogMcastReceiverFile()

code-review
Natalia Serrano 2024-11-12 20:11:23 +01:00
parent bddbf6fa57
commit cb0c2b259d
1 changed files with 59 additions and 6 deletions

View File

@ -3,6 +3,7 @@
import subprocess
import re
import json
import os.path
import ogGlobals
import SystemLib
@ -368,10 +369,10 @@ def ogMcastSyntax (op, sess, file=None, device=None, tool=None, level=None):
#
#ogMcastSendFile [str_REPOSITORY] [int_ndisk int_npart] /Relative_path_file sesionMcast" \
#ogMcastSendFile (disk=1, par=1, file='/aula1/winxp.img', sess='sesionMcast')
#ogMcastSendFile (from='REPO', file='/aula1/ubuntu.iso', sess='sesionMcast')
#ogMcastSendFile (from='CACHE', file='/aula1/winxp.img', sess='sesionMcast')
#ogMcastSendFile ( file='/opt/opengnsys/images/aula1/hd500.vmx', sess='sesionMcast')
#ogMcastSendFile (disk=1, par=1, file='/aula1/winxp.img', sess='sesionMcast')
#ogMcastSendFile (take_from='REPO', file='/aula1/ubuntu.iso', sess='sesionMcast')
#ogMcastSendFile (take_from='CACHE', file='/aula1/winxp.img', sess='sesionMcast')
#ogMcastSendFile ( file='/opt/opengnsys/images/aula1/hd500.vmx', sess='sesionMcast')
def ogMcastSendFile (disk=None, par=None, take_from=None, file=None, sess=None):
if file is None:
raise TypeError ('missing required argument: "file"')
@ -382,7 +383,7 @@ def ogMcastSendFile (disk=None, par=None, take_from=None, file=None, sess=None):
if disk is None and par is None:
## we were given take_from=
source = FileLib.ogGetPath (src=take_from, file=file)
dev_err = ' '.join ([take_from, file])
dev_err = f'{take_from} {file}'
print (f'ogGetPath (src=({take_from}), file=({file})) = source ({source})')
else:
raise TypeError ('argument "take_from" can be specified along neither "disk" nor "par"')
@ -391,7 +392,7 @@ def ogMcastSendFile (disk=None, par=None, take_from=None, file=None, sess=None):
if disk is not None and par is not None:
## we were given disk= par=
source = FileLib.ogGetPath (src=f'{disk} {par}', file=file)
dev_err = ' '.join ([disk, par, file])
dev_err = f'{disk} {par} {file}'
print (f'ogGetPath (src=({disk} {par}), file=({file})) = source ({source})')
elif disk is None and par is None:
## we were given nothing
@ -401,6 +402,10 @@ def ogMcastSendFile (disk=None, par=None, take_from=None, file=None, sess=None):
else:
raise TypeError ('if one of "disk" and "par" are specified, then both must be')
if not source:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or file {dev_err} not found')
return
path2 = FileLib.ogGetPath (file=source)
print (f'path2 ({path2})')
if not path2:
@ -431,6 +436,54 @@ def ogMcastSendFile (disk=None, par=None, take_from=None, file=None, sess=None):
#*/ ##
#
#ogMcastReceiverFile ([ str_portMcast] [ [Relative_path_file] | [str_REPOSITORY path_file] | [int_ndisk int_npart path_file ] ]" \
#ogMcastReceiverFile ( file='/PS1_PH1.img', sess='9000')
#ogMcastReceiverFile (write_to='CACHE', file='/aula1/PS2_PH4.img', sess='9000')
#ogMcastReceiverFile (disk=1, par=1, file='/isos/linux.iso', sess='9000')
def ogMcastReceiverFile (disk=None, par=None, write_to=None, file=None, sess=None):
if file is None:
raise TypeError ('missing required argument: "file"')
if sess is None:
raise TypeError ('missing required argument: "sess"')
if write_to is not None:
if disk is None and par is None:
## we were given write_to=
targetdir = FileLib.ogGetParentPath (src=write_to, file=file)
dev_err = f'{write_to} {file}'
print (f'ogGetParentPath (src=({write_to}), file=({file})) = targetdir ({targetdir})')
else:
raise TypeError ('argument "write_to" can be specified along neither "disk" nor "par"')
else:
if disk is not None and par is not None:
## we were given disk= par=
targetdir = FileLib.ogGetParentPath (src=f'{disk} {par}', file=file)
dev_err = f'{disk} {par} {file}'
print (f'ogGetParentPath (src=({disk} {par}), file=({file})) = targetdir ({targetdir})')
elif disk is None and par is None:
## we were given nothing
targetdir = FileLib.ogGetParentPath (file=file)
dev_err = file
print (f'ogGetParentPath (file=({file})) = targetdir ({targetdir})')
else:
raise TypeError ('if one of "disk" and "par" are specified, then both must be')
if not targetdir:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'target directory {targetdir} not found')
return
targetfile = os.path.basename (file)
print (f'targetfile ({targetfile})')
cmd = ogMcastSyntax ('RECEIVERFILE', sess, file=os.path.join (targetdir, targetfile))
if not cmd: return None
print (f'cmd ({cmd})')
try:
subprocess.run (cmd, shell=True, check=True)
except subprocess.CalledProcessError:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_MCASTRECEIVERFILE, targetfile)
return None
#/**