annotate Resources/SyncOrthancFolder.py @ 9:ad4d62a9422d

back to mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 19 May 2023 13:32:58 +0200
parents 3f1cf4a8e31f
children 7f77ea98e42c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python3
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # SPDX-License-Identifier: GPL-3.0-or-later
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 # Kitware's VolView plugin for Orthanc
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 # Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 #
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # This program is free software: you can redistribute it and/or
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # modify it under the terms of the GNU General Public License as
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # published by the Free Software Foundation, either version 3 of the
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # License, or (at your option) any later version.
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 #
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # This program is distributed in the hope that it will be useful, but
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # General Public License for more details.
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 #
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # You should have received a copy of the GNU General Public License
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 # This maintenance script updates the content of the "Orthanc" folder
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 # to match the latest version of the Orthanc source code.
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 import multiprocessing
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 import os
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 import stat
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 import urllib.request
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 TARGET = os.path.join(os.path.dirname(__file__), 'Orthanc')
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 PLUGIN_SDK_VERSION = '1.0.0'
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 REPOSITORY = 'https://hg.orthanc-server.com/orthanc/raw-file'
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 FILES = [
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 ('OrthancFramework/Resources/CMake/AutoGeneratedCode.cmake', 'CMake'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 ('OrthancFramework/Resources/CMake/Compiler.cmake', 'CMake'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 ('OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake', 'CMake'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 ('OrthancFramework/Resources/CMake/DownloadPackage.cmake', 'CMake'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 ('OrthancFramework/Resources/EmbedResources.py', 'CMake'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 ('OrthancFramework/Resources/Toolchains/LinuxStandardBaseToolchain.cmake', 'Toolchains'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 ('OrthancFramework/Resources/Toolchains/MinGW-W64-Toolchain32.cmake', 'Toolchains'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 ('OrthancFramework/Resources/Toolchains/MinGW-W64-Toolchain64.cmake', 'Toolchains'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 ('OrthancFramework/Resources/Toolchains/MinGWToolchain.cmake', 'Toolchains'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 ('OrthancServer/Plugins/Samples/Common/ExportedSymbolsPlugins.list', 'Plugins'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 ('OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp', 'Plugins'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 ('OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h', 'Plugins'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 ('OrthancServer/Plugins/Samples/Common/OrthancPluginException.h', 'Plugins'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 ('OrthancServer/Plugins/Samples/Common/OrthancPluginsExports.cmake', 'Plugins'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 ('OrthancServer/Plugins/Samples/Common/VersionScriptPlugins.map', 'Plugins'),
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 ]
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 SDK = [
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 'orthanc/OrthancCPlugin.h',
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 ]
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 def Download(x):
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 branch = x[0]
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 source = x[1]
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 target = os.path.join(TARGET, x[2])
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 print(target)
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 try:
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 os.makedirs(os.path.dirname(target))
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 except:
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 pass
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 url = '%s/%s/%s' % (REPOSITORY, branch, source)
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 with open(target, 'wb') as f:
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 try:
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 f.write(urllib.request.urlopen(url).read())
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 except:
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 print('ERROR %s' % url)
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 raise
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 commands = []
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 for f in FILES:
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 commands.append([ 'default',
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 f[0],
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 os.path.join(f[1], os.path.basename(f[0])) ])
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 for f in SDK:
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 commands.append([
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 'Orthanc-%s' % PLUGIN_SDK_VERSION,
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 'Plugins/Include/%s' % f,
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 'Sdk-%s/%s' % (PLUGIN_SDK_VERSION, f)
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 ])
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 pool = multiprocessing.Pool(10) # simultaneous downloads
3f1cf4a8e31f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 pool.map(Download, commands)