Mercurial > hg > orthanc-stone
annotate Applications/Resources/SyncOrthancFolder.py @ 1666:1e6d3289b1ad
enable catching of exceptions in stone web viewer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Nov 2020 17:10:08 +0100 |
parents | 8c5f9864545f |
children | 9ac2a65d4172 |
rev | line source |
---|---|
1538
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
3 # Stone of Orthanc |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
5 # Department, University Hospital of Liege, Belgium |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
6 # Copyright (C) 2017-2020 Osimis S.A., Belgium |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
7 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
8 # This program is free software: you can redistribute it and/or |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
9 # modify it under the terms of the GNU Affero General Public License |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
10 # as published by the Free Software Foundation, either version 3 of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
11 # the License, or (at your option) any later version. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
12 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, but |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
14 # WITHOUT ANY WARRANTY; without even the implied warranty of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
16 # Affero General Public License for more details. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
17 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
18 # You should have received a copy of the GNU Affero General Public License |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
20 |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
21 |
1538
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 # |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 # This maintenance script updates the content of the "Orthanc" folder |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 # to match the latest version of the Orthanc source code. |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 # |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 import multiprocessing |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 import os |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 import stat |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 import urllib2 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 TARGET = os.path.join(os.path.dirname(__file__), 'Orthanc') |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 PLUGIN_SDK_VERSION = '1.0.0' |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 REPOSITORY = 'https://hg.orthanc-server.com/orthanc/raw-file' |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 FILES = [ |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 ('OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h', 'Plugins'), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 ('OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp', 'Plugins'), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 ('OrthancServer/Plugins/Samples/Common/OrthancPluginException.h', 'Plugins'), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 ('OrthancServer/Plugins/Samples/Common/ExportedSymbolsPlugins.list', 'Plugins'), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 ('OrthancServer/Plugins/Samples/Common/OrthancPluginsExports.cmake', 'Plugins'), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 ('OrthancServer/Plugins/Samples/Common/VersionScriptPlugins.map', 'Plugins'), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 ] |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 SDK = [ |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 'orthanc/OrthancCPlugin.h', |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 ] |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 def Download(x): |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 branch = x[0] |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 source = x[1] |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 target = os.path.join(TARGET, x[2]) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 print target |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 try: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 os.makedirs(os.path.dirname(target)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 except: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 pass |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 url = '%s/%s/%s' % (REPOSITORY, branch, source) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 with open(target, 'w') as f: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 f.write(urllib2.urlopen(url).read()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 commands = [] |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 for f in FILES: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 commands.append([ 'default', |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 f[0], |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 os.path.join(f[1], os.path.basename(f[0])) ]) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 for f in SDK: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 commands.append([ |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 'Orthanc-%s' % PLUGIN_SDK_VERSION, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 'Plugins/Include/%s' % f, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 'Sdk-%s/%s' % (PLUGIN_SDK_VERSION, f) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 ]) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 pool = multiprocessing.Pool(10) # simultaneous downloads |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 pool.map(Download, commands) |