annotate Resources/SyncOrthancFolder.py @ 47:28956ed68280

agpl license
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Apr 2017 11:00:15 +0200
parents 981f0257e080
children d20e25cfcf3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 #
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # This maintenance script updates the content of the "Orthanc" folder
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # to match the latest version of the Orthanc source code.
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 import sys
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 import multiprocessing
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 import os
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 import stat
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 import urllib2
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13
16
ff1e935768e7 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 15
diff changeset
14 TARGET = os.path.join(os.path.dirname(__file__), 'Orthanc')
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 REPOSITORY = 'https://bitbucket.org/sjodogne/orthanc/raw'
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 FILES = [
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 'Core/ChunkedBuffer.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 'Core/ChunkedBuffer.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 'Core/Compression/DeflateBaseCompressor.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 'Core/Compression/DeflateBaseCompressor.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 'Core/Compression/GzipCompressor.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 'Core/Compression/GzipCompressor.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 'Core/Compression/IBufferCompressor.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 'Core/Enumerations.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 'Core/Enumerations.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 'Core/HttpClient.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 'Core/HttpClient.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 'Core/Images/Image.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 'Core/Images/Image.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 'Core/Images/ImageAccessor.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 'Core/Images/ImageAccessor.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 'Core/Images/ImageBuffer.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 'Core/Images/ImageBuffer.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 'Core/Images/ImageProcessing.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 'Core/Images/ImageProcessing.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 'Core/Images/JpegErrorManager.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 'Core/Images/JpegErrorManager.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 'Core/Images/JpegReader.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 'Core/Images/JpegReader.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 'Core/Images/PngReader.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 'Core/Images/PngReader.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 'Core/Logging.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 'Core/Logging.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 'Core/OrthancException.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 'Core/PrecompiledHeaders.h',
15
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
47 'Core/SystemToolbox.cpp',
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
48 'Core/SystemToolbox.h',
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 'Core/Toolbox.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 'Core/Toolbox.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 'Core/WebServiceParameters.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 'Core/WebServiceParameters.h',
31
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
53 'Plugins/Samples/Common/DicomDatasetReader.cpp',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
54 'Plugins/Samples/Common/DicomDatasetReader.h',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
55 'Plugins/Samples/Common/DicomPath.cpp',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
56 'Plugins/Samples/Common/DicomPath.h',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
57 'Plugins/Samples/Common/DicomTag.cpp',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
58 'Plugins/Samples/Common/DicomTag.h',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
59 'Plugins/Samples/Common/FullOrthancDataset.cpp',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
60 'Plugins/Samples/Common/FullOrthancDataset.h',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
61 'Plugins/Samples/Common/IDicomDataset.h',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
62 'Plugins/Samples/Common/IOrthancConnection.cpp',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
63 'Plugins/Samples/Common/IOrthancConnection.h',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
64 'Plugins/Samples/Common/OrthancHttpConnection.cpp',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
65 'Plugins/Samples/Common/OrthancHttpConnection.h',
9aace933cb64 sharing code with the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
66 'Plugins/Samples/Common/OrthancPluginException.h',
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 'Resources/CMake/AutoGeneratedCode.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 'Resources/CMake/BoostConfiguration.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 'Resources/CMake/Compiler.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 'Resources/CMake/DownloadPackage.cmake',
20
946377d1c992 skeleton for unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
71 'Resources/CMake/GoogleTestConfiguration.cmake',
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 'Resources/CMake/JsonCppConfiguration.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 'Resources/CMake/LibCurlConfiguration.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 'Resources/CMake/LibIconvConfiguration.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 'Resources/CMake/LibJpegConfiguration.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 'Resources/CMake/LibPngConfiguration.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 'Resources/CMake/OpenSslConfiguration.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 'Resources/CMake/ZlibConfiguration.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 'Resources/EmbedResources.py',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 'Resources/MinGW-W64-Toolchain32.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 'Resources/MinGW-W64-Toolchain64.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 'Resources/MinGWToolchain.cmake',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 'Resources/ThirdParty/VisualStudio/stdint.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 'Resources/ThirdParty/base64/base64.cpp',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 'Resources/ThirdParty/base64/base64.h',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 'Resources/ThirdParty/patch/msys-1.0.dll',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 'Resources/ThirdParty/patch/patch.exe',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 'Resources/ThirdParty/patch/patch.exe.manifest',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 'Resources/WindowsResources.py',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 'Resources/WindowsResources.rc',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 ]
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 EXE = [
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 'Resources/WindowsResources.py',
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 ]
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 def Download(x):
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 branch = x[0]
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 source = x[1]
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 target = os.path.join(TARGET, x[2])
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 print target
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 try:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 os.makedirs(os.path.dirname(target))
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 except:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 pass
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
23
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
109 url = '%s/%s/%s' % (REPOSITORY, branch, source)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 with open(target, 'w') as f:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 f.write(urllib2.urlopen(url).read())
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 commands = []
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 for f in FILES:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 commands.append([ 'default', f, f ])
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 if sys.platform == 'win32':
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 # Sequential execution
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 for c in commands:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 Download(c)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 else:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 # Concurrent downloads
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 pool = multiprocessing.Pool(10)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 pool.map(Download, commands)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 for exe in EXE:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 path = os.path.join(TARGET, exe)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 st = os.stat(path)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 os.chmod(path, st.st_mode | stat.S_IEXEC)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135