Ticket #2783 (closed enhancement: fixed)

Opened 4 years ago

Last modified 15 months ago

Python utililities should support command-line wildcards

Reported by: mwtoews 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

gdal_merge.py.patch Download (0.6 KB) - added by mwtoews 4 years ago.
patch for gdal_merge.py using fnmatch solution
glob_patch2.diff Download (2.4 KB) - added by mwtoews 4 years ago.
improvements to gdal_merge.py and gdalident.py using python glob module

Change History

Changed 4 years ago by mwtoews

patch for gdal_merge.py using fnmatch solution

Changed 4 years ago by hobu

  • status changed from new to closed
  • resolution set to fixed

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.

Changed 4 years ago by mwtoews

  • status changed from closed to reopened
  • resolution fixed deleted
  • version changed from 1.6.0 to svn-trunk
  • milestone changed from 1.6.1 to 1.6.3
  • keywords gdal_merge, gdalident added; fnmatch removed
  • type changed from defect to enhancement

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 4 years ago by mwtoews

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

Changed 4 years ago by mwtoews

  • owner changed from warmerdam to hobu
  • status changed from reopened to new

Changed 4 years ago by hobu

  • status changed from new to closed
  • resolution set to fixed

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

Changed 3 years ago by warmerdam

  • status changed from closed to reopened
  • resolution fixed deleted

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.

Changed 3 years ago by antonio

  • cc antonio added

Changed 15 months ago by warmerdam

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

Changed 15 months ago by warmerdam

  • status changed from reopened to closed
  • resolution set to fixed

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.