
    g                         d dl Z d dlmZ d dlmZmZ d dlmZ  G d de j                        Z	 G d de j                        Z
 G d	 d
e      Zy)    N)gdal)BaseCommandCommandError)get_func_argsc                       e Zd ZdZddZy)LayerOptionActionzy
    Custom argparse action for the `ogrinspect` `layer_key` keyword option
    which may be an integer or a string.
    Nc                     	 t        || j                  t        |             y # t        $ r t        || j                  |       Y y w xY wN)setattrdestint
ValueErrorselfparser	namespacevalueoption_strings        /var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/contrib/gis/management/commands/ogrinspect.py__call__zLayerOptionAction.__call__   s:    	1Ityy#e*5 	1Ityy%0	1s    #  AAr
   __name__
__module____qualname____doc__r        r   r   r      s    
1r   r   c                       e Zd ZdZddZy)ListOptionActionz
    Custom argparse action for `ogrinspect` keywords that require
    a string list. If the string is 'True'/'true' then the option
    value will be a boolean instead.
    Nc                     |j                         dk(  rt        || j                  d       y t        || j                  |j                  d             y )NtrueT,)lowerr   r   splitr   s        r   r   zListOptionAction.__call__   s9    ;;=F"Ityy$/Ityy%++c*:;r   r
   r   r   r   r   r   r      s    <r   r   c                        e Zd ZdZg Zd Zd Zy)CommandzInspects the given OGR-compatible data source (e.g., a shapefile) and outputs
a GeoDjango model with the given model name. For example:
 ./manage.py ogrinspect zipcode.shp Zipcodec                    |j                  dd       |j                  dd       |j                  dt        dd	       |j                  d
t        dd	       |j                  ddd       |j                  ddt        dd       |j                  ddd       |j                  dd       |j                  dddd       |j                  d t        dd!	       |j                  d"d#       |j                  d$dd%       y )&Ndata_sourcezPath to the data source.)help
model_namezName of the model to create.z--blankFzUse a comma separated list of OGR field names to add the `blank=True` option to the field definition. Set to `true` to apply to all applicable fields.)actiondefaultr)   z	--decimalzUse a comma separated list of OGR float fields to generate `DecimalField` instead of the default `FloatField`. Set to `true` to apply to all OGR float fields.z--geom-namegeomzDSpecifies the model name for the Geometry Field (defaults to `geom`))r,   r)   z--layer	layer_keyr   zThe key for specifying which layer in the OGR data source to use. Defaults to 0 (the first layer). May be an integer or a string identifier for the layer.)r   r+   r,   r)   z--multi-geom
store_truez?Treat the geometry in the data source as a geometry collection.)r+   r)   z--name-fieldz:Specifies a field name to return for the __str__() method.z--no-importsstore_falseimportszDDo not include `from django.contrib.gis.db import models` statement.)r+   r   r)   z--nullzUse a comma separated list of OGR field names to add the `null=True` option to the field definition. Set to `true` to apply to all applicable fields.z--sridzeThe SRID to use for the Geometry Field. If it can be determined, the SRID of the data source is used.z	--mappingz8Generate mapping dictionary for use with `LayerMapping`.)add_argumentr   r   )r   r   s     r   add_argumentszCommand.add_arguments,   sk   M0JKL/MN#1	 	 	
 	#L	 	 	
 	W 	 	

 	$? 	 	
 	R 	 	

 	M 	 	
 	 W	 	 	
 	#1	 	 	
 	? 	 	

 	K 	 	
r   c                    |j                  d      |j                  d      }}	 t        j                  |      }ddlm}m} |j                         D 	
ci c]  \  }	}
|	t        |      v r|
|	|
 }}	}
 |||fi |D cg c]  }| }}|d   r|d   |d   |d   d	} ||fi |}|j                         D 	
ci c]  \  }	}
|
|	
 c}
}	|j                  d
d
d|z  d|j                         z  g       |j                  fd||d      j                  D               |j                  d|d   d||d      ddg       dj                  |      S # t        j                  $ r}t	        |      d }~ww xY wc c}
}	w c c}w c c}
}	w )Nr(   r*   r   )_ogrinspectmappingr6   	geom_namer.   
multi_geom)r7   r.   r8    z7# Auto-generated `LayerMapping` dictionary for %s modelz%s_mapping = {c              3   6   K   | ]  }d |   d|d  yw)    '': '',Nr   ).0ogr_fldrev_mappings     r   	<genexpr>z!Command.handle.<locals>.<genexpr>   s#      >G &1%97C>s   r;   r<   r=   }
)popr   
DataSourceGDALExceptionr   #django.contrib.gis.utils.ogrinspectr5   r6   itemsr   extendr#   fieldsjoin)r   argsoptionsr(   r*   dsmsgr5   r6   kvogr_optionssoutputkwargsmapping_dictr@   s                   @r   handlezCommand.handleo   s   ")++m"<gkk,>WZ	$-B 	M
  
'1M+..1= qD' 	 

 )ZG;GHG!GH9 %[1$[1%l3F
 #200L -9,>,>,@A,@DAq1a4,@AKMMM !$z'7'7'99 MM !'+"67>>  MM {+\'+:N-OQ yy  _ !! 	$s##	$

 I Bs)   E E9 	E?;FE6&E11E6N)r   r   r   r)   requires_system_checksr3   rW   r   r   r   r&   r&   #   s     	6 	  A
F5!r   r&   )argparsedjango.contrib.gisr   django.core.management.baser   r   django.utils.inspectr   Actionr   r   r&   r   r   r   <module>r^      s?     # A .
1 
1<x <A!k A!r   