view Resources/SyncOrthancFolder.py @ 2160:66ce58986217 legacy

closing legacy
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 27 Sep 2024 22:33:15 +0200
parents 981f0257e080
children d20e25cfcf3a
line wrap: on
line source

#!/usr/bin/python

#
# This maintenance script updates the content of the "Orthanc" folder
# to match the latest version of the Orthanc source code.
#

import sys
import multiprocessing
import os
import stat
import urllib2

TARGET = os.path.join(os.path.dirname(__file__), 'Orthanc')
REPOSITORY = 'https://bitbucket.org/sjodogne/orthanc/raw'

FILES = [
    'Core/ChunkedBuffer.cpp',
    'Core/ChunkedBuffer.h',
    'Core/Compression/DeflateBaseCompressor.cpp',
    'Core/Compression/DeflateBaseCompressor.h',
    'Core/Compression/GzipCompressor.cpp',
    'Core/Compression/GzipCompressor.h',
    'Core/Compression/IBufferCompressor.h',
    'Core/Enumerations.cpp',
    'Core/Enumerations.h',
    'Core/HttpClient.cpp',
    'Core/HttpClient.h',
    'Core/Images/Image.cpp',
    'Core/Images/Image.h',
    'Core/Images/ImageAccessor.cpp',
    'Core/Images/ImageAccessor.h',
    'Core/Images/ImageBuffer.cpp',
    'Core/Images/ImageBuffer.h',
    'Core/Images/ImageProcessing.cpp',
    'Core/Images/ImageProcessing.h',
    'Core/Images/JpegErrorManager.cpp',
    'Core/Images/JpegErrorManager.h',
    'Core/Images/JpegReader.cpp',
    'Core/Images/JpegReader.h',
    'Core/Images/PngReader.cpp',
    'Core/Images/PngReader.h',
    'Core/Logging.cpp',
    'Core/Logging.h',
    'Core/OrthancException.h',
    'Core/PrecompiledHeaders.h',
    'Core/SystemToolbox.cpp',
    'Core/SystemToolbox.h',
    'Core/Toolbox.cpp',
    'Core/Toolbox.h',
    'Core/WebServiceParameters.cpp',
    'Core/WebServiceParameters.h',
    'Plugins/Samples/Common/DicomDatasetReader.cpp',
    'Plugins/Samples/Common/DicomDatasetReader.h',
    'Plugins/Samples/Common/DicomPath.cpp',
    'Plugins/Samples/Common/DicomPath.h',
    'Plugins/Samples/Common/DicomTag.cpp',
    'Plugins/Samples/Common/DicomTag.h',
    'Plugins/Samples/Common/FullOrthancDataset.cpp',
    'Plugins/Samples/Common/FullOrthancDataset.h',
    'Plugins/Samples/Common/IDicomDataset.h',
    'Plugins/Samples/Common/IOrthancConnection.cpp',
    'Plugins/Samples/Common/IOrthancConnection.h',
    'Plugins/Samples/Common/OrthancHttpConnection.cpp',
    'Plugins/Samples/Common/OrthancHttpConnection.h',
    'Plugins/Samples/Common/OrthancPluginException.h',
    'Resources/CMake/AutoGeneratedCode.cmake',
    'Resources/CMake/BoostConfiguration.cmake',
    'Resources/CMake/Compiler.cmake',
    'Resources/CMake/DownloadPackage.cmake',
    'Resources/CMake/GoogleTestConfiguration.cmake',
    'Resources/CMake/JsonCppConfiguration.cmake',
    'Resources/CMake/LibCurlConfiguration.cmake',
    'Resources/CMake/LibIconvConfiguration.cmake',
    'Resources/CMake/LibJpegConfiguration.cmake',
    'Resources/CMake/LibPngConfiguration.cmake',
    'Resources/CMake/OpenSslConfiguration.cmake',
    'Resources/CMake/ZlibConfiguration.cmake',
    'Resources/EmbedResources.py',
    'Resources/MinGW-W64-Toolchain32.cmake',
    'Resources/MinGW-W64-Toolchain64.cmake',
    'Resources/MinGWToolchain.cmake',
    'Resources/ThirdParty/VisualStudio/stdint.h',
    'Resources/ThirdParty/base64/base64.cpp',
    'Resources/ThirdParty/base64/base64.h',
    'Resources/ThirdParty/patch/msys-1.0.dll',
    'Resources/ThirdParty/patch/patch.exe',
    'Resources/ThirdParty/patch/patch.exe.manifest',
    'Resources/WindowsResources.py',
    'Resources/WindowsResources.rc',
]

EXE = [
    'Resources/WindowsResources.py',
]


def Download(x):
    branch = x[0]
    source = x[1]
    target = os.path.join(TARGET, x[2])
    print target

    try:
        os.makedirs(os.path.dirname(target))
    except:
        pass

    url = '%s/%s/%s' % (REPOSITORY, branch, source)

    with open(target, 'w') as f:
        f.write(urllib2.urlopen(url).read())


commands = []

for f in FILES:
    commands.append([ 'default', f, f ])


if sys.platform == 'win32':
    # Sequential execution
    for c in commands:
        Download(c)
else:
    # Concurrent downloads
    pool = multiprocessing.Pool(10)
    pool.map(Download, commands)


for exe in EXE:
    path = os.path.join(TARGET, exe)
    st = os.stat(path)
    os.chmod(path, st.st_mode | stat.S_IEXEC)