From f46dc98e0801f567dfe76c2c1a719f085a0ea98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Jodogne?= Date: Wed, 22 Nov 2023 16:33:05 +0100 Subject: [PATCH] creating new generator of macOS packages --- UCLouvain/CreateMacOSPackage.py | 99 +++++++++++++++++++++++++++++++++ build-matrix.json | 30 ++++++++-- 2 files changed, 123 insertions(+), 6 deletions(-) create mode 100755 UCLouvain/CreateMacOSPackage.py diff --git a/UCLouvain/CreateMacOSPackage.py b/UCLouvain/CreateMacOSPackage.py new file mode 100755 index 00000000..c9052f58 --- /dev/null +++ b/UCLouvain/CreateMacOSPackage.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 + +# Orthanc - A Lightweight, RESTful DICOM Store +# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics +# Department, University Hospital of Liege, Belgium +# Copyright (C) 2017-2023 Osimis S.A., Belgium +# Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program. If not, see +# . + + +import json +import os +import requests +import sys +import time +import zipfile + +if len(sys.argv) != 3: + print('Usage: %s [target ZIP] [version]' % sys.argv[0]) + print('Example: %s /tmp/macos.zip 23.11.0' % sys.argv[0]) + exit(-1) + +TARGET = sys.argv[1] +PREFIX = 'Orthanc-OSX-%s' % sys.argv[2] + + +def AddContentToZip(archive, content, targetPath, isExecutable): + info = zipfile.ZipInfo(os.path.join(PREFIX, targetPath)) + info.date_time = time.localtime() + + if isExecutable: + info.external_attr = 0o100755 << 16 # -rwxr-xr-x permissions (755 in octal) + else: + info.external_attr = 0o100644 << 16 # -rw-r--r-- permissions (644 in octal) + + archive.writestr(info, content) + + +def AddFile(archive, sourcePath, targetPath = None, isExecutable = False): + if targetPath == None: + targetPath = os.path.basename(sourcePath) + + with open(os.path.join(BASE, sourcePath), 'rb') as f: + AddContentToZip(archive, f.read(), targetPath, isExecutable) + + +def DownloadFile(archive, url, targetPath = None, isExecutable = False): + if targetPath == None: + targetPath = url.split('/') [-1] + + print(' downloading: %s' % url) + r = requests.get(url) + r.raise_for_status() + AddContentToZip(archive, r.content, targetPath, isExecutable) + + +BASE = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..') + + +with open(os.path.join(BASE, 'build-matrix.json')) as f: + matrix = json.loads(f.read()) + + +with zipfile.ZipFile(TARGET, 'w') as archive: + AddFile(archive, 'orthancBuildResources/readmeOSX.txt', 'readme.txt') + AddFile(archive, 'orthancBuildResources/configOSX.json') + AddFile(archive, 'orthancBuildResources/startOrthanc.command', isExecutable = True) + AddFile(archive, 'WindowsInstaller/Resources/ca-certificates.crt') + + for project in matrix['configs']: + if project['name'].startswith('XXXX'): # This is a documentation + continue + + if not 'downloadsOSX' in project: + print('Skipping project without macOS binaries: %s' % project['name']) + continue + + version = project['stable'].split('-') [-1] + + for f in project['downloadsOSX']: + if isinstance(f, str): + url = f.replace('${VERSION}', version) + DownloadFile(archive, url) + else: + url = f['url'].replace('${VERSION}', version) + DownloadFile(archive, url, f.get('target', None), f.get('executable', False)) diff --git a/build-matrix.json b/build-matrix.json index ffb9f119..65598d4d 100644 --- a/build-matrix.json +++ b/build-matrix.json @@ -294,7 +294,10 @@ "Resources": [ ["indexer.json", "Configuration"] ] - }] + }], + "downloadsOSX" : [ + "https://orthanc.uclouvain.be/downloads/macos/orthanc-indexer/OrthancIndexer-${VERSION}.dylib" + ] }, { "name": "Orthanc-tcia", @@ -319,7 +322,10 @@ "Resources": [ ["tcia.json", "Configuration"] ] - }] + }], + "downloadsOSX" : [ + "https://orthanc.uclouvain.be/downloads/macos/orthanc-tcia/OrthancTcia-${VERSION}.dylib" + ] }, { "name": "Orthanc-python", @@ -727,7 +733,10 @@ "Resources": [ ["orthanc-explorer-2.json", "Configuration"] ] - }] + }], + "downloadsOSX" : [ + "https://orthanc.uclouvain.be/downloads/macos/orthanc-explorer-2/OrthancExplorer2-${VERSION}.dylib" + ] }, { "name": "osimis-viewer", @@ -779,7 +788,10 @@ ], "Resources": [ ] - }] + }], + "downloadsOSX" : [ + "https://orthanc.uclouvain.be/downloads/macos/orthanc-neuro/OrthancNeuro-${VERSION}.dylib" + ] }, { "name": "Orthanc-volview", @@ -805,7 +817,10 @@ ], "Resources": [ ] - }] + }], + "downloadsOSX" : [ + "https://orthanc.uclouvain.be/downloads/macos/orthanc-volview/OrthancVolView-${VERSION}.dylib" + ] }, { "name": "Orthanc-ohif", @@ -831,7 +846,10 @@ ], "Resources": [ ] - }] + }], + "downloadsOSX" : [ + "https://orthanc.uclouvain.be/downloads/macos/orthanc-ohif/OrthancOHIF-${VERSION}.dylib" + ] } ]