view Resources/SyncOrthancFolder.py @ 18:61bcf35d4761

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 16 Nov 2016 12:18:53 +0100
parents ff1e935768e7
children 946377d1c992
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',
    'Resources/CMake/AutoGeneratedCode.cmake',
    'Resources/CMake/BoostConfiguration.cmake',
    'Resources/CMake/Compiler.cmake',
    'Resources/CMake/DownloadPackage.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)