# HG changeset patch # User Sebastien Jodogne # Date 1679484478 -3600 # Node ID 6002fc2c98cf215aa27b0feef55b9fe67b4456cb # Parent ad2fc4ec99fb1e5f7ab4ac98b89d39e5f4d86915 compatibility with Python 2.7 for our CIS diff -r ad2fc4ec99fb -r 6002fc2c98cf CMakeLists.txt --- a/CMakeLists.txt Wed Mar 22 11:51:32 2023 +0100 +++ b/CMakeLists.txt Wed Mar 22 12:27:58 2023 +0100 @@ -58,7 +58,7 @@ if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "system") if (ORTHANC_FRAMEWORK_USE_SHARED) include(FindBoost) - find_package(Boost COMPONENTS system) + find_package(Boost COMPONENTS system thread) if (NOT Boost_FOUND) message(FATAL_ERROR "Unable to locate Boost on this system") @@ -150,6 +150,7 @@ OUTPUT ${AUTOGENERATED_DIR}/StaticAssets.cpp COMMAND + ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Resources/EmbedStaticAssets.py ${CMAKE_SOURCE_DIR}/VolView/dist ${AUTOGENERATED_DIR}/StaticAssets.cpp diff -r ad2fc4ec99fb -r 6002fc2c98cf Resources/EmbedStaticAssets.py --- a/Resources/EmbedStaticAssets.py Wed Mar 22 11:51:32 2023 +0100 +++ b/Resources/EmbedStaticAssets.py Wed Mar 22 12:27:58 2023 +0100 @@ -22,12 +22,10 @@ import gzip import hashlib +import io import os import sys -if (sys.version_info < (3, 0)): - raise Exception('You must use Python 3.x to run this script') - if len(sys.argv) != 3: raise Exception('Usage: %s [source folder] [target C++]' % sys.argv[0]) @@ -43,9 +41,17 @@ column = 0 - for i in content: + for c in content: + + if sys.version_info < (3, 0): + # Python 2.7 + i = ord(c) + else: + # Python 3.x + i = c + if i < 32 or i >= 127 or i == ord('?'): - f.write('\\{0:03o}'.format(i)) # Octal formatting + f.write('\\{0:03o}'.format(i)) elif i in [ ord('"'), ord('\\') ]: f.write('\\' + chr(i)) else: @@ -96,8 +102,17 @@ with open(fullPath, 'rb') as source: content = source.read() - - EncodeFileAsCString(g, variable, gzip.compress(content)) + + if sys.version_info < (3, 0): + # Python 2.7 + fileobj = io.BytesIO() + gzip.GzipFile(fileobj=fileobj, mode='w').write(content) + compressed = fileobj.getvalue() + else: + # Python 3.x + compressed = gzip.compress(content) + + EncodeFileAsCString(g, variable, compressed) WriteChecksum(g, variable + '_md5', content) index[relativePath] = variable