annotate Resources/SyncOrthancFolder.py @ 132:4cf3c2bc119f

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Aug 2023 11:55:33 +0200
parents 461dfb859ac7
children cc0765aae484
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
132
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
1 #!/usr/bin/python3
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 #
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # This maintenance script updates the content of the "Orthanc" folder
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # to match the latest version of the Orthanc source code.
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 import multiprocessing
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 import os
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 import stat
132
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
11 import urllib.request
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 import subprocess
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 TARGET = os.path.join(os.path.dirname(__file__), 'Orthanc')
107
461dfb859ac7 upgrade to Orthanc SDK 1.10.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 100
diff changeset
15 PLUGIN_SDK_VERSION = '1.10.0'
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 REPOSITORY = 'https://hg.orthanc-server.com/orthanc/raw-file'
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 FILES = [
36
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
19 ('OrthancFramework/Resources/CMake/AutoGeneratedCode.cmake', 'CMake'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
20 ('OrthancFramework/Resources/CMake/Compiler.cmake', 'CMake'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
21 ('OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake', 'CMake'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
22 ('OrthancFramework/Resources/CMake/DownloadPackage.cmake', 'CMake'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
23
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
24 ('OrthancFramework/Resources/Toolchains/LinuxStandardBaseToolchain.cmake', 'Toolchains'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
25 ('OrthancFramework/Resources/Toolchains/MinGW-W64-Toolchain32.cmake', 'Toolchains'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
26 ('OrthancFramework/Resources/Toolchains/MinGW-W64-Toolchain64.cmake', 'Toolchains'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
27 ('OrthancFramework/Resources/Toolchains/MinGWToolchain.cmake', 'Toolchains'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
28
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
29 ('OrthancServer/Plugins/Samples/Common/ExportedSymbolsPlugins.list', 'Plugins'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
30 ('OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp', 'Plugins'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
31 ('OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h', 'Plugins'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
32 ('OrthancServer/Plugins/Samples/Common/OrthancPluginException.h', 'Plugins'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
33 ('OrthancServer/Plugins/Samples/Common/OrthancPluginsExports.cmake', 'Plugins'),
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
34 ('OrthancServer/Plugins/Samples/Common/VersionScriptPlugins.map', 'Plugins'),
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 ]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 SDK = [
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 'orthanc/OrthancCPlugin.h',
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 ]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 def Download(x):
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 branch = x[0]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 source = x[1]
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 target = os.path.join(TARGET, x[2])
132
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
46 print(target)
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 try:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 os.makedirs(os.path.dirname(target))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 except:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 pass
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 url = '%s/%s/%s' % (REPOSITORY, branch, source)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
132
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
55 with open(target, 'wb') as f:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
56 try:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
57 f.write(urllib.request.urlopen(url).read())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
58 except:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
59 print('ERROR %s' % url)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
60 raise
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 commands = []
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 for f in FILES:
36
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
66 commands.append([ 'default',
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
67 f[0],
fd58eb5749ed CMake simplification using DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
68 os.path.join(f[1], os.path.basename(f[0])) ])
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 for f in SDK:
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 commands.append([
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 'Orthanc-%s' % PLUGIN_SDK_VERSION,
41
393d2da0722a upgrade to Orthanc SDK 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
73 'OrthancServer/Plugins/Include/%s' % f,
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 'Sdk-%s/%s' % (PLUGIN_SDK_VERSION, f)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 ])
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 pool = multiprocessing.Pool(10) # simultaneous downloads
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 pool.map(Download, commands)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
41
393d2da0722a upgrade to Orthanc SDK 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
82 if False:
393d2da0722a upgrade to Orthanc SDK 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
83 # Patch the SDK
393d2da0722a upgrade to Orthanc SDK 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
84 subprocess.check_call([ 'patch', '-p0', '-i', os.path.join
393d2da0722a upgrade to Orthanc SDK 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
85 (os.path.abspath(os.path.dirname(__file__)),
393d2da0722a upgrade to Orthanc SDK 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
86 'OrthancCPlugin-%s.patch' % PLUGIN_SDK_VERSION) ],
393d2da0722a upgrade to Orthanc SDK 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
87 cwd = os.path.join(os.path.dirname(__file__),
393d2da0722a upgrade to Orthanc SDK 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
88 'Orthanc',
393d2da0722a upgrade to Orthanc SDK 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 36
diff changeset
89 'Sdk-%s' % PLUGIN_SDK_VERSION, 'orthanc'))