Skip to content

Commit

Permalink
updates for python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mehrtash committed Oct 7, 2020
1 parent e7214b1 commit 650459f
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions DeepInfer/DeepInfer.py
@@ -1,4 +1,4 @@
import Queue
import queue
import json
import platform
import os
Expand All @@ -10,6 +10,8 @@
from glob import glob
from time import sleep

from functools import reduce

from __main__ import qt, ctk, slicer

# To avoid the overhead of importing SimpleITK during application
Expand Down Expand Up @@ -338,8 +340,7 @@ def getAllDigests(self):

def populateLocalModels(self):
digests = self.getAllDigests()
jsonFiles = glob(JSON_LOCAL_DIR + "/*.json")
jsonFiles.sort(cmp=lambda x, y: cmp(os.path.basename(x), os.path.basename(y)))
jsonFiles = sorted(glob(JSON_LOCAL_DIR + "/*.json"))
self.jsonModels = []
for fname in jsonFiles:
with open(fname, "r") as fp:
Expand Down Expand Up @@ -407,22 +408,22 @@ def onConnectButton(self):
self.downloadButton.visible = True
self.connectButton.visible = False
self.connectButton.enabled = False
import urllib2
from urllib.request import urlopen
url = 'https://api.github.com/repos/DeepInfer/Model-Registry/contents/'
response = urllib2.urlopen(url)
response = urlopen(url)
data = json.load(response)
for item in data:
if 'json' in item['name']:
# print(item['name'])
url = item['url']
response = urllib2.urlopen(url)
response = urlopen(url)
data = json.load(response)
dl_url = data['download_url']
print("downloading: {}...".format(dl_url))
response = urllib2.urlopen(dl_url)
response = urlopen(dl_url)
content = response.read()
outputPath = os.path.join(JSON_CLOUD_DIR, dl_url.split('/')[-1])
with open(outputPath, 'w') as f:
with open(outputPath, 'wb') as f:
f.write(content)
self.populateModelRegistryTable()
except Exception as e:
Expand All @@ -438,7 +439,7 @@ def onTestDockerButton(self):
cmd.append(self.dockerPath.currentPath)
cmd.append('--version')
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
message = p.stdout.readline().replace('\n', '')
message = p.stdout.readline().decode('utf-8').replace('\n', '')
if message.startswith('Docker version'):
qt.QMessageBox.information(None, 'Docker Status', 'Docker is configured correctly'
' ({}).'.format(message))
Expand Down Expand Up @@ -630,7 +631,7 @@ class DeepInferLogic:
"""

def __init__(self):
self.main_queue = Queue.Queue()
self.main_queue = queue.Queue()
self.main_queue_running = False
self.thread = threading.Thread()
self.abort = False
Expand Down Expand Up @@ -699,7 +700,7 @@ def checkDockerDaemon(self):
print(cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
slicer.app.processEvents()
line = p.stdout.readline()
line = p.stdout.readline().decode('utf-8')
if line[:9] == 'CONTAINER':
return True
return False
Expand All @@ -708,7 +709,7 @@ def executeDocker(self, dockerName, modelName, dataPath, iodict, inputs, params)
try:
assert self.checkDockerDaemon(), "Docker Daemon is not running"
except Exception as e:
print(e.message)
print(e)
self.abort = True

modules = slicer.modules
Expand All @@ -732,8 +733,6 @@ def executeDocker(self, dockerName, modelName, dataPath, iodict, inputs, params)
fileName = item + '.nrrd'
inputDict[item] = fileName
sitk.WriteImage(img, str(os.path.join(TMP_PATH, fileName)))
#except Exception as e:
# print(e.message)
elif iodict[item]["type"] == "point_vec":
input_node_name = inputs[item].GetName()
fidListNode = getNode(input_node_name)
Expand Down Expand Up @@ -812,7 +811,7 @@ def thread_doit(self, modelParameters):

'''
except Exception as e:
msg = e.message
msg = e
qt.QMessageBox.critical(slicer.util.mainWindow(), "Exception during execution of ", msg)
slicer.modules.DeepInferWidget.applyButton.enabled = True
slicer.modules.DeepInferWidget.progress.hide = True
Expand Down

1 comment on commit 650459f

@tokjun
Copy link

@tokjun tokjun commented on 650459f Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mehrtash, is there any plan to integrate this into the latest Slicer? Although the module shows up on Slicer Extensions Manager, it isn't loaded properly.

Please sign in to comment.