changeset 83:16e247e407d9

improvements to sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Oct 2015 18:30:25 +0200
parents 56a016ae8090
children 581937911d14
files Resources/SyncOrthancFolder.py
diffstat 1 files changed, 39 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/SyncOrthancFolder.py	Fri Oct 09 17:38:27 2015 +0200
+++ b/Resources/SyncOrthancFolder.py	Fri Oct 09 18:30:25 2015 +0200
@@ -5,15 +5,14 @@
 # to match the latest version of the Orthanc source code.
 #
 
+import multiprocessing
 import os
-import shutil
+import stat
 import urllib2
 
+TARGET = os.path.join(os.path.dirname(__file__), '..', 'Orthanc')
 PLUGIN_SDK_VERSION = '0.9.4'
-
-SOURCE = '/home/jodogne/Subversion/Orthanc'
-TARGET = os.path.join(os.path.dirname(__file__), '..', 'Orthanc')
-REPOSITORY = 'https://bitbucket.org/sjodogne/orthanc/raw/Orthanc-%s/Plugins/Include' % PLUGIN_SDK_VERSION
+REPOSITORY = 'https://bitbucket.org/sjodogne/orthanc/raw'
 
 FILES = [
     'Core/ChunkedBuffer.cpp',
@@ -80,23 +79,46 @@
     'orthanc/OrthancCPlugin.h',
 ]   
 
-for f in FILES:
-    source = os.path.join(SOURCE, f)
-    target = os.path.join(TARGET, f)
+EXE = [
+    'Resources/EmbedResources.py',
+    'Resources/WindowsResources.py',
+]
+
+
+def Download(x):
+    branch = x[0]
+    source = x[1]
+    target = os.path.join(TARGET, x[2])
+    print target
+
     try:
         os.makedirs(os.path.dirname(target))
     except:
         pass
 
-    shutil.copy(source, target)
+    url = '%s/%s/%s' % (REPOSITORY, branch, source)
+
+    with open(target, 'w') as f:
+        f.write(urllib2.urlopen(url).read())
+
+
+commands = []
+
+for f in FILES:
+    commands.append([ 'default', f, f ])
 
 for f in SDK:
-    source = '%s/%s' % (REPOSITORY, f)
-    target = os.path.join(TARGET, 'Sdk-%s' % PLUGIN_SDK_VERSION, f)
-    try:
-        os.makedirs(os.path.dirname(target))
-    except:
-        pass
+    commands.append([ 'Orthanc-%s' % PLUGIN_SDK_VERSION, 
+                      'Plugins/Include/%s' % f,
+                      'Sdk-%s/%s' % (PLUGIN_SDK_VERSION, f) ])
+
 
-    with open(target, 'w') as g:
-        g.write(urllib2.urlopen(source).read())
+pool = multiprocessing.Pool(10)  # simultaneous downloads
+pool.map(Download, commands)
+
+
+for exe in EXE:
+    path = os.path.join(TARGET, exe)
+    st = os.stat(path)
+    os.chmod(path, st.st_mode | stat.S_IEXEC)
+