Compare commits

..

24 Commits
0.19.2 ... main

Author SHA1 Message Date
Natalia Serrano aa5efb52a3 Merge pull request 'refs #2343 don't check call to updateBootCache' (#75) from update-boot-cache into main
ogclient/pipeline/head This commit looks good Details
ogclient/pipeline/tag This commit looks good Details
Reviewed-on: #75
2025-06-27 11:31:36 +02:00
Natalia Serrano a64968d57f refs #2343 don't check call to updateBootCache 2025-06-27 11:31:09 +02:00
Nicolas Arenas 84c7aa8e29 Merge branch 'update_torrent_clients'
ogclient/pipeline/head This commit looks good Details
2025-06-27 08:10:43 +02:00
Nicolas Arenas 2a92557bbc Updated Changelog 2025-06-27 08:07:33 +02:00
Nicolas Arenas b410403ea5 missing changes in last commit 2025-06-27 08:03:43 +02:00
Nicolas Arenas 5ea6489b41 missing changes in last commit 2025-06-27 07:46:16 +02:00
Nicolas Arenas 155f4b95b8 Merge pull request 'refs #2340: Replaces ctorrent with aria2c and mktorrent' (#73) from update_torrent_clients into main
ogclient/pipeline/head This commit looks good Details
Reviewed-on: #73
2025-06-27 07:02:53 +02:00
Nicolas Arenas 4ae16782ca updated changelog 2025-06-27 06:53:51 +02:00
Nicolas Arenas 5321325142 refs #2340: Replaces ctorrent with aria2c and mktorrent 2025-06-26 18:44:31 +02:00
Natalia Serrano 4c191aa730 Merge pull request 'fix-syntax-and-others' (#72) from fix-syntax-and-others into main
ogclient/pipeline/head This commit looks good Details
ogclient/pipeline/tag This commit looks good Details
Reviewed-on: #72
2025-06-26 13:39:31 +02:00
Natalia Serrano e3f5470fce refs #2331 fix syntax and other errors 2025-06-26 13:37:33 +02:00
Natalia Serrano 13ebbc2939 refs #2319 widen a check for None 2025-06-26 13:26:49 +02:00
Natalia Serrano 9cc67bbf1f Merge pull request 'refs #2316 prevent Configurar.py from messing with the browser' (#71) from configurar-coproc into main
ogclient/pipeline/head This commit looks good Details
ogclient/pipeline/tag This commit looks good Details
Reviewed-on: #71
2025-06-25 11:22:25 +02:00
Natalia Serrano 78f27b724e refs #2316 prevent Configurar.py from messing with the browser 2025-06-25 11:21:53 +02:00
Natalia Serrano b78fb6f900 Merge pull request 'refs #2314 fix bugs' (#70) from fix-bugs into main
ogclient/pipeline/head This commit looks good Details
ogclient/pipeline/tag This commit looks good Details
Reviewed-on: #70
2025-06-25 11:18:08 +02:00
Natalia Serrano 0f2cb4aefe refs #2314 fix bugs 2025-06-25 11:17:31 +02:00
Natalia Serrano 5541e39b5f Merge pull request 'refs #2308 do ogExecAndLog also when creating images' (#69) from ogexecandlog-createimage into main
ogclient/pipeline/head This commit looks good Details
ogclient/pipeline/tag This commit looks good Details
Reviewed-on: #69
2025-06-24 15:25:56 +02:00
Natalia Serrano 4f0543fe79 refs #2308 do ogExecAndLog also when creating images 2025-06-24 15:25:09 +02:00
Natalia Serrano a5eacbe203 Merge pull request '#2301 adds mount route when boot mark is created' (#67) from fix-bootMark-linux into main
ogclient/pipeline/head This commit looks good Details
ogclient/pipeline/tag This commit looks good Details
Reviewed-on: #67
2025-06-24 15:10:25 +02:00
Luis Gerardo Romero Garcia a34c98eb4c refs #2301 updates changelog 0.19.3 2025-06-24 15:09:21 +02:00
Luis Gerardo Romero Garcia c55a75f5ce #2301 adds mount route when boot mark is created 2025-06-24 15:08:29 +02:00
Natalia Serrano 1bf1283aff Merge pull request 'refs #2305 have ogExecAndLog do subprocess.Popen' (#68) from ogexecandlog into main
ogclient/pipeline/head This commit looks good Details
ogclient/pipeline/tag This commit looks good Details
Reviewed-on: #68
2025-06-24 15:04:40 +02:00
Natalia Serrano d5279eba42 refs #2305 have ogExecAndLog do subprocess.Popen 2025-06-24 15:03:52 +02:00
Natalia Serrano 87fb51ed2a refs #2304 remove obsolete useless function ogMcastRequest
ogclient/pipeline/head This commit looks good Details
2025-06-24 11:50:16 +02:00
14 changed files with 209 additions and 122 deletions

View File

@ -5,6 +5,61 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.22.2] - 2025-06-27
### Fixed
- Don't check rc of updateBootCache.py because we may have no cache partition
## [0.22.1] - 2025-06-27
### Fixed
- Included some changes that should be in the previous version
## [0.22.0] - 2025-06-26
### Changed
- Changed torrent client from ctorrent to aria2c
- Updated ogCreateTorrent function replaced ctorrent with mktorrent
## [0.21.1] - 2025-06-26
### Fixed
- Fixed syntax and other errors
## [0.21.0] - 2025-06-25
### Changed
- Prevent Configurar.py from messing with the browser
## [0.20.3] - 2025-06-25
### Fixed
- Fixed bugs when partitioning disks
## [0.20.2] - 2025-06-24
### Changed
- Do a couple of ogExecAndLog()s also when creating images
## [0.20.1] - 2025-06-24
### Changed
- Fix mark for ogboot on linux
## [0.20.0] - 2025-06-24
### Changed
- In order to have /tmp/command.log updated in realtime, ogExecAndLog now spawns a subprocess rather than calling functions directly
## [0.19.2] - 2025-06-24
### Changed

View File

@ -19,6 +19,7 @@ if 5 == len (sys.argv):
args = parser.parse_args()
src = { 'container': args.src_container, 'file': args.src_file }
dst = { 'container': args.dst_container, 'file': args.dst_file }
elif 7 == len (sys.argv):
parser.add_argument ('src_disk')
parser.add_argument ('src_par')
@ -29,6 +30,31 @@ elif 7 == len (sys.argv):
args = parser.parse_args()
src = { 'disk': args.src_disk, 'par': args.src_par, 'file': args.src_file }
dst = { 'disk': args.dst_disk, 'par': args.dst_par, 'file': args.dst_file }
elif 4 == len (sys.argv):
## can be either:
## - src_container src_file dst_file
## - src_file dst_container dst_file
if 'REPO' == sys.argv[1] or 'CACHE' == sys.argv[1]:
## we are in "src_container src_file dst_file"
parser.add_argument ('src_container')
parser.add_argument ('src_file')
parser.add_argument ('dst_file')
args = parser.parse_args()
src = { 'container': args.src_container, 'file': args.src_file }
dst = { 'file': args.dst_file }
elif 'REPO' == sys.argv[2] or 'CACHE' == sys.argv[2]:
## we are in "src_file dst_container dst_file"
parser.add_argument ('src_file')
parser.add_argument ('dst_container')
parser.add_argument ('dst_file')
args = parser.parse_args()
src = { 'file': args.src_file }
dst = { 'container': args.dst_container, 'file': args.dst_file }
else:
ogHelp ('ogCopyFile', 'ogCopyFile [ str_repo | int_ndisk int_npartition ] path_source [ str_repo | int_ndisk int_npartition ] path_target', ['ogCopyFile REPO newfile.txt 1 2 /tmp/newfile.txt'])
sys.exit (1)
elif 6 == len (sys.argv):
## can be either:
## - src_disk src_par src_file dst_container dst_file
@ -36,7 +62,7 @@ elif 6 == len (sys.argv):
try:
num = int (sys.argv[1]) ## raises ValueError if sys.argv[1] doesn't look like a number
## "src_disk src_par src_file dst_container dst_file"
## we are in "src_disk src_par src_file dst_container dst_file"
parser.add_argument ('src_disk')
parser.add_argument ('src_par')
parser.add_argument ('src_file')
@ -46,7 +72,7 @@ elif 6 == len (sys.argv):
src = { 'disk': args.src_disk, 'par': args.src_par, 'file': args.src_file }
dst = { 'container': args.dst_container, 'file': args.dst_file }
except:
## "src_container src_file dst_disk dst_par dst_file"
## we are in "src_container src_file dst_disk dst_par dst_file"
parser.add_argument ('src_container')
parser.add_argument ('src_file')
parser.add_argument ('dst_disk')

View File

@ -47,9 +47,6 @@ prog = os.path.basename(__name__)
#param = ''.join(sys.argv[2:]).replace(' ', '').replace('\t', '')
param = sys.argv[2]
# Activa navegador para ver progreso
coproc = subprocess.Popen (['/opt/opengnsys/bin/browser', '-qws', 'http://localhost/cgi-bin/httpd-log.sh'])
# Leer los dos bloques de parámetros, separados por '!'.
tbprm = param.split ('!')
pparam = tbprm[0] # General disk parameters
@ -71,7 +68,6 @@ for item in tbprm:
# Error si no se define el parámetro de disco (dis).
if dis is None:
coproc.kill()
sys.exit (ogGlobals.OG_ERR_FORMAT)
# Toma valores de distribución de particiones, separados por "%".
@ -101,13 +97,12 @@ for item in tbprm:
elif 'ope' == k: ope = int (v)
missing_params = []
if par is None: missing_params.append ('par')
if cpt is None: missing_params.append ('cpt')
if sfi is None: missing_params.append ('sfi')
if tam is None: missing_params.append ('tam')
if par is None or 'None' == par: missing_params.append ('par')
if cpt is None or 'None' == cpt: missing_params.append ('cpt')
if sfi is None or 'None' == sfi: missing_params.append ('sfi')
if tam is None or 'None' == tam: missing_params.append ('tam')
if missing_params:
print (f'partition data ({item}) missing required parameters ({' '.join (missing_params)})')
coproc.kill()
sys.exit (1)
# Componer datos de particionado.
@ -143,28 +138,26 @@ cur_ptt = DiskLib.ogGetPartitionTableType (dis)
ptt = 'GPT' if InventoryLib.ogIsEfiActive() else 'MSDOS'
if not cur_ptt or ptt != cur_ptt:
DiskLib.ogDeletePartitionTable (dis)
SystemLib.ogExecAndLog ('command', DiskLib.ogUpdatePartitionTable)
SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogUpdatePartitionTable'])
DiskLib.ogCreatePartitionTable (dis, ptt)
# Inicia la cache.
if 'CACHE' in sparam:
SystemLib.ogEcho (['session', 'log'], None, f'[30] {ogGlobals.lang.MSG_HELP_ogCreateCache}')
SystemLib.ogEcho (['session', 'log'], None, f' initCache {tch}')
rc = SystemLib.ogExecAndLog ('command', CacheLib.initCache, tch)
rc = SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGSCRIPTS}/initCache', tch])
if not rc:
SystemLib.ogRaiseError (['log', 'session'], ogGlobals.OG_ERR_CACHE, f'initCache failed')
coproc.kill()
sys.exit (1)
# Definir particionado.
SystemLib.ogEcho (['session', 'log'], None, f'[50] {ogGlobals.lang.MSG_HELP_ogCreatePartitions}')
SystemLib.ogEcho (['session', 'log'], None, f' ogCreatePartitions {dis} {' '.join (tbp)}')
res = SystemLib.ogExecAndLog ('command', DiskLib.ogCreatePartitions, dis, tbp)
res = SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogCreatePartitions', str(dis)] + tbp)
if not res:
coproc.kill()
SystemLib.ogRaiseError (['log', 'session'], ogGlobals.OG_ERR_GENERIC, f'ogCreatePartitions {dis} {' '.join (tbp)}')
sys.exit (1)
SystemLib.ogExecAndLog ('command', DiskLib.ogUpdatePartitionTable)
SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogUpdatePartitionTable'])
# Formatear particiones
SystemLib.ogEcho (['session', 'log'], None, f'[70] {ogGlobals.lang.MSG_HELP_ogFormat}')
@ -174,12 +167,11 @@ for p in range (1, maxp+1):
if 'CACHE' == tbf[p]:
if CACHESIZE == tch: # Si el tamaño es distinto ya se ha formateado.
SystemLib.ogEcho (['session', 'log'], None, ' ogFormatCache')
retval = SystemLib.ogExecAndLog ('command', CacheLib.ogFormatCache)
retval = SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogFormatCache'])
else:
SystemLib.ogEcho (['session', 'log'], None, f' ogFormatFs {dis} {p} {tbf[p]}')
retval = SystemLib.ogExecAndLog ('command', FileSystemLib.ogFormatFs, dis, str(p), tbf[p])
if retval:
coproc.kill()
retval = SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogFormatFs', str(dis), str(p), tbf[p]])
if not retval:
SystemLib.ogRaiseError (['session', 'log'], ogGlobals.OG_ERR_GENERIC, f'ogFormatFs {dis} {p} {tbf[p]}')
sys.exit (1)
# Registro de fin de ejecución
@ -190,5 +182,4 @@ SystemLib.ogEcho (['session', 'log'], None, f'{ogGlobals.lang.MSG_INTERFACE_END}
# Retorno
#___________________________________________________________________
coproc.kill()
sys.exit (0)

View File

@ -701,7 +701,7 @@ def ogGrubInstallMbr (disk, par, checkos='FALSE', kernelparam=''):
prefixsecondstage = '' # Reactivamos el grub con el grub.cfg original.
else: # SI Reconfigurar segunda etapa (grub.cfg) == TRUE
#llamada a updateBootCache para que aloje la primera fase del ogLive
subprocess.run ([f'{ogGlobals.OGSCRIPTS}/updateBootCache.py'], check=True)
subprocess.run ([f'{ogGlobals.OGSCRIPTS}/updateBootCache.py'])
if InventoryLib.ogIsEfiActive():
# UEFI: grubSintax necesita grub.cfg para detectar los kernels: si no existe recupero backup.

View File

@ -177,7 +177,7 @@ def ogCreatePartitions (disk, parts):
ogCreatePartitionTable (ND)
# Definir particiones y notificar al kernel.
p = subprocess.run (['sfdisk', DISK], input=sfdisk_input, capture_output=True, text=True)
p = subprocess.run (['sfdisk', DISK], input=sfdisk_input, text=True)
subprocess.run (['partprobe', DISK])
if CACHESIZE: CacheLib.ogMountCache()
return not p.returncode

View File

@ -263,7 +263,7 @@ def ogFormatFs (disk, par, fs=None, label=None):
errcode = ogGlobals.OG_ERR_PARTITION
ogUnlock (disk, par)
return errcode
return not errcode ## reverse to indicate success
#/**

View File

@ -515,9 +515,7 @@ def ogRestoreImage (repo, imgpath, disk, par):
rc = None
try:
p = subprocess.run (program, shell=True, capture_output=True, text=True)
print (p.stdout)
print (p.stderr)
p = subprocess.run (program, shell=True, text=True)
rc = not p.returncode
if not rc:
SystemLib.ogRaiseError ([], ogGlobalsOG_ERR_IMAGE, f'{imgfile}, {disk}, {par}')

View File

@ -615,18 +615,6 @@ def ogMcastReceiverPartition (disk, par, sess, tool, compressor):
return True
#/**
# ogMcastRequest
#@brief Función temporal para solicitar al ogRepoAux el envio de un fichero por multicast
#@param 1 Fichero a enviar ubicado en el REPO. puede ser ruta absoluta o relatica a /opt/opengnsys/images
#@param 2 PROTOOPT opciones protocolo multicast
#*/ ##
## now ogCore takes this responsibility
def ogMcastRequest (img, proto):
return True
##########################################
############## funciones torrent
#/**
@ -683,7 +671,7 @@ def ogTorrentStart (disk=None, par=None, container=None, torrentfile=None, torre
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or torrentfile {dev_err} not found')
return
if subprocess.run (['ctorrent', '-x', source]).returncode: ## if True, then ctorrent failed
if subprocess.run (['aria2c', '-S', source]).returncode: ## if True, then aria2c failed
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, '')
return None
@ -709,24 +697,36 @@ def ogTorrentStart (disk=None, par=None, container=None, torrentfile=None, torre
OPTION = None
cwd = os.getcwd()
# si No fichero .bf, y Si fichero destino imagen ya descargada y su chequeo fue comprobado en su descarga inicial.
if not os.path.exists (f'{source}.bf') and os.path.exists (target):
# si No fichero .aria2, y Si fichero destino imagen ya descargada y su chequeo fue comprobado en su descarga inicial.
if not os.path.exists (f'{target}.aria2') and os.path.exists (target):
print ('imagen ya descargada')
if 'seeder' != mode: return 'success' ## return any true value
print ('MODE seeder ctorrent')
print ('MODE seeder aria2c')
os.chdir (dirsource)
subprocess.run (['timeout', '--signal', 'INT', time, 'ctorrent', '-f', source])
aria2_cmd = [
"aria2c",
"--check-integrity=true",
"--bt-seed-unverified=true",
"--disable-ipv6",
"--seed-ratio=0.0",
f"--seed-time={time}",
"--enable-dht=false",
"--enable-peer-exchange=false",
f"--dir={dirsource}",
f"{source}"
]
subprocess.run (aria2_cmd)
os.chdir (cwd)
return 'success'
#Si no existe bf ni fichero destino descarga inicial.
if not os.path.exists (f'{source}.bf') and not os.path.exists (target):
#Si no existe bf ni fichero destino descarga inicial.
if not os.path.exists (f'{target}.aria2') and not os.path.exists (target):
print ('descarga inicial')
OPTION = 'DOWNLOAD'
# Si fichero bf descarga anterior no completada -.
if os.path.exists (f'{source}.bf') and os.path.exists (target):
if os.path.exists (f'{target}.aria2') and os.path.exists (target):
print ('Continuar con Descargar inicial no terminada.')
OPTION = 'DOWNLOAD'
@ -735,23 +735,51 @@ def ogTorrentStart (disk=None, par=None, container=None, torrentfile=None, torre
os.chdir (dirsource)
if 'peer' == mode:
print ('Donwloading Torrent as peer')
# Creamos el fichero de resumen por defecto
open (f'{source}.bf', 'w').close()
# ctorrent controla otro fichero -b ${SOURCE}.bfog
subprocess.run (['ctorrent', '-f', '-c', '-X', f'sleep {time}; kill -2 $(pidof ctorrent)', '-C', '100', source, '-s', target, '-b', f'{source}.bfog'])
SystemLib.ogEcho(["session","log"],"warning",f'Starting PeerTorrent download in PEER mode')
aria2_cmd = [
"aria2c",
"--enable-dht=false",
"--enable-peer-exchange=false",
"--disable-ipv6" ,
f"--seed-time={time}",
f"--dir={dirsource}",
f"{source}"
]
elif 'leecher' == mode:
print ('Donwloading Torrent as leecher')
subprocess.run (['ctorrent', '${SOURCE}', '-X', 'sleep 30; kill -2 $(pidof ctorrent)', '-C', '100', '-U', '0'])
SystemLib.ogEcho(["session","log"],"warning",f'Starting PeerTorrent download in LEECHER mode')
aria2_cmd = [
"aria2c",
"--enable-dht=false",
"--enable-peer-exchange=false",
"--disable-ipv6" ,
"--seed-time=0",
f"--dir={dirsource}",
f"{source}"
]
elif 'seeder' == mode:
print ('MODE seeder ctorrent')
# Creamos el fichero de resumen por defecto
open (f'{source}.bf', 'w').close()
# ctorrent controla otro fichero -b ${SOURCE}.bfog
subprocess.run (['ctorrent', '-f', '-c', '-X', f'sleep {time}; kill -2 $(pidof ctorrent)', '-C', '100', source, '-s', target, '-b', f'{source}.bfog'])
print ('MODE seeder aria2c')
SystemLib.ogEcho(["session","log"],"warning",f'Starting PeerTorrent download in SEEDER mode')
aria2_cmd = [
"aria2c",
"--check-integrity=true",
"--bt-seed-unverified=true",
"--disable-ipv6" ,
"--seed-ratio=0.0",
f"--seed-time={time}",
"--enable-dht=false",
"--enable-peer-exchange=false",
f"--dir={dirsource}", f"{source}"
]
else:
print ('this should not happen')
return None
SystemLib.ogEcho(["session","log"],"warning",f'Launching torrent command: {aria2_cmd}')
subprocess.run (aria2_cmd)
os.chdir (cwd)
@ -821,11 +849,13 @@ def ogCreateTorrent (disk=None, par=None, container=None, file=None, ip_bttrack=
cwd = os.getcwd()
os.chdir (os.path.dirname (source))
print (f'ctorrent -t {os.path.basename (source)} -u http://{ip_bttrack}:6969/announce -s {source}.torrent')
subprocess.run (['ctorrent', '-t', os.path.basename (source), '-u', f'http://{ip_bttrack}:6969/announce', '-s', f'{source}.torrent'])
print (f'mktorrent -a http://{ip_bttrack}:6969/announce -o {source}.torrent {source}')
subprocess.run (['mktorrent' , '-a', f'http://{ip_bttrack}:6969/announce', '-o', f'{source}.torrent', source])
os.chdir (cwd)
#/**
# ogUpdateCacheIsNecesary [ str_repo ] Relative_path_file_OGIMG_with_/
#@brief Comprueba que el fichero que se desea almacenar en la cache del cliente, no esta.

View File

@ -3,22 +3,15 @@ import datetime
from zoneinfo import ZoneInfo
import sys
import os
import select
import json
import shutil
import inspect
import glob
## for ogExecAndLog
from io import StringIO
from contextlib import redirect_stdout, redirect_stderr
import ogGlobals
import StringLib
#NODEBUGFUNCTIONS, OGIMG, OG_ERR_CACHESIZE, OG_ERR_NOTCACHE, OG_ERR_NOTWRITE, OG_ERR_FILESYS
#OG_ERR_REPO, OG_ERR_NOTOS, OG_ERR_NOGPT, OG_ERR_OUTOFLIMIT, OG_ERR_IMAGE, OG_ERR_CACHE
#OGLOGSESSION, OGLOGCOMMAND, OGLOGFILE, OG_ERR_LOCKED, OG_ERR_PARTITION, OG_ERR_FORMAT, OG_ERR_NOTEXEC, OG_ERR_NOTFOUND
def _logtype2logfile (t):
if 'log' == t.lower(): return ogGlobals.OGLOGFILE
if 'jsonlog' == t.lower(): return ogGlobals.OGJSONLOGFILE
@ -84,11 +77,11 @@ def ogEcho (logtypes, loglevel, msg):
#@note str_logfile = { LOG, SESSION, COMMAND }
#*/
#ogExecAndLog (str_logfile ... str_command ...",
#ogExecAndLog ([], ogMyLib.ogSomeMethod, *args, **kwargs)
#ogExecAndLog ('command', ogMyLib.ogSomeMethod, *args, **kwargs)
#ogExecAndLog (['command'], ogMyLib.ogSomeMethod, *args, **kwargs)
#ogExecAndLog (['log', 'command'], ogMyLib.ogSomeMethod, *args, **kwargs)
def ogExecAndLog (logtypes, fun, *args, **kwargs):
#ogExecAndLog ([], ['/path/to/script', *args])
#ogExecAndLog ('command', ['/path/to/script', *args])
#ogExecAndLog (['command'], ['/path/to/script', *args])
#ogExecAndLog (['log', 'command'], ['/path/to/script', *args])
def ogExecAndLog (logtypes, script_and_args):
logfiles = ['/dev/stdout']
if type (logtypes) is list:
for l in logtypes:
@ -106,7 +99,7 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs):
else:
logfiles.append (_logtype2logfile (logtypes))
if not fun:
if not script_and_args:
ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, 'no function provided')
return
@ -129,38 +122,38 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs):
# ## redirect stdout only
# eval $COMMAND | tee -a $FILES
sout = serr = ''
capture_stderr = False
if 'command' in logtypes:
os.unlink (ogGlobals.OGLOGCOMMAND)
open (ogGlobals.OGLOGCOMMAND, 'w').close()
with redirect_stdout (StringIO()) as r_stdout, redirect_stderr (StringIO()) as r_stderr:
rc = fun (*args, **kwargs)
sout = r_stdout.getvalue()
serr = r_stderr.getvalue()
else:
with redirect_stdout (StringIO()) as r_stdout:
rc = fun (*args, **kwargs)
sout = r_stdout.getvalue()
capture_stderr = True
rc_str = str (rc)
if sout or serr or ('True' != rc_str and 'False' != rc_str and 'None' != rc_str):
for f in logfiles:
with open (f, 'a') as fd:
if ogGlobals.OGJSONLOGFILE == f:
if sout: fd.write (json.dumps ({'message':sout}) + '\n')
if serr: fd.write (json.dumps ({'message':serr}) + '\n')
if rc_str: fd.write (json.dumps ({'message':rc_str}) + '\n')
else:
if sout: fd.write (f'{sout}\n')
if serr: fd.write (f'{serr}\n')
if rc_str: fd.write (f'{rc_str}\n')
#fd.write (f"ogExecAndLog: {fun.__name__} rc:\n{rc_str}\n")
#if sout: fd.write (f"ogExecAndLog: {fun.__name__} stdout:\n{sout}\n")
#else: fd.write (f"ogExecAndLog: {fun.__name__} stdout: (none)\n")
#if serr: fd.write (f"ogExecAndLog: {fun.__name__} stderr:\n{serr}\n")
#else: fd.write (f"ogExecAndLog: {fun.__name__} stderr: (none)\n")
p = subprocess.Popen (script_and_args, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
ready_to_read, _, _ = select.select ([p.stdout, p.stderr], [], [], 1)
return rc
partial_out = ''
if p.stdout in ready_to_read:
l = p.stdout.readline()
partial_out += l
if p.stderr in ready_to_read:
l = p.stderr.readline() ## always read from stderr even if we're discarding it, to prevent buffers from filling up
if capture_stderr:
partial_out += l
if partial_out:
for f in logfiles:
with open (f, 'a') as fd:
if ogGlobals.OGJSONLOGFILE == f:
fd.write (json.dumps ({'message':partial_out}))
else:
fd.write (partial_out)
if p.poll() is not None:
break
rc = p.returncode
return not rc ## negate shell return code
#/**
# ogGetCaller

View File

@ -81,7 +81,7 @@ if 'Windows' == ostype:
elif 'Linux' == ostype:
# Marca para arranque.
boot_mark_file = f'/Part-{int(disk):02d}-{int(par):02d}'
boot_mark_file = f'{mntdir}/Part-{int(disk):02d}-{int(par):02d}'
try:
open (boot_mark_file, 'w').close()
except Exception as e:

View File

@ -140,7 +140,7 @@ def main (disk, par, repo, imgname):
# Evaluar variable de engine.cfg para reducir el sistema de archivos en la creacion
if ogGlobals.IMGREDUCE:
SystemLib.ogEcho (['log', 'session'], None, f'[30] {ogGlobals.lang.MSG_HELP_ogReduceFs}')
FileSystemLib.ogReduceFs (disk, par)
SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogReduceFs', disk, par])
newsizefs = FileSystemLib.ogGetFsSize (disk, par)
timeaux = time.time() - time1
SystemLib.ogEcho (['log', 'session'], None, f' {ogGlobals.lang.MSG_SCRIPTS_TIME_PARTIAL} ( {newsizefs} KB ) : {int (timeaux/60)}m {int (timeaux%60)}s')
@ -157,7 +157,7 @@ def main (disk, par, repo, imgname):
with open (ogGlobals.OGLOGCOMMAND, 'w') as fd: fd.write ('')
time2 = time.time()
SystemLib.ogEcho (['log', 'session'], None, f'[40] {ogGlobals.lang.MSG_HELP_ogCreateImage} : ogCreateImage {disk} {par} {repo} {imgname} {ogGlobals.IMGPROG} {ogGlobals.IMGCOMP}')
if not ImageLib.ogCreateImage (disk, par, repo, f'/{imgname}', ogGlobals.IMGPROG, ogGlobals.IMGCOMP):
if not SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogCreateImage', disk, par, repo, f'/{imgname}', ogGlobals.IMGPROG, ogGlobals.IMGCOMP]):
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_IMAGE, 'ogCreateImage')
sys.exit (1)
resumecreateimage = subprocess.run (['grep', 'Total Time:', ogGlobals.OGLOGCOMMAND], capture_output=True, text=True).stdout

View File

@ -5,7 +5,6 @@
import sys
import time
import subprocess
import ogGlobals
import SystemLib

6
ogclient/scripts/restoreImage.py 100644 → 100755
View File

@ -90,7 +90,7 @@ if not imgfile or not imgdir:
retval = 0
if proto in ['UNICAST', 'UNICAST-DIRECT']:
SystemLib.ogEcho (['log', 'session'], None, f'[40] ogRestoreImage {repo} {imgname} {disk} {par} UNICAST')
retval = SystemLib.ogExecAndLog ('command', ImageLib.ogRestoreImage, repo, imgname, disk, par)
retval = SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogRestoreImage', repo, imgname, disk, par])
elif proto in ['MULTICAST', 'MULTICAST-DIRECT']:
tool = ImageLib.ogGetImageProgram ('REPO', imgname)
if not tool:
@ -103,9 +103,7 @@ elif proto in ['MULTICAST', 'MULTICAST-DIRECT']:
sys.exit (1)
SystemLib.ogEcho (['log', 'session'], None, f'[40] ogMcastReceiverPartition {disk} {par} {port} {tool} {compress}')
if not ProtocolLib.ogMcastRequest (f'{imgname}.img', protoopt):
sys.exit (1)
retval = SystemLib.ogExecAndLog ('command', ProtocolLib.ogMcastReceiverPartition, disk, par, port, tool, compress)
retval = SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogMcastReceiverPartition', disk, par, port, tool, compress])
else:
SystemLib.ogRaiseError ('session', ogGlobals.OG_ERR_FORMAT, f'{ogGlobals.lang.MSG_FORMAT}: {prog} REPO|CACHE imagen ndisco nparticion [ UNICAST|MULTICAST opciones protocolo]')
sys.exit (1)

21
ogclient/scripts/updateCache.py 100644 → 100755
View File

@ -143,7 +143,7 @@ if sizerequired >= cachesizefree:
SystemLib.ogRaiseError ('session', ogGlobals.OG_ERR_CACHESIZE, 'CACHE')
sys.exit (1)
# Comprobamos que imagen cache igual a la del repo. Si sincronizada no podemos comprobar.
# Comprobamos que imagen cache igual a la del repo. Si sincronizada no podemos comprobar.
rc = ProtocolLib.ogUpdateCacheIsNecesary (repositorio, path, protocolo)
# si rc=True: actualizamos; si rc=False: no actualizamos (exit 0); si rc=None: exit error
if rc == True: pass ## es necesario actualizar
@ -156,9 +156,10 @@ CacheLib.ogMountCache()
imgdir = FileLib.ogGetParentPath ('CACHE', f'/{path}')
if not imgdir:
SystemLib.ogEcho (['log', 'session'], None, f'[5] {ogGlobals.lang.MSG_HELP_ogMakeDir} "{path} {os.path.dirname (path)}".')
FileLib.ogMakeDir ('CACHE', os.path.dirname (f'/{path}'))
imgdir = ogGetParentPath ('CACHE', f'/{path}')
FileLib.ogMakeDir (container='CACHE', file=os.path.dirname (f'/{path}'))
imgdir = FileLib.ogGetParentPath ('CACHE', f'/{path}')
if not imgdir:
SystemLib.ogRaiseError ('session', ogGlobals.OG_ERR_IMAGE, 'no directory for images')
sys.exit (1)
t0 = time.time()
@ -167,13 +168,13 @@ if 'TORRENT' == protocolo:
SystemLib.ogEcho (['log', 'session'], None, f'ogCopyFile {repositorio} {path}.torrent absolute {ogGlobals.OGCAC}/{ogGlobals.OGIMG}')
mac_digits = NetLib.ogGetMacAddress().split (':')
timewait = int ('0x' + mac_digits[4] + mac_digits[5], 16) * 120 / 65535
if not SystemLib.ogExecAndLog ('command', FileLib.ogCopyFile, {'container':repositorio, 'file':f'{path}.torrent'}, {'file':imgdir}):
if not SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogCopyFile', repositorio, f'{path}.torrent', imgdir]):
sys.exit (1)
p2pwait = random.randint (1, 121)
SystemLib.ogEcho (['log', 'session'], None, f' [ ] {ogGlobals.lang.MSG_SCRIPTS_TASK_SLEEP} : {p2pwait} seconds')
time.sleep (p2pwait)
SystemLib.ogEcho (['log', 'session'], None, f' [ ] {ogGlobals.lang.MSG_SCRIPTS_TASK_START}: ogTorrentStart CACHE {path}.torrent {optprotocolo}')
SystemLib.ogExecAndLog ('command', ProtocolLib.ogTorrentStart, container='CACHE', torrentfile=f'{path}.torrent', torrentsess=optprotocolo)
SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogTorrentStart', 'CACHE', f'{path}.torrent', optprotocolo])
resumeupdatecache = subprocess.run (['grep', '--max-count', '1', '--before-context', '1', 'Download', ogGlobals.OGLOGCOMMAND], capture_output=True, text=True).stdout
resumeupdatecachebf = subprocess.run (['grep', '--max-count', '1', 'Download', ogGlobals.OGLOGCOMMAND], capture_output=True, text=True).stdout
if 'Download complete.' == resumeupdatecachebf:
@ -182,19 +183,15 @@ elif 'MULTICAST' == protocolo:
SystemLib.ogEcho (['log', 'session'], None, f'{ogGlobals.lang.MSG_SCRIPTS_UPDATECACHE_CHECKMCASTSESSION}: {repoip}:{port}')
time.sleep (random.randint (1, 31))
SystemLib.ogEcho (['log', 'session'], None, f'ogMcastRequest {path} {optprotocolo}')
if not SystemLib.ogExecAndLog ('command', ProtocolLib.ogMcastRequest, path, optprotocolo):
sys.exit (1)
SystemLib.ogEcho (['log', 'session'], None, f'ogMcastReceiverFile {port} CACHE {path}')
if not SystemLib.ogExecAndLog ('command', ProtocolLib.ogMcastReceiverFile, sess=port, container='CACHE', file=path):
if not SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogMcastReceiverFile', port, 'CACHE', path]):
sys.exit (1)
resumeupdatecache = subprocess.run (['grep', '--max-count', '1', '--before-context', '1', 'Transfer complete', f'{ogGlobals.OGLOGCOMMAND}.tmp'], capture_output=True, text=True).stdout
elif 'UNICAST' == protocolo:
print (f'ogExecAndLog ("command", FileLib.ogCopyFile, {{"container":{repositorio}, "file":{path}}}, {{"file":{imgdir}}})')
SystemLib.ogExecAndLog ('command', FileLib.ogCopyFile, {'container':repositorio, 'file':path}, {'file':imgdir})
print (f'ogExecAndLog ("command", {ogGlobals.OGPYFUNCS}/ogCopyFile {repositorio} {path} {imgdir}')
SystemLib.ogExecAndLog ('command', [f'{ogGlobals.OGPYFUNCS}/ogCopyFile', repositorio, path, imgdir])
time.sleep (5)
resumeupdatecache = subprocess.run (['grep', '--max-count', '1', '100%', f'{ogGlobals.OGLOGCOMMAND}.tmp'], capture_output=True, text=True).stdout