mirror of https://git.48k.eu/ogclient
src: cleanup ogGetImageInfo
Rename ogGetImageInfo to get_image_info. Move code from ogOperations.py to obtain image data into get_image_info.master
parent
34007857f6
commit
914bd993fc
|
|
@ -545,7 +545,7 @@ class OgLiveOperations:
|
||||||
if os.access(f'{image_path}', os.R_OK) == False:
|
if os.access(f'{image_path}', os.R_OK) == False:
|
||||||
raise OgError(f'Cannot access partclone image file {image_path}')
|
raise OgError(f'Cannot access partclone image file {image_path}')
|
||||||
|
|
||||||
image_info = ogGetImageInfo(image_path)
|
image_info = get_image_info(image_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if os.path.exists(image_path):
|
if os.path.exists(image_path):
|
||||||
os.unlink(image_path)
|
os.unlink(image_path)
|
||||||
|
|
@ -560,21 +560,6 @@ class OgLiveOperations:
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
try:
|
|
||||||
st = os.stat(image_path)
|
|
||||||
size = st.st_size
|
|
||||||
perms = st.st_mode & (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
|
|
||||||
mtime = int(st.st_mtime)
|
|
||||||
except:
|
|
||||||
logging.info(f'cannot retrieve stats from {image_path}')
|
|
||||||
size = 0
|
|
||||||
perms = 0
|
|
||||||
mtime = 0
|
|
||||||
|
|
||||||
image_info.size = size
|
|
||||||
image_info.perms = perms
|
|
||||||
image_info.mtime = mtime
|
|
||||||
|
|
||||||
if self._write_md5_file(f'/opt/opengnsys/images/{name}.img') == -1:
|
if self._write_md5_file(f'/opt/opengnsys/images/{name}.img') == -1:
|
||||||
raise OgError(f'Cannot write {name}.full.sum file')
|
raise OgError(f'Cannot write {name}.full.sum file')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ def run_lzop_partcloneinfo(image_path):
|
||||||
return p2_out
|
return p2_out
|
||||||
|
|
||||||
|
|
||||||
def ogGetImageInfo(image_path):
|
def get_image_info(image_path):
|
||||||
"""
|
"""
|
||||||
Obtain filesystem and device size information of an OpenGnsys partition
|
Obtain filesystem and device size information of an OpenGnsys partition
|
||||||
image.
|
image.
|
||||||
|
|
@ -116,7 +116,7 @@ def ogGetImageInfo(image_path):
|
||||||
|
|
||||||
Returns an ImageInfo object.
|
Returns an ImageInfo object.
|
||||||
|
|
||||||
>>> image_info = ogGetImageInfo('/opt/opengnsys/images/foobar.img')
|
>>> image_info = get_image_info('/opt/opengnsys/images/foobar.img')
|
||||||
>>> image_info.filesystem
|
>>> image_info.filesystem
|
||||||
>>> 'NTFS'
|
>>> 'NTFS'
|
||||||
>>> image_info.datasize
|
>>> image_info.datasize
|
||||||
|
|
@ -128,6 +128,15 @@ def ogGetImageInfo(image_path):
|
||||||
"""
|
"""
|
||||||
partclone_output = run_lzop_partcloneinfo(image_path)
|
partclone_output = run_lzop_partcloneinfo(image_path)
|
||||||
image_info = image_info_from_partclone(partclone_output)
|
image_info = image_info_from_partclone(partclone_output)
|
||||||
|
|
||||||
|
try:
|
||||||
|
st = os.stat(image_path)
|
||||||
|
self.size = st.st_size
|
||||||
|
self.perms = st.st_mode & (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
|
||||||
|
self.mtime = int(st.st_mtime)
|
||||||
|
except:
|
||||||
|
logging.info(f'cannot retrieve stats from {image_path}')
|
||||||
|
|
||||||
return image_info
|
return image_info
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue