diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-12-31 14:36:45 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-12-31 16:26:44 +0100 |
| commit | d0eeddd6fcd93b23bb632ad3ea95ae3f871907e3 (patch) | |
| tree | 0889a8600465f9e635eb62f68d600119c3d4220e | |
| parent | 75220d3b5dbe03ef70d42433178a9598133a4ac1 (diff) | |
Fixed #21716 -- Only passed arguments supported by ogrinspect
Thanks Marco Badan for the report.
| -rw-r--r-- | django/contrib/gis/management/commands/ogrinspect.py | 20 | ||||
| -rw-r--r-- | django/contrib/gis/tests/inspectapp/tests.py | 7 |
2 files changed, 15 insertions, 12 deletions
diff --git a/django/contrib/gis/management/commands/ogrinspect.py b/django/contrib/gis/management/commands/ogrinspect.py index c7b1389574..78c610635a 100644 --- a/django/contrib/gis/management/commands/ogrinspect.py +++ b/django/contrib/gis/management/commands/ogrinspect.py @@ -1,4 +1,6 @@ +import inspect from optparse import make_option + from django.contrib.gis import gdal from django.core.management.base import LabelCommand, CommandError @@ -83,27 +85,21 @@ class Command(LabelCommand): if not gdal.HAS_GDAL: raise CommandError('GDAL is required to inspect geospatial data sources.') - # Removing options with `None` values. - options = dict((k, v) for k, v in options.items() if not v is None) - # Getting the OGR DataSource from the string parameter. try: ds = gdal.DataSource(data_source) except gdal.OGRException as msg: raise CommandError(msg) - # Whether the user wants to generate the LayerMapping dictionary as well. - show_mapping = options.pop('mapping', False) - - # Getting rid of settings that `_ogrinspect` doesn't like. - options.pop('verbosity', False) - options.pop('settings', False) - # Returning the output of ogrinspect with the given arguments # and options. from django.contrib.gis.utils.ogrinspect import _ogrinspect, mapping - output = [s for s in _ogrinspect(ds, model_name, **options)] - if show_mapping: + # Filter options to params accepted by `_ogrinspect` + ogr_options = dict((k, v) for k, v in options.items() + if k in inspect.getargspec(_ogrinspect).args and v is not None) + output = [s for s in _ogrinspect(ds, model_name, **ogr_options)] + + if options['mapping']: # Constructing the keyword arguments for `mapping`, and # calling it on the data source. kwargs = {'geom_name': options['geom_name'], diff --git a/django/contrib/gis/tests/inspectapp/tests.py b/django/contrib/gis/tests/inspectapp/tests.py index 17642ea8df..2690dc484d 100644 --- a/django/contrib/gis/tests/inspectapp/tests.py +++ b/django/contrib/gis/tests/inspectapp/tests.py @@ -115,6 +115,13 @@ class OGRInspectTest(TestCase): ' objects = models.GeoManager()' )) + def test_management_command(self): + shp_file = os.path.join(TEST_DATA, 'cities', 'cities.shp') + out = StringIO() + call_command('ogrinspect', shp_file, 'City', stdout=out) + output = out.getvalue() + self.assertIn('class City(models.Model):', output) + def get_ogr_db_string(): """ |
