Opened 10 years ago

Closed 6 years ago

#2783 closed enhancement (fixed)

Python utililities should support command-line wildcards

Reported by: Mike Toews Owned by: hobu
Priority: normal Milestone: 1.8.1
Component: Utilities Version: svn-trunk
Severity: minor Keywords: python, glob, gdal_merge, gdalident
Cc: antonio

Description

At present, a command that uses wildcards does not work as expected, for example with gdal_merge.py:

> gdal_merge.py -o test.tif 094a*
ERROR 4: `094a*' does not exist in the file system,
and is not recognised as a supported dataset name.

Traceback (most recent call last):
  File "C:\PROGRA~1\FWTOOL~1.1\bin\gdal_merge.py", line 358, in ?
    ulx = file_infos[0].ulx
IndexError: list index out of range

The present workaround is to use batch files and additional parameters (e.g., http://n2.nabble.com/gdal_merge-multiple-files-td2032804.html).

There are two solutions that should be used for all Python command line utilities:

Attachments (2)

gdal_merge.py.patch (580 bytes) - added by Mike Toews 10 years ago.
patch for gdal_merge.py using fnmatch solution
glob_patch2.diff (2.4 KB) - added by Mike Toews 9 years ago.
improvements to gdal_merge.py and gdalident.py using python glob module

Download all attachments as: .zip

Change History (10)

Changed 10 years ago by Mike Toews

Attachment: gdal_merge.py.patch added

patch for gdal_merge.py using fnmatch solution

comment:1 Changed 9 years ago by hobu

Resolution: fixed
Status: newclosed

applied in the 1.6 branch in r16856 and in trunk in r16857. Thanks for the patch! I don't know that we'll generally support wildcards for all of the python utilities, but it sure makes sense for the merge operation in my mind.

comment:2 Changed 9 years ago by Mike Toews

Keywords: gdal_merge gdalident added; fnmatch removed
Milestone: 1.6.11.6.3
Resolution: fixed
Status: closedreopened
Type: defectenhancement
Version: 1.6.0svn-trunk

I've reviewed my comments and submission, and I'd like to improve on it. I was misinformed about the glob module, in that I misread it was introduced in Python 2.5. The glob module was actually introduced in Python <=2.3 (I'm not sure how to check this history). The glob module really helps wildcard expansions, and should be used in place of fnmatch due to its ease of use.

I have also learned that wildcard expansion is only needed for MS-DOS BAT files. Of course, this is still of valid importance for many users.

Nevertheless, I've included a patch "glob_patch2.diff" using "svn diff" for both gdal_merge.py and gdalident.py. These have been tested in MS-DOS and Linux. It is also much more simpler to read than the previous patch.

Changed 9 years ago by Mike Toews

Attachment: glob_patch2.diff added

improvements to gdal_merge.py and gdalident.py using python glob module

comment:3 Changed 9 years ago by Mike Toews

Owner: changed from warmerdam to hobu
Status: reopenednew

comment:4 Changed 9 years ago by hobu

Resolution: fixed
Status: newclosed

Applied in trunk in r17632 and backported in r17633. Please reopen if this is not working.

comment:5 Changed 8 years ago by warmerdam

Resolution: fixed
Status: closedreopened

Howard,

Globbing of arguments to gdal_merge.py or any other scripts by default is inappropriate as some objects are not in the filesystem as detailed in:

http://lists.osgeo.org/pipermail/gdal-dev/2010-March/023830.html

I think the globbing needs to be backed out or only applied when a -glob or -wildcard switch is passed in.

comment:6 Changed 8 years ago by antonio

Cc: antonio added

comment:7 Changed 6 years ago by warmerdam

As above, and per (#4542) this auto-globbing breaks non-simple files. I will apparently have to back it out myself.

comment:8 Changed 6 years ago by warmerdam

Resolution: fixed
Status: reopenedclosed

all globbing changes backed out in trunk (r24064), 1.9 (r24063) and 1.8 (r24062). evil evil stuff.

If it is going to be reintroduced it needs to be respectful of non-simple files and likely should be windows only.

Note: See TracTickets for help on using tickets.