refs #1101 improve ogGetImageInfo() a bit
parent
79c1ab34c0
commit
b668a526b0
|
@ -149,7 +149,7 @@ def ogRestoreImageSyntax (imgfile, part, tool=None, level=None):
|
||||||
'bzip': ' bzip -dc ',
|
'bzip': ' bzip -dc ',
|
||||||
}.get (level, '')
|
}.get (level, '')
|
||||||
print (f'tool ({tool}) level ({level}) compressor ({compressor})')
|
print (f'tool ({tool}) level ({level}) compressor ({compressor})')
|
||||||
if compressor is '':
|
if compressor == '':
|
||||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'Compressor no valid {level}')
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'Compressor no valid {level}')
|
||||||
## original bash code is broken: 'return' is never called
|
## original bash code is broken: 'return' is never called
|
||||||
#return
|
#return
|
||||||
|
@ -213,22 +213,38 @@ def ogGetImageInfo (imgfile):
|
||||||
lc_all = os.getenv ('LC_ALL')
|
lc_all = os.getenv ('LC_ALL')
|
||||||
os.environ['LC_ALL'] = 'C'
|
os.environ['LC_ALL'] = 'C'
|
||||||
partclone_info = subprocess.run (['partclone.info', filehead], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True).stdout
|
partclone_info = subprocess.run (['partclone.info', filehead], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True).stdout
|
||||||
|
#partclone_info = subprocess.run (['cat', '/tmp/foo-partclone'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True).stdout
|
||||||
|
#Partclone v0.3.13 http://partclone.org
|
||||||
|
#Unknown mode
|
||||||
|
#File system: NTFS
|
||||||
|
#Device size: 29.2 GB = 7138019 Blocks
|
||||||
|
#Space in use: 26.6 GB = 6485355 Blocks
|
||||||
|
#Free Space: 2.7 GB = 652664 Blocks
|
||||||
|
#Block size: 4096 Byte
|
||||||
|
#
|
||||||
|
#image format: 0002
|
||||||
|
#created on a: 64 bits platform
|
||||||
|
#with partclone: v0.3.13
|
||||||
|
#bitmap mode: BIT
|
||||||
|
#checksum algo: CRC32
|
||||||
|
#checksum size: 4
|
||||||
|
#blocks/checksum: 256
|
||||||
if lc_all is not None:
|
if lc_all is not None:
|
||||||
os.environ["LC_ALL"] = lc_all
|
os.environ["LC_ALL"] = lc_all
|
||||||
else:
|
else:
|
||||||
del os.environ["LC_ALL"]
|
del os.environ["LC_ALL"]
|
||||||
|
|
||||||
if 'size' in partclone_info:
|
if 'size' in partclone_info:
|
||||||
tools = 'PARTCLONE'
|
tools = 'PARTCLONE'
|
||||||
sizefactor = 1000000 if 'GB' in partclone_info else 1024
|
sizefactor = 1000000 if 'GB' in partclone_info else 1024
|
||||||
fs_lines = list (filter (lambda l: 'File system' in l, partclone_info.splitlines()))
|
m = re.search (r'File system *: *(\S+)', partclone_info)
|
||||||
fs = fs_lines[0].split (':')[1].strip()
|
fs = m.group(1) if m else ''
|
||||||
if fs in ['HFS', 'HFSPLUS', 'FAT32']:
|
if fs in ['HFS', 'HFSPLUS', 'FAT32']:
|
||||||
## TODO
|
## TODO
|
||||||
#FSPLUS=$(echo $PARTCLONEINFO | awk '{gsub(/\: /,"\n"); print toupper($9);}')
|
#FSPLUS=$(echo $PARTCLONEINFO | awk '{gsub(/\: /,"\n"); print toupper($9);}')
|
||||||
#echo $PARTCLONEINFO | grep GB > /dev/null && SIZEFACTOR=1000000 || SIZEFACTOR=1024
|
|
||||||
fsplus = 'PLUS'
|
fsplus = 'PLUS'
|
||||||
if fsplus:
|
if fsplus:
|
||||||
fs += fsplus
|
fs += fsplus ## 'HFS' -> 'HFSPLUS'
|
||||||
size = 42
|
size = 42
|
||||||
else:
|
else:
|
||||||
size = 42
|
size = 42
|
||||||
|
@ -242,24 +258,51 @@ def ogGetImageInfo (imgfile):
|
||||||
|
|
||||||
if False == imgdetect and not os.path.exists ('/dev/loop2'):
|
if False == imgdetect and not os.path.exists ('/dev/loop2'):
|
||||||
filehead_contents = Path (filehead).read_bytes()
|
filehead_contents = Path (filehead).read_bytes()
|
||||||
|
ntfscloneinfo = ''
|
||||||
if b'ntfsclone-image' in filehead_contents:
|
if b'ntfsclone-image' in filehead_contents:
|
||||||
print (f'shelling out "cat {filenead} | ntfsclone --restore --overwrite /dev/loop2 - 2>&1"')
|
print (f'shelling out "cat {filenead} | ntfsclone --restore --overwrite /dev/loop2 - 2>&1"')
|
||||||
ntfscloneinfo = subprocess.run (f'cat {filenead} | ntfsclone --restore --overwrite /dev/loop2 - 2>&1', shell=True, capture_output=True, text=True).stdout
|
ntfscloneinfo = subprocess.run (f'cat {filenead} | ntfsclone --restore --overwrite /dev/loop2 - 2>&1', shell=True, capture_output=True, text=True).stdout
|
||||||
|
#ntfscloneinfo = subprocess.run (['cat', '/tmp/foo-ntfsclone'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True).stdout
|
||||||
|
|
||||||
if 'ntfsclone' in ntfscloneinfo:
|
if 'ntfsclone' in ntfscloneinfo:
|
||||||
tools = 'NTFSCLONE'
|
tools = 'NTFSCLONE'
|
||||||
size_lines = list (filter (lambda l: '__TODO__' in l, ntfscloneinfo.splitlines())) ## TODO
|
m = re.search (r'__TODO__ *: *(\S+)', ntfscloneinfo) ## TODO
|
||||||
size = 42 #int (size_lines[0].split (':')[1].strip()) ## TODO
|
size = 42 #float (m.group(1))/1000 if m else 0 ## TODO
|
||||||
fs = 'NTFS'
|
fs = 'NTFS'
|
||||||
imgdetect = True
|
imgdetect = True
|
||||||
|
|
||||||
if False == imgdetect:
|
if False == imgdetect:
|
||||||
partimageinfo = subprocess.run (['partimage', '-B', 'gui=no', 'imginfo', filehead], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True).stdout
|
partimageinfo = subprocess.run (['partimage', '-B', 'gui=no', 'imginfo', filehead], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True).stdout
|
||||||
|
#partimageinfo = subprocess.run (['cat', '/tmp/foo-partimage'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True).stdout
|
||||||
|
#Volume number:.........0
|
||||||
|
#Volume size:...........1,27 MiB
|
||||||
|
#Compression level: ....0 -> ninguno
|
||||||
|
#Identificator:.........12442509728668372730=ACACACACCB9ECEFA
|
||||||
|
#Filesystem:............ntfs
|
||||||
|
#Description:...........Sin descripcion
|
||||||
|
#Original device:......./dev/nvme0n1p2
|
||||||
|
#Original filepath:.... stdout
|
||||||
|
#Flags:.................0: Bandera sin activar
|
||||||
|
#Creation date:.........Mon Nov 11 21:00:22 2024
|
||||||
|
#Partition size:........476,84 GiB
|
||||||
|
#Hostname:..............ING-LTR-083
|
||||||
|
#Compatible Version:....0.6.1
|
||||||
|
#Encryption algorithm:..0 -> ninguno
|
||||||
|
#MBR saved count:.......0
|
||||||
|
print (f'partimageinfo bef ({partimageinfo})')
|
||||||
|
partimageinfo = re.sub (r':\s*\.+', ' : ', partimageinfo)
|
||||||
|
print (f'partimageinfo aft ({partimageinfo})')
|
||||||
if 'Partition' in partimageinfo:
|
if 'Partition' in partimageinfo:
|
||||||
tools = 'TOOLS=PARTIMAGE'
|
tools = 'PARTIMAGE'
|
||||||
fs_lines = list (filter (lambda l: '__TODO__' in l, partimageinfo.splitlines())) ## TODO
|
m = re.search (r'Filesystem *: *(\S+)', partimageinfo)
|
||||||
fs = 'EXTFS' #fs_lines[0].split (':')[1].strip() ## TODO
|
fs = m.group(1).upper() if m else ''
|
||||||
size_lines = list (filter (lambda l: '__TODO__' in l, partimageinfo.splitlines())) ## TODO
|
|
||||||
size = 42 #int (size_lines[0].split (':')[1].strip()) ## TODO
|
m = re.search (r'Partition size *: *(\S+)', partimageinfo)
|
||||||
|
size = m.group(1) if m else ''
|
||||||
|
size = re.sub (r' [MGT]i?B$', '', size)
|
||||||
|
size = float (size.replace (',', '.'))
|
||||||
|
size = int (size*1024*1024)
|
||||||
|
|
||||||
imgdetect = True
|
imgdetect = True
|
||||||
if 'boot sector' in subprocess.run (['file', filehead], capture_output=True, text=True).stdout:
|
if 'boot sector' in subprocess.run (['file', filehead], capture_output=True, text=True).stdout:
|
||||||
tools = 'partclone.dd'
|
tools = 'partclone.dd'
|
||||||
|
@ -271,5 +314,5 @@ def ogGetImageInfo (imgfile):
|
||||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_IMAGE, f'Image format is not valid {imgfile}')
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_IMAGE, f'Image format is not valid {imgfile}')
|
||||||
return
|
return
|
||||||
|
|
||||||
compressor = compressor.lower()
|
compressor = compressor.upper()
|
||||||
return ':'.join ([tools, compressor, fs, str (size)])
|
return ':'.join ([tools, compressor, fs, str (size)])
|
||||||
|
|
Loading…
Reference in New Issue