Loading django/contrib/gis/management/commands/ogrinspect.py +8 −12 Original line number Diff line number Diff line import inspect from optparse import make_option from django.contrib.gis import gdal from django.core.management.base import LabelCommand, CommandError Loading Loading @@ -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'], Loading django/contrib/gis/tests/inspectapp/tests.py +7 −0 Original line number Diff line number Diff line Loading @@ -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(): """ Loading Loading
django/contrib/gis/management/commands/ogrinspect.py +8 −12 Original line number Diff line number Diff line import inspect from optparse import make_option from django.contrib.gis import gdal from django.core.management.base import LabelCommand, CommandError Loading Loading @@ -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'], Loading
django/contrib/gis/tests/inspectapp/tests.py +7 −0 Original line number Diff line number Diff line Loading @@ -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(): """ Loading