Explorar o código

Adding slicer dedicated setup with adjusted paths to control loaded modules and libraries

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

+ 27 - 0
wrapper/nixWrapper.py

@@ -135,7 +135,34 @@ def loadLibrary(name,doReload=True):
 
     
     sys.path.append(finalName)
+    updateSetup(name,finalName)
 
+def updateSetup(name,path):
+
+    #update setup.json
+    #set paths[name]=finalName
+    #for use in slicer, use .labkey/slicer/setup.json
+    setupDir=os.path.join(os.path.expanduser('~'),'.labkey','slicer')
+    if not os.path.isdir(setupDir):
+        os.makedirs(setupDir)
+    setupFile=os.path.join(setupDir,'setup.json')
+    
+    #if f is not there, create an empty json
+    try:
+        with open(setupFile,'r') as f:
+            setup=json.load(f)
+    except OSError:
+        setup={}
+
+    try:
+        setup['paths'][name]=path
+    except KeyError:
+        setup['paths']={}
+        setup['paths'][name]=path
+
+    with open(setupFile,'w') as f:
+        json.dump(setup,f)
+    
 def setConfig(labkeyUser,labkeyServer='https://merlin.fmf.uni-lj.si',\
         certificateZip=None):
     connectionConfig={}