Browse Source

Switching to pypi nixWrapper

Andrej Studen 2 weeks ago
parent
commit
dae4dab1c4
1 changed files with 15 additions and 62 deletions
  1. 15 62
      slicerModule/nixModule.py

+ 15 - 62
slicerModule/nixModule.py

@@ -11,66 +11,20 @@ import urllib3
 import string
 import chardet
 import base64
+
+try:
+   import nixWrapper
+except ModuleNotFoundError:
+   import subprocess
+   py='{}PythonSlicer'.format(slicer.app.slicerHome[:-2])
+   print(f'Executable: {py}')
+   subprocess.check_call([py, '-m', 'pip', 'install', 'nixWrapper'])
+   import nixWrapper
+
 #
 # labkeySlicerPythonExtension
 #
 
-def buildGITURL(server,project,path,branch='master'):
-    #copy of buildGITURL from nixWrapper.py
-    if server.find('wiscigt')>-1:
-        projectURL='%2f'.join(project)
-        pathURL='%2f'.join(path)
-        return server+'/api/v4/projects/'+projectURL+'/repository/files/'+pathURL+'?ref='+branch
-    if server.find('fmf.uni-lj.si')>-1:
-        projectURL='/'.join(project)#studen/nixSuite
-        pathURL='/'.join(path)
-        return '/'.join([server,projectURL,'raw',branch,pathURL])
-
-def getWrapper(name):
-    project=['labkey','nixsuite']
-    if name=='nixWrapper.py':
-        path=['wrapper','nixWrapper.py']
-    server='http://wiscigt.powertheword.com'
-   #update to new git server layout 
-    server='https://git0.fmf.uni-lj.si'
-    project=['studen','nixSuite']
-    
-
-    remoteSourcesURL=buildGITURL(server,project,path)
-    http = urllib3.PoolManager()
-    r = http.request('GET', remoteSourcesURL)
-
-    print(r.data)
-    
-    #gogs returns raw data
-    if server.find('fmf.uni-lj.si')>-1:
-        m_bytes=r.data
-
-    if server.find('wiscigt')>-1:
-        #returns a JSON
-        encoding=chardet.detect(r.data)['encoding']
-        jsonData=json.loads(r.data.decode(encoding))
-        content=jsonData['content']
-        #we are interested in content, do looped way of decoding it
-        b64_bytes=content.encode('ascii')
-        m_bytes=base64.b64decode(b64_bytes)
-    
-
-    #we are interested in content, do looped way of decoding it
-    m=m_bytes.decode('ascii')
-    #m is string coded file that needs to be written to file
-    pathList=['.nix','software','src']
-    pathList.extend(project)
-    pathList.extend(path)
-    localPath=os.path.join(os.path.expanduser('~'),*pathList)
-    p=pathlib.Path(localPath)
-    if not os.path.isdir(str(p.parent)):
-        os.makedirs(str(p.parent))
-    
-    with open(localPath,'w') as f:
-        f.write(m)
-    return localPath
-
 class nixModule(ScriptedLoadableModule):
   """Uses ScriptedLoadableModule base class, available at:
   https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
@@ -105,10 +59,9 @@ class nixModuleWidget(ScriptedLoadableModuleWidget):
 
     fhome=os.path.expanduser('~')
 
-    fwrapper=getWrapper('nixWrapper.py')
-    p=pathlib.Path(fwrapper)
-    sys.path.append(str(p.parent))
-    import nixWrapper
+    #fwrapper=getWrapper('nixWrapper.py')
+    #p=pathlib.Path(fwrapper)
+    #sys.path.append(str(p.parent))
 
     self.remoteResources=nixWrapper.getResources()
     
@@ -180,11 +133,11 @@ class nixModuleLogic(ScriptedLoadableModuleLogic):
       ScriptedLoadableModuleLogic.__init__(self, parent)
 
   def loadModule(self,libName,modName):
-      import nixWrapper
+  #    import nixWrapper
       nixWrapper.loadModule(slicer,qt,libName,modName)
 
   def loadLibrary(self,libName):
-      import nixWrapper
+  #    import nixWrapper
       nixWrapper.loadLibrary(libName)
 
 class nixModuleTest(ScriptedLoadableModuleTest):