pytroll / satpy

Python package for earth-observing satellite data processing
http://satpy.readthedocs.org/en/latest/
GNU General Public License v3.0
1.06k stars 293 forks source link

Fix OLCI and other readers' file patterns to work on Windows #211

Closed djhoese closed 6 years ago

djhoese commented 6 years ago

Problem description

It was brought up on the mailing list that a Windows user had to modify the file patterns in the OLCI reader to not use "/" but use "\" instead. I would have thought that python would have handled this fine and found the files, but it didn't work for this user. It might be as simple as splitting on '/' and then using os.path.join to make the actual pathname to search for.

@adybbroe Do you know if this is something you handle specially in pyspectral (with LUT paths, etc)?

RutgerK commented 6 years ago

Perhaps using the Pathlib module which was introduced with Python 3 can help here. https://docs.python.org/3/library/pathlib.html

For example if i use it with a 'posix' Path on a Windows machine, it automatically converts to a pathlib.WindowsPath object.

from pathlib import Path

p = Path('some/posix/path')
print(str(p))

Results in:

some\posix\path

I suspect it also works the other way around when on Linux.

In my limited experience with the Pathlib module i find it very convenient. Also for joining paths, checking if they exists etc. The only downside is that you have to use str(Path) when you want to pass it on to something which expects a string instead of a Path object. Which makes sense of course, but it requires some changes in the code. For example

gdal.Open(path) # where path is a string

Would become:

gdal.Open(str(path)) # where path is a Path object

djhoese commented 6 years ago

For now we still have to support python 2.7, but pathlib would be nice. For this simple issue I'm hoping we can just do os.path.join(base_dir, *file_pattern.split("/")) for now since we have to do the join for the base directory anyone (if I recall correctly).

mraspaud commented 6 years ago

I think that's fixed now

mraspaud commented 6 years ago

I believe commit 2dbb18685d33e09fbc37313d9968b6acc52ee7dc fixed this. @RutgerK, would you be able to test this ?

djhoese commented 6 years ago

@mraspaud I don't see how it would have fixed it. It doesn't seem to address the wrong slashes being used in the file patterns.

mraspaud commented 6 years ago

my bad, it is commit 7d1942502a3079fe8af60d0873a2646ea190428b