Commit 6c61d952 authored by Paal Kvamme's avatar Paal Kvamme
Browse files

Expose the verid attribute as a stringized UUID in OpenZGY/Python and the zgydump tool.

parent 81c76655
Pipeline #30550 passed with stages
in 6 minutes and 33 seconds
......@@ -360,6 +360,43 @@ class ZgyMeta:
"""
return self._meta._ih._nlods
@staticmethod
def _formatUUID(uuid):
"""
Convert a little-endian binary UUID to a big-endian string version.
See the C++ version for details.
First part byteswaps as an uint32_t.
Second and third part byteswaps as two uint16_t.
Remaining two parts are not byteswapped.
Hyphens added between parts.
"""
return ("{3:02x}{2:02x}{1:02x}{0:02x}-" +
"{5:02x}{4:02x}-{7:02x}{6:02x}-" +
"{8:02x}{9:02x}-" +
"{10:02x}{11:02x}{12:02x}{13:02x}{14:02x}{15:02x}").format(*uuid)
#@property
#def dataid(self):
# """
# GUID set on file creation.
# """
# return self._formatUUID(self._meta._ih._dataid)
@property
def verid(self):
"""
GUID set each time the file is changed.
"""
return self._formatUUID(self._meta._ih._verid)
#@property
#def previd(self):
# """
# GUID before last change.
# """
# return self._formatUUID(self._meta._ih._previd)
@property
def meta(self):
"""
......
......@@ -1439,8 +1439,15 @@ class ZgyInternalMeta:
# Meta information that might be updated after creation.
# Except for dataid.
ih._dataid = bytes([random.randint(0,255) for i in range(16)])
ih._verid = bytes([random.randint(0,255) for i in range(16)])
def makeUUID():
# See the C++ version for details.
# TODO-Worry: Is the entropy of the random seed good enough?
uuid = bytearray([random.randint(0,255) for i in range(16)])
uuid[8] = (uuid[8] & 0x3f) | 0x80 # variant 1 (DCE)
uuid[7] = (uuid[7] & 0x0f) | 0x40 # version 4 (random)
return uuid
ih._dataid = makeUUID()
ih._verid = makeUUID()
ih._previd = bytes(16)
ih._srcname = ""
ih._srcdesc = ""
......
......@@ -10,6 +10,7 @@ _brief_info = """
File name = '{name}'
File size (bytes) = {r._fd.xx_eof:,d}
File format and version = {r.datatype.name} ZGY version {r._accessor._metadata._fh._version}
Current data Version = {r.verid}
Brick size I,J,K = {r.bricksize}
Number of bricks I,J,K = {r.brickcount[0]}
Number of LODs = {r.nlods}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment