fix-create-partitions #13

Merged
nserrano merged 3 commits from fix-create-partitions into main 2025-03-28 14:10:13 +01:00
13 changed files with 20 additions and 92 deletions

View File

@ -5,6 +5,12 @@ 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.2.3] - 2025-03-28
### Fixed
- Fixed some errors in Configurar.py, ogCreateCache, ogCreatePartitions and initCache.py
## [0.2.2] - 2025-03-26
### Fixed

View File

@ -147,7 +147,10 @@ if not cur_ptt or ptt != cur_ptt:
if 'CACHE' in sparam:
SystemLib.ogEcho (['session', 'log'], None, f'[30] {ogGlobals.lang.MSG_HELP_ogCreateCache}')
SystemLib.ogEcho (['session', 'log'], None, f' initCache {tch}')
SystemLib.ogExecAndLog ('command', CacheLib.initCache, tch)
rc = SystemLib.ogExecAndLog ('command', CacheLib.initCache, tch)
if rc:
SystemLib.ogRaiseError (['log', 'session'], ogGlobals.OG_ERR_CACHE, f'initCache failed')
sys.exit (1)
# Definir particionado.
SystemLib.ogEcho (['session', 'log'], None, f'[50] {ogGlobals.lang.MSG_HELP_ogCreatePartitions}')

View File

@ -1387,7 +1387,6 @@ def ogGrubSecurity (disk, par, user='root', passwd=''):
for _cuatro in ['menu.lst', 'grub.cfg', 'grub.cfg.backup.og']:
path = '/'.join ([secondstage, _uno, _dos, _tres, _cuatro])
grubcfg += glob.glob (path)
print (f'nati grubcfg ({grubcfg})')
# comprobamos que exista el archivo de configuración.
if not grubcfg:

View File

@ -60,11 +60,9 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
prev_part = part - i
if prev_part <= 0: break
ENDPREVPART = DiskLib.ogGetLastSector (ndsk, prev_part)
print (f'nati got endprevpart ({ENDPREVPART})')
if ENDPREVPART: break
i += 1
if not ENDPREVPART:
print (f'nati no endprevpart, assuming 0')
ENDPREVPART=0
#SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, ndsk)
#return None
@ -72,7 +70,6 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
MINSIZE = 25000
MAXSIZE = END
if SIZE < MINSIZE or SIZE > MAXSIZE or START < ENDPREVPART:
print (f'nati size ({SIZE}) < minsize ({MINSIZE}) or size > maxsize ({MAXSIZE}) or start ({START}) < endprevpart ({ENDPREVPART})')
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, ndsk)
return None
@ -82,23 +79,20 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
# En el caso de ser disco GPT, de momento se borra la particion y se vuelve a crear,
# por lo que se pierden los datos.
pttype = DiskLib.ogGetPartitionTableType (ndsk)
print (f'nati pttype ({pttype})')
if not pttype:
pttype = 'MSDOS'
DiskLib.ogCreatePartitionTable (ndsk, pttype)
get_ptt = DiskLib.ogGetPartitionTableType (ndsk)
print (f'nati get_ptt ({get_ptt})')
if 'GPT' == get_ptt:
# Si la tabla de particiones no es valida, volver a generarla.
if subprocess.run (['sgdisk', '-p', DISK]).returncode:
subprocess.run (['gdisk', DISK], input='2\nw\nY\n', text=True)
if subprocess.run (['sgdisk', '-p', DISK], capture_output=True, text=True).returncode:
subprocess.run (['gdisk', DISK], input='2\nw\nY\n', capture_output=True, text=True)
# Si existe la cache se borra previamente
if ogFindCache(): ogDeleteCache()
# Capturamos el codigo de particion GPT para cache
# PATCH - Cuando es GPT, la particion con codigo CACHE (CA00) no existe y no puede crearse, se cambia por LINUX (8300)
ID = DiskLib.ogTypeToId ('LINUX', 'GPT')
print (f'nati ID ({ID})')
subprocess.run (['sgdisk', DISK, f'-n{part}:{START}:{END}', f'-c{part}:CACHE', f'-t{part}:{ID}'])
elif 'MSDOS' == get_ptt:
# Si la tabla de particiones no es valida, volver a generarla.
@ -106,7 +100,6 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
subprocess.run (['fdisk', DISK], input='w\n', text=True)
# Definir particiones y notificar al kernel.
ID = DiskLib.ogTypeToId ('CACHE', 'MSDOS')
print (f'nati ID ({ID})')
# Salvamos la configuración de las particiones e incluimos la cache.
tmp = subprocess.run (['sfdisk', '--dump', DISK], capture_output=True, text=True).stdout.splitlines()
tmp = [ x for x in tmp if f'{DISK}{part}' not in x ]
@ -117,10 +110,10 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
tmp = [UNIT, ''] + tmp
# Guardamos nueva configuración en el disco.
i = '\n'.join(tmp)
print (f'nati i ({i})')
subprocess.run (['sfdisk', '--no-reread', DISK], input=i, text=True)
# Actualiza la tabla de particiones en el kernel.
DiskLib.ogUpdatePartitionTable()
return True

View File

@ -76,7 +76,7 @@ def ogCreatePartitions (disk, parts):
CACHEPART = CacheLib.ogFindCache()
if CACHEPART:
cache_disk, cache_part = CACHEPART.split()
if ND == cache_disk:
if ND == int (cache_disk):
CACHESIZE = int (CacheLib.ogGetCacheSize()) * 2
# Sector de inicio (la partición 1 empieza en el sector 63).
IODISCO = ogDiskToDev (disk)
@ -100,7 +100,6 @@ def ogCreatePartitions (disk, parts):
SECTORS -= CACHESIZE
PART = 1
print (f'START ({START}) SECTORS ({SECTORS}) PART ({PART})')
sfdisk_input = 'unit: sectors\n\n'
NVME_PREFIX = 'p' if 'nvme' in DISK else ''
@ -109,6 +108,7 @@ def ogCreatePartitions (disk, parts):
if f'{ND} {PART}' == CACHEPART and CACHESIZE:
sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start={SECTORS+1}, size={CACHESIZE}, Id=ca\n'
PART += 1
continue
# Leer formato de cada parámetro - Tipo:Tamaño
TYPE, SIZE = p.split (':')
@ -176,9 +176,7 @@ def ogCreatePartitions (disk, parts):
ogCreatePartitionTable (ND)
# Definir particiones y notificar al kernel.
#print (f'nati: about to run sfdisk: ({sfdisk_input})')
p = subprocess.run (['sfdisk', DISK], input=sfdisk_input, capture_output=True, text=True)
#print (f'nati: rc ({p.returncode}) stdout ({p.stdout}) stderr ({p.stderr})')
subprocess.run (['partprobe', DISK])
if CACHESIZE: CacheLib.ogMountCache()
return True
@ -284,9 +282,7 @@ def ogCreateGptPartitions (disk, parts):
ogCreatePartitionTable (ND, 'GPT')
# Definir particiones y notificar al kernel.
#print (f'nati: about to run sgdisk ({DELOPTIONS}) ({OPTIONS}) ({DISK})')
p = subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK])
#print (f'nati: rc ({p.returncode}) stdout ({p.stdout}) stderr ({p.stderr})')
p = subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK], capture_output=True, text=True)
subprocess.run (['partprobe', DISK])
if CACHESIZE: CacheLib.ogMountCache()
return True
@ -818,7 +814,7 @@ def ogGetPartitionId (disk, par):
if fsid == '8300' and f'{disk} {par}' == CacheLib.ogFindCache():
fsid = 'CA00'
elif 'MSDOS' == pttype:
fsid = subprocess.run (['sfdisk', '--part-type', DISK, par], capture_output=True, text=True).stdout.strip()
fsid = subprocess.run (['sfdisk', '--part-type', DISK, str(par)], capture_output=True, text=True).stdout.strip()
elif 'LVM' == pttype:
fsid = '10000'
elif 'ZPOOL' == pttype:

View File

@ -213,10 +213,8 @@ def ogCopyFile (src, dst):
if not TARGET:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or file {dst_dev_err} not found')
return
print (f'nati: ogCopyFile: SOURCE ({SOURCE}) TARGET ({TARGET})')
# Copiar fichero (para evitar problemas de comunicaciones las copias se hacen con rsync en vez de cp).
print (f'nati: ogCopyFile: rsync --progress --inplace -avh ({SOURCE}) ({TARGET})')
result = subprocess.run(["rsync", "--progress", "--inplace", "-avh", SOURCE, TARGET], capture_output=True, text=True)
return result.returncode
@ -506,12 +504,10 @@ def ogMakeDir (container=None, disk=None, par=None, file=None):
else:
raise TypeError ('if one of "disk" and "par" are specified, then both must be')
print (f'nati: ogMakeDir: parent ({parent})')
if not parent:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or file {dev_err} not found')
return None
dst = os.path.basename (file)
print (f'nati: ogMakeDir: dst ({dst})')
os.makedirs (os.path.join (parent, dst), exist_ok=True)
return True

View File

@ -248,7 +248,6 @@ def ogCreateImage (disk, par, container, imgfile, tool='partclone', level='gzip'
# Crear Imagen.
#trap
print (f'nati program ({program})')
p = subprocess.run (program, shell=True, check=True)
errcode = p.returncode
if 0 == errcode:
@ -512,10 +511,8 @@ def ogRestoreImage (repo, imgpath, disk, par):
rc = None
try:
#print (f'nati: ogRestoreImage: running ({program})')
p = subprocess.run (program, shell=True, capture_output=True, text=True)
rc = p.returncode
#print (f'nati: ogRestoreImage: rc ({rc}) stdout ({p.stdout}) stderr ({p.stderr})')
if not rc:
SystemLib.ogRaiseError ([], ogGlobalsOG_ERR_IMAGE, f'{imgfile}, {disk}, {par}')
except:

View File

@ -177,7 +177,6 @@ def ogGetMacAddress():
mac_addresses.append(parts[i + 1].upper())
if mac_addresses:
print (f'nati: ogGetMacAddress: {mac_addresses[0]}')
return mac_addresses[0]
else:
print("No active mac address found")

View File

@ -82,7 +82,6 @@ def ogUcastSyntax (op, sess, file=None, device=None, tool=None, level=None):
address += f' -O {session[i]}:{portbase}'
else:
address = f'{session[1]}:{portbase}'
#print (f'nati mode ({mode}) address ({address})')
if 'SENDPARTITION' == op:
syn = ImageLib.ogCreateImageSyntax (device, ' ', tool, level)
@ -90,7 +89,6 @@ def ogUcastSyntax (op, sess, file=None, device=None, tool=None, level=None):
## otherwise, param2 in ImageLib.ogCreateImageSyntax() is not '| mbuffer' but empty
## and then parts[2] is out of range
parts = syn.split ('|')
#print (f'nati syn ({syn}) parts ({parts})')
prog1 = f'{parts[0]}|{parts[2]}'.strip()
prog1 = prog1.replace ('>', '').strip()
return f'{prog1} | mbuffer {address}'
@ -131,7 +129,6 @@ def ogUcastSendPartition (disk, par, sess, tool, level):
cmd = ogUcastSyntax ('SENDPARTITION', sess, device=PART, tool=tool, level=level)
if not cmd: return None
print (f'nati cmd ({cmd})')
try:
subprocess.run (cmd, shell=True, check=True)
except subprocess.CalledProcessError:
@ -163,7 +160,6 @@ def ogUcastReceiverPartition (disk, par, sess, tool, level):
cmd = ogUcastSyntax ('RECEIVERPARTITION', sess, device=PART, tool=tool, level=level)
if not cmd: return None
print (f'nati cmd ({cmd})')
try:
subprocess.run (cmd, shell=True, check=True)
except subprocess.CalledProcessError:
@ -208,7 +204,6 @@ def ogUcastSendFile (disk=None, par=None, container=None, file=None, sess=None):
## we were given container=
source = FileLib.ogGetPath (src=container, file=file)
dev_err = f'{container} {file}'
print (f'nati ogGetPath (src=({container}), file=({file})) = source ({source})')
else:
raise TypeError ('argument "container" can be specified along neither "disk" nor "par"')
@ -217,12 +212,10 @@ def ogUcastSendFile (disk=None, par=None, container=None, file=None, sess=None):
## we were given disk= par=
source = FileLib.ogGetPath (src=f'{disk} {par}', file=file)
dev_err = f'{disk} {par} {file}'
print (f'nati ogGetPath (src=({disk} {par}), file=({file})) = source ({source})')
elif disk is None and par is None:
## we were given nothing
source = FileLib.ogGetPath (file=file)
dev_err = file
print (f'nati ogGetPath (file=({file})) = source ({source})')
else:
raise TypeError ('if one of "disk" and "par" are specified, then both must be')
@ -231,14 +224,12 @@ def ogUcastSendFile (disk=None, par=None, container=None, file=None, sess=None):
return
path2 = FileLib.ogGetPath (file=source)
print (f'nati path2 ({path2})')
if not path2:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or file {dev_err} not found')
return
cmd = ogUcastSyntax ('SENDFILE', sess, file=source)
if not cmd: return None
print (f'nati cmd ({cmd})')
try:
subprocess.run (cmd, shell=True, check=True)
except subprocess.CalledProcessError:
@ -309,7 +300,6 @@ def ogMcastSyntax (op, sess, file=None, device=None, tool=None, level=None):
if 'SEND' in op: mode = 'server'
else: mode = 'client'
print (f'nati mode ({mode})')
try:
isudpcast = subprocess.run (['udp-receiver', '--help'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True).stdout
@ -318,7 +308,6 @@ def ogMcastSyntax (op, sess, file=None, device=None, tool=None, level=None):
return
session = sess.split (':')
print (f'nati sess ({sess}) session ({session})')
PERROR = 0
if 'server' == mode:
@ -332,7 +321,6 @@ def ogMcastSyntax (op, sess, file=None, device=None, tool=None, level=None):
mbuffer = " --pipe 'mbuffer -q -m 20M' "
portbase = int (session[0])
print (f'nati portbase ({portbase})')
if portbase not in range (9000, 9100, 2):
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'McastSession portbase {portbase}')
PERROR = 3
@ -372,7 +360,6 @@ def ogMcastSyntax (op, sess, file=None, device=None, tool=None, level=None):
if 'client' == mode:
other = session[1:]
print (f'nati session ({session}) other ({other})')
serveraddress = other[0] if len (other) > 0 else ''
starttimeout = other[1] if len (other) > 1 else ''
receivertimeout = other[2] if len (other) > 2 else ''
@ -383,23 +370,16 @@ def ogMcastSyntax (op, sess, file=None, device=None, tool=None, level=None):
else:
repoip = NetLib.ogGetRepoIp()
clientip = _clientip()
#print (f'nati repoip ({repoip}) clientip ({clientip})')
if 1 != len (clientip):
raise Exception ('more than one local IP address found')
c = clientip[0]
#print (f'nati c ({c})')
clientip = c['local']
mascara = c['prefixlen']
#print (f'nati clientip ({clientip}) mascara ({mascara})')
ripbt = _binary_ip (repoip)
ipbt = _binary_ip (clientip)
reposubred = ripbt[0:mascara]
clientsubred = ipbt[0:mascara]
#print (f'nati ripbt ({ripbt})')
#print (f'nati ipbt ({ipbt})')
#print (f'nati reposubred ({reposubred})')
#print (f'nati clientsubred ({clientsubred})')
if reposubred == clientsubred: serveraddress = ' '
else: serveraddress = f' --mcast-rdv-address {repoip}'
@ -427,7 +407,6 @@ def ogMcastSyntax (op, sess, file=None, device=None, tool=None, level=None):
## otherwise, param2 in ImageLib.ogCreateImageSyntax() is not '| mbuffer' but empty
## and then parts[2] is out of range
parts = syn.split ('|')
#print (f'nati syn ({syn}) parts ({parts})')
prog1 = f'{parts[0]}|{parts[2]}'.strip()
prog1 = prog1.replace ('>', '').strip()
return f'{prog1} | {syntaxserver}'
@ -483,7 +462,6 @@ def ogMcastSendFile (disk=None, par=None, container=None, file=None, sess=None):
## we were given container=
source = FileLib.ogGetPath (src=container, file=file)
dev_err = f'{container} {file}'
print (f'nati ogGetPath (src=({container}), file=({file})) = source ({source})')
else:
raise TypeError ('argument "container" can be specified along neither "disk" nor "par"')
@ -492,12 +470,10 @@ def ogMcastSendFile (disk=None, par=None, container=None, file=None, sess=None):
## we were given disk= par=
source = FileLib.ogGetPath (src=f'{disk} {par}', file=file)
dev_err = f'{disk} {par} {file}'
print (f'nati ogGetPath (src=({disk} {par}), file=({file})) = source ({source})')
elif disk is None and par is None:
## we were given nothing
source = FileLib.ogGetPath (file=file)
dev_err = file
print (f'nati ogGetPath (file=({file})) = source ({source})')
else:
raise TypeError ('if one of "disk" and "par" are specified, then both must be')
@ -506,14 +482,12 @@ def ogMcastSendFile (disk=None, par=None, container=None, file=None, sess=None):
return
path2 = FileLib.ogGetPath (file=source)
print (f'nati path2 ({path2})')
if not path2:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or file {dev_err} not found')
return
cmd = ogMcastSyntax ('SENDFILE', sess, file=source)
if not cmd: return None
print (f'nati cmd ({cmd})')
try:
subprocess.run (cmd, shell=True, check=True)
except subprocess.CalledProcessError:
@ -552,7 +526,6 @@ def ogMcastReceiverFile (disk=None, par=None, container=None, file=None, sess=No
## we were given container=
targetdir = FileLib.ogGetParentPath (src=container, file=file)
dev_err = f'{container} {file}'
print (f'nati ogGetParentPath (src=({container}), file=({file})) = targetdir ({targetdir})')
else:
raise TypeError ('argument "container" can be specified along neither "disk" nor "par"')
@ -561,12 +534,10 @@ def ogMcastReceiverFile (disk=None, par=None, container=None, file=None, sess=No
## we were given disk= par=
targetdir = FileLib.ogGetParentPath (src=f'{disk} {par}', file=file)
dev_err = f'{disk} {par} {file}'
print (f'nati 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'nati ogGetParentPath (file=({file})) = targetdir ({targetdir})')
else:
raise TypeError ('if one of "disk" and "par" are specified, then both must be')
@ -575,12 +546,9 @@ def ogMcastReceiverFile (disk=None, par=None, container=None, file=None, sess=No
return
targetfile = os.path.basename (file)
print (f'nati targetfile ({targetfile})')
print (f'nati calling ogMcastSyntax with sess ({sess})')
cmd = ogMcastSyntax ('RECEIVERFILE', sess, file=os.path.join (targetdir, targetfile))
if not cmd: return None
print (f'nati cmd ({cmd})')
try:
subprocess.run (cmd, shell=True, check=True)
except subprocess.CalledProcessError:
@ -613,7 +581,6 @@ def ogMcastSendPartition (disk, par, sess, tool, compressor):
FileSystemLib.ogUnmount (disk, par)
cmd = ogMcastSyntax ('SENDPARTITION', sess, device=PART, tool=tool, level=compressor)
if not cmd: return None
print (f'nati cmd ({cmd})')
try:
subprocess.run (cmd, shell=True, check=True)
except subprocess.CalledProcessError:
@ -639,7 +606,6 @@ def ogMcastReceiverPartition (disk, par, sess, tool, compressor):
FileSystemLib.ogUnmount (disk, par)
cmd = ogMcastSyntax ('RECEIVERPARTITION', sess, device=PART, tool=tool, level=compressor)
if not cmd: return None
print (f'nati cmd ({cmd})')
try:
subprocess.run (cmd, shell=True, check=True)
except subprocess.CalledProcessError:
@ -693,7 +659,6 @@ def ogTorrentStart (disk=None, par=None, container=None, torrentfile=None, torre
return None
source = FileLib.ogGetPath (src=container, file=torrentfile)
dev_err = f'{container} {torrentfile}'
print (f'nati ogGetPath (src=({container}), file=({torrentfile})) = source ({source})')
else:
raise TypeError ('argument "container" can be specified along neither "disk" nor "par"')
@ -702,7 +667,6 @@ def ogTorrentStart (disk=None, par=None, container=None, torrentfile=None, torre
## we were given disk= par=
source = FileLib.ogGetPath (src=f'{disk} {par}', file=torrentfile)
dev_err = f'{disk} {par} {torrentfile}'
print (f'nati ogGetPath (src=({disk} {par}), file=({torrentfile})) = source ({source})')
elif disk is None and par is None:
## we were given nothing
if torrentfile.startswith ('/opt/opengnsys/images'):
@ -710,7 +674,6 @@ def ogTorrentStart (disk=None, par=None, container=None, torrentfile=None, torre
return None
source = FileLib.ogGetPath (file=torrentfile)
dev_err = torrentfile
print (f'nati ogGetPath (file=({torrentfile})) = source ({source})')
else:
raise TypeError ('if one of "disk" and "par" are specified, then both must be')
@ -825,7 +788,6 @@ def ogCreateTorrent (disk=None, par=None, container=None, file=None, ip_bttrack=
return
f = f'{file}.{ext}'
source = FileLib.ogGetPath (src=container, file=f)
print (f'nati ogGetPath (src=({container}), file=({f})) = source ({source})')
else:
raise TypeError ('argument "container" can be specified along neither "disk" nor "par"')
@ -834,12 +796,10 @@ def ogCreateTorrent (disk=None, par=None, container=None, file=None, ip_bttrack=
## we were given disk= par=
f = f'{file}.img'
source = FileLib.ogGetPath (src=f'{disk} {par}', file=f)
print (f'nati ogGetPath (src=({disk} {par}), file=({f})) = source ({source})')
elif disk is None and par is None:
## we were given nothing
f = f'{file}.img'
source = FileLib.ogGetPath (file=f)
print (f'nati ogGetPath (file=({f})) = source ({source})')
else:
raise TypeError ('if one of "disk" and "par" are specified, then both must be')
@ -890,14 +850,12 @@ def ogUpdateCacheIsNecesary (repo, file, proto):
return None
filesource = FileLib.ogGetPath (src=repo, file=file)
#print (f'nati filesource ({filesource})')
if not filesource:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f' {repo} {file}')
return None
# paso 1. si no existe la imagen, confirmar que es necesario actualizar la cache.
filetarget = FileLib.ogGetPath (src='CACHE', file=file)
#print (f'nati filetarget ({filetarget})')
if not filetarget:
# borramos el fichero bf del torrent, en el caso de que se hubiese quedado de algun proceso fallido
if FileLib.ogGetPath (src='CACHE', file=f'/{file}.torrent.bf'): ogDeleteFile (container='CACHE', file=f'{file}.torrent.bf')

View File

@ -19,10 +19,8 @@ import FileLib
# Función ficticia para lanzar chntpw con timeout de 5 s., evitando cuelgues del programa.
chntpw_exe = shutil.which ('drbl-chntpw') or shutil.which ('chntpw')
def chntpw (hivefile, input_file):
#print (f'nati: hivefile ({hivefile}) input_file ({input_file}) type ({type(input_file)})')
with open (input_file, 'r') as fd:
input_contents = fd.read()
#print (f'nati: input_contents ({input_contents})')
return subprocess.run ([chntpw_exe, '-e', hivefile], timeout=5, input=input_contents, capture_output=True, text=True).stdout
## en el codigo bash aparecen "${3%\\*}" y "${3##*\\}" varias veces

View File

@ -108,29 +108,18 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs):
if 'command' in logtypes:
os.unlink (ogGlobals.OGLOGCOMMAND)
open (ogGlobals.OGLOGCOMMAND, 'w').close()
#print ('nati: ogExecAndLog: about to redirect stdout and stderr')
#time.sleep (1) ## nati
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()
#print (f'nati: ogExecAndLog: end of redirections, rc ({rc}) sout ({sout}) serr ({serr})')
#time.sleep (1) ## nati
else:
#print ('nati: ogExecAndLog: about to redirect stdout only')
#time.sleep (1) ## nati
with redirect_stdout (StringIO()) as r_stdout:
rc = fun (*args, **kwargs)
sout = r_stdout.getvalue()
#print (f'nati: ogExecAndLog: end of redirections, rc ({rc}) sout ({sout})')
#time.sleep (1) ## nati
rc_str = str (rc)
if sout or serr or ('True' != rc_str and 'False' != rc_str and 'None' != rc_str):
#print ('nati: ogExecAndLog: sout or serr are true')
#time.sleep (1) ## nati
for f in logfiles:
#print (f'nati: ogExecAndLog: logging to logfile ({f})')
with open (f, 'a') as fd:
if sout: fd.write (f'{sout}\n')
if serr: fd.write (f'{serr}\n')
@ -141,7 +130,6 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs):
#if serr: fd.write (f"ogExecAndLog: {fun.__name__} stderr:\n{serr}\n")
#else: fd.write (f"ogExecAndLog: {fun.__name__} stderr: (none)\n")
#print (f'nati: ogExecAndLog: returning rc ({rc})')
return rc
#/**
@ -265,7 +253,6 @@ def ogRaiseError (logtypes, code, msg):
if code == ogGlobals.OG_ERR_FORMAT or \
(str_call_stack in ogGlobals.NODEBUGFUNCTIONS) or \
not (len(call_stack)>0 and (call_stack[0] in ogGlobals.NODEBUGFUNCTIONS)):
#print ('nati: ogRaiseError: actually calling ogEcho')
ogEcho (logtypes, "error", f"{str_call_stack.replace(' ', '<-')}: {MSG}")
return code

View File

@ -47,8 +47,9 @@ def main (NDISK, NPART, SIZE, MOUNT):
if SIZE != CACHESIZE:
print("[10] Crear partición de caché local.")
CacheLib.ogUnmountCache()
print (f'nati: calling ogCreateCache ({NDISK}, {NPART}, {SIZE})')
CacheLib.ogCreateCache (NDISK, NPART, SIZE)
if not CacheLib.ogCreateCache (NDISK, NPART, SIZE):
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_CACHE, 'failed to create cache')
return False
DiskLib.ogUpdatePartitionTable()
# Si caché no montada y no formateada o cambia el tamaño: formatear.
@ -104,23 +105,19 @@ if __name__ == "__main__":
NPART = int (args[1])
SIZE = int (args[2])
else:
print (f'nati: params no es ni 1 ni 2 ni 3 sino ({PARAMS})')
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, EXECFORMAT)
sys.exit (1)
except ValueError:
print (f'nati: ValueError')
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, EXECFORMAT)
sys.exit (1)
# Si disco o partición no son mayores o iguales que 1, error.
if NDISK < 1 or NPART < 1:
print (f'nati: ndisk<1 or npart<1, ({NDISK}) ({NPART})')
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, EXECFORMAT)
sys.exit (1)
# Si tamaño no es numérico o tamaño<-1, error.
if SIZE < -1:
print (f'nati: SIZE<-1 ({SIZE})')
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, EXECFORMAT)
sys.exit (1)

View File

@ -144,7 +144,6 @@ if sizerequired >= cachesizefree:
sys.exit (1)
# Comprobamos que imagen cache igual a la del repo. Si sincronizada no podemos comprobar.
## nati: esto ya lo hicimos mas arriba...
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