瀏覽代碼

Have API look at .labkey directory for remote configuration

Andrej Studen 5 年之前
父節點
當前提交
ab0dea9c79

+ 1 - 1
labkeySlicerPythonExtension/labkeySlicerPythonExtension.py

@@ -50,7 +50,7 @@ class labkeySlicerPythonExtensionWidget(ScriptedLoadableModuleWidget):
     self.layout.addWidget(connectionCollapsibleButton)
     self.layout.addWidget(connectionCollapsibleButton)
 
 
     connectionFormLayout = qt.QFormLayout(connectionCollapsibleButton)
     connectionFormLayout = qt.QFormLayout(connectionCollapsibleButton)
-    self.configDir='.'
+    self.configDir=os.getenv("HOME")+os.sep+".labkey";
 
 
     self.serverURL=qt.QLineEdit("https://merlin.fmf.uni-lj.si")
     self.serverURL=qt.QLineEdit("https://merlin.fmf.uni-lj.si")
     self.serverURL.textChanged.connect(self.updateServerURL)
     self.serverURL.textChanged.connect(self.updateServerURL)

+ 16 - 3
labkeySlicerPythonExtension/slicerNetwork.py

@@ -39,12 +39,17 @@ class labkeyURIHandler(slicer.vtkURIHandler):
         self.className="labkeyURIHandler"
         self.className="labkeyURIHandler"
         slicer.mrmlScene.AddURIHandler(self)
         slicer.mrmlScene.AddURIHandler(self)
         try:
         try:
-	       self.localCacheDirectory=os.path.join(os.environ["HOME"],"labkeyCache")
+	       fhome=os.environ["HOME"]
         except:
         except:
 	    #in windows, the variable is called HOMEPATH
 	    #in windows, the variable is called HOMEPATH
 	       fhome=os.environ['HOMEDRIVE']+os.environ['HOMEPATH']
 	       fhome=os.environ['HOMEDRIVE']+os.environ['HOMEPATH']
-	       self.localCacheDirectory=os.path.join(fhome,"labkeyCache")
+
+        self.localCacheDirectory=os.path.join(fhome,"labkeyCache")
+        self.configDir=os.path.join(fhome,".labkey")
         self.mode="http"
         self.mode="http"
+        #try initializing network from default config file, if found
+        self.initFromConfig()
+
 
 
     def CanHandleURI(self,uri):
     def CanHandleURI(self,uri):
         print "labkeyURIHandler::CanHandleURI({0})".format(uri)
         print "labkeyURIHandler::CanHandleURI({0})".format(uri)
@@ -197,12 +202,20 @@ class labkeyURIHandler(slicer.vtkURIHandler):
         cookie_handler=urllib2.HTTPCookieProcessor(cj)
         cookie_handler=urllib2.HTTPCookieProcessor(cj)
         self.opener=urllib2.build_opener(http_handler,cookie_handler)
         self.opener=urllib2.build_opener(http_handler,cookie_handler)
 
 
+    def initFromConfig(self):
+        path=os.path.join(self.configDir,"remote.json")
+        try:
+            self.parseConfig(path)
+        except OSError:
+            return
+        self.initRemote()
+
     def parseConfig(self,fname):
     def parseConfig(self,fname):
         try:
         try:
             f=open(fname)
             f=open(fname)
         except OSError as e:
         except OSError as e:
             print "Confgiuration error: OS error({0}): {1}".format(e.errno, e.strerror)
             print "Confgiuration error: OS error({0}): {1}".format(e.errno, e.strerror)
-            return
+            raise
 
 
         dt=json.load(f)
         dt=json.load(f)
         if dt.has_key('SSL'):
         if dt.has_key('SSL'):