Skip to content

Commit

Permalink
creating new generator of macOS packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jodogne committed Nov 22, 2023
1 parent 8ee000e commit f46dc98
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 6 deletions.
99 changes: 99 additions & 0 deletions UCLouvain/CreateMacOSPackage.py
Original file line number Diff line number Diff line change
@@ -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
# <http://www.gnu.org/licenses/>.


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))
30 changes: 24 additions & 6 deletions build-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@
"Resources": [
["indexer.json", "Configuration"]
]
}]
}],
"downloadsOSX" : [
"https://orthanc.uclouvain.be/downloads/macos/orthanc-indexer/OrthancIndexer-${VERSION}.dylib"
]
},
{
"name": "Orthanc-tcia",
Expand All @@ -319,7 +322,10 @@
"Resources": [
["tcia.json", "Configuration"]
]
}]
}],
"downloadsOSX" : [
"https://orthanc.uclouvain.be/downloads/macos/orthanc-tcia/OrthancTcia-${VERSION}.dylib"
]
},
{
"name": "Orthanc-python",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -779,7 +788,10 @@
],
"Resources": [
]
}]
}],
"downloadsOSX" : [
"https://orthanc.uclouvain.be/downloads/macos/orthanc-neuro/OrthancNeuro-${VERSION}.dylib"
]
},
{
"name": "Orthanc-volview",
Expand All @@ -805,7 +817,10 @@
],
"Resources": [
]
}]
}],
"downloadsOSX" : [
"https://orthanc.uclouvain.be/downloads/macos/orthanc-volview/OrthancVolView-${VERSION}.dylib"
]
},
{
"name": "Orthanc-ohif",
Expand All @@ -831,7 +846,10 @@
],
"Resources": [
]
}]
}],
"downloadsOSX" : [
"https://orthanc.uclouvain.be/downloads/macos/orthanc-ohif/OrthancOHIF-${VERSION}.dylib"
]
}
]

Expand Down

0 comments on commit f46dc98

Please sign in to comment.