Skip to content

Commit

Permalink
Improve compatability of python code.
Browse files Browse the repository at this point in the history
  • Loading branch information
benajamin authored and Benjamin Watts committed Aug 8, 2018
1 parent eacd2ae commit 1638bd6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions hdf_python/thumbnailInserter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import struct
import sys
import codecs

import xmltodict

Expand Down Expand Up @@ -45,31 +46,31 @@ def check_header(file, location, header):
"""Check if at the specified position The header of a hdf5 file is found"""
file.seek(location)
sig = file.read(8)
return int.from_bytes(sig, byteorder="big") == header
return int(codecs.encode(sig, 'hex'), 16) == header


def exists_header(file, location):
"""Check if at the specified position is a valid header"""
file.seek(location)
sig = file.read(8)
# Compare but ignore the two changeable byts
return int.from_bytes(sig, byteorder="big") & 0xffff0000ffffffff == MAGIC_HDF & 0xffff0000ffffffff
return int(codecs.encode(sig, 'hex'), 16) & 0xffff0000ffffffff == MAGIC_HDF & 0xffff0000ffffffff


def read_datablock_size(file, location):
"""Return the size of the datablock starting at location"""
# Advance 8 bytes to skip signature
file.seek(location + 8)
# Return the 8 byte long size
return int.from_bytes(file.read(8), byteorder="big")
return int(codecs.encode(file.read(8), 'hex'), 16)


def construct_xmp_file(imageFile, key_value_data):
"""Construct the xmp file based on the imageFile and key_value_data input"""
# Remove the quotes and leading b from the string
base64Image = base64.b64encode(imageFile.read()).decode('utf-8')
# Get the xmp template
path = os.path.dirname(os.path.abspath(__file__)) + "/template.xmp"
path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"template.xmp")

with open(path, "r") as xmpFile:
xmp = xmpFile.read()
Expand Down

0 comments on commit 1638bd6

Please sign in to comment.