Mercurial > hg > orthanc-stone
annotate Resources/SyncOrthancFolder.py @ 254:abc1c6231947 am-2
cleanup
author | am@osimis.io |
---|---|
date | Tue, 03 Jul 2018 11:49:02 +0200 |
parents | 5412adf19980 |
children | 8e5f69c94fea |
rev | line source |
---|---|
200
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 # |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 # This maintenance script updates the content of the "Orthanc" folder |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 # to match the latest version of the Orthanc source code. |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 # |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 import multiprocessing |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 import os |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 import stat |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 import urllib2 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 TARGET = os.path.join(os.path.dirname(__file__), 'Orthanc') |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 REPOSITORY = 'https://bitbucket.org/sjodogne/orthanc/raw' |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 FILES = [ |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
17 'DownloadOrthancFramework.cmake', |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
18 'LinuxStandardBaseToolchain.cmake', |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
19 'MinGW-W64-Toolchain32.cmake', |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
20 'MinGW-W64-Toolchain64.cmake', |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
21 'MinGWToolchain.cmake', |
200
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 ] |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 def Download(x): |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 branch = x[0] |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 source = x[1] |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 target = os.path.join(TARGET, x[2]) |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 print target |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 try: |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 os.makedirs(os.path.dirname(target)) |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 except: |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 pass |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 url = '%s/%s/%s' % (REPOSITORY, branch, source) |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
38 with open(target, 'w') as f: |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
39 f.write(urllib2.urlopen(url).read()) |
200
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 commands = [] |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 for f in FILES: |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
45 commands.append([ 'default', |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
46 os.path.join('Resources', f), |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
47 f ]) |
200
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
03afbee0cc7b
integration of Orthanc core into Stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 pool = multiprocessing.Pool(10) # simultaneous downloads |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
208
diff
changeset
|
50 pool.map(Download, commands) |