SBU-BMI / SlicerPathology

3D Slicer extension for Pathology segmentation tools
http://bmi.stonybrookmedicine.edu
Other
5 stars 8 forks source link

runtime error: path #78

Closed tdiprima closed 7 years ago

tdiprima commented 7 years ago

We're getting a "Permission denied" error on Windows because the slashes are backwards: u'C:/TCGA-3C-AALI-01Z-00-DX1_20170501094619.zip'

On Linux, the slashes go like this: / On Windows, it's like this: \

But if you look at the error output... there ares slashes going both directions.

SAVING
{'TCGA-3C-AALI-01Z-00-DX1-label': {'sizeUpperThld': 50.0, 'algorithm': 'Yi', 'sizeThld': 3.0, 'curvatureWeight': 8.0, 'kernelSize': 20.0, 'label': 'Nucleus', 'mpp': 0.25, 'otsuRatio': 1.0}}
{
"TCGA-3C-AALI-01Z-00-DX1-label": {
"algorithm": "Yi",
"curvatureWeight": 8.0,
"kernelSize": 20.0,
"label": "Nucleus",
"mpp": 0.25,
"otsuRatio": 1.0,
"sizeThld": 3.0,
"sizeUpperThld": 50.0
}
}
huh?
TCGA-3C-AALI-01Z-00-DX1-label
zipfile name
C:/TCGA-3C-AALI-01Z-00-DX1_20170501094619.zip
Traceback (most recent call last):
File "C:/Users/bmi-admin/AppData/Roaming/NA-MIC/Extensions-25993/SlicerPathology/lib/Slicer-4.7/qt-scripted-modules/SlicerPathology.py", line 313, in onSaveButtonClicked
zf = zipfile.ZipFile(zfname, mode='w')
File "C:\Program Files\Slicer 4.7.0-2017-04-29\lib\Python\Lib\zipfile.py", line 756, in __init__
self.fp = open(file, modeDict[mode])
IOError: [Errno 13] Permission denied: u'C:/TCGA-3C-AALI-01Z-00-DX1_20170501094619.zip'
fedorov commented 7 years ago

I don't know how you compose that path name, but in Python you can (should!) use os.path.join to do this in a platform-safe way.

fedorov commented 7 years ago

Although, looking at the error, I am not sure path separator is the cause. You are trying to access C:/TCGA-3C-AALI-01Z-00-DX1_20170501094619.zip. It is highly unlikely this is correct, and if it is correct - it should be fixed. You cannot expect to be able to save anything into top level of a system drive on Windows. It's not a good style, and you would need Admin permissions to do it...

tdiprima commented 7 years ago

Thanks for the tip, @fedorov. I'll have a go at it.

tdiprima commented 7 years ago

Update:

We have 2 issues:

  1. We're adding a slash when building this file path os.path.join(self.resourcesPath, "Colors/SlicerPathology.csv") We should probably do a join, and another join.

  2. When we get the output mask file name, we do os.path.join(self.dataDirButton.directory, labelName + '.tif') And that comes out to ./TCGA-41-3393-01Z-00-DX1... So it looks like Windows interprets that as root. So we can't build that one as a relative path.

fedorov commented 7 years ago

We should probably do a join, and another join.

join takes arbitrary number of arguments, so it is easier:

In [3]: os.path.join('a','b','c','d','e')
Out[3]: 'a/b/c/d/e'
tdiprima commented 7 years ago

Right. Or even os.sep. Coolness! Thank you.

Update: I figured out what triggers problem 2... If the user doesn't change the data directory (class ctkDirectoryButton), when you ask it for it's .directory, it gives you: . Current directory in *nix. But in Windows, that's not right.