Explorar o código

Adding doReload option to loadLibrary (the point being not to reload unless the library is missing)

Andrej Studen %!s(int64=3) %!d(string=hai) anos
pai
achega
a31392dc25
Modificáronse 1 ficheiros con 13 adicións e 9 borrados
  1. 13 9
      wrapper/nixWrapper.py

+ 13 - 9
wrapper/nixWrapper.py

@@ -56,7 +56,19 @@ def loadModule(slicer,qt,name,moduleName):
     slicer.util.selectModule(moduleName)
 
 
-def loadLibrary(name):
+def loadLibrary(name,doReload=True):
+
+    installDir=getSuitePath()
+    finalName=os.path.join(installDir,name)
+    if os.path.isdir(finalName):
+        if not doReload:
+            #1 keep existing copy, return
+            sys.path.append(finalName)
+            return
+        else:
+            #1 remove existing copy
+            shutil.rmtree(finalName)
+    
     #load library from git, store it at a default location and 
     #add path to the python sys
     remoteSources=getResources()
@@ -84,14 +96,6 @@ def loadLibrary(name):
     r.release_conn()
     
     #2 Unzip
-    installDir=getSuitePath()
-
-    #3 remove existing copy
-    finalName=os.path.join(installDir,name)
-    if os.path.isdir(finalName):
-        shutil.rmtree(finalName)
-
-    #unzip
     with zipfile.ZipFile(tempFile,'r') as zip_ref:
         zip_ref.extractall(installDir)