
    h                         S SK r S SKJr  S SKJrJr  S SKJr   " S S\ R                  5      r	 " S S\ R                  5      r
 " S	 S
\5      rg)    N)gdal)BaseCommandCommandError)get_func_argsc                   "    \ rS rSrSrSS jrSrg)LayerOptionAction   zm
Custom argparse action for the `ogrinspect` `layer_key` keyword option
which may be an integer or a string.
Nc                      [        X R                  [        U5      5        g ! [         a    [        X R                  U5         g f = fN)setattrdestint
ValueErrorselfparser	namespacevalueoption_strings        c/var/www/html/env/lib/python3.13/site-packages/django/contrib/gis/management/commands/ogrinspect.py__call__LayerOptionAction.__call__   s6    	1Iyy#e*5 	1Iyy%0	1s   "  AA r   __name__
__module____qualname____firstlineno____doc__r   __static_attributes__r       r   r   r      s    
1r!   r   c                   "    \ rS rSrSrSS jrSrg)ListOptionAction   z
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                     UR                  5       S:X  a  [        X R                  S5        g [        X R                  UR                  S5      5        g )NtrueT,)lowerr   r   splitr   s        r   r   ListOptionAction.__call__   s5    ;;=F"Iyy$/Iyy%++c*:;r!   r   r   r   r   r!   r   r#   r#      s    <r!   r#   c                   (    \ rS rSrSr/ rS rS rSrg)Command#   zInspects 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                    UR                  SSS9  UR                  SSS9  UR                  S[        SSS	9  UR                  S
[        SSS	9  UR                  SSSS9  UR                  SS[        SSS9  UR                  SSSS9  UR                  SSS9  UR                  SSSSS9  UR                  S [        SS!S	9  UR                  S"S#S9  UR                  S$SS%S9  g )&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defaultr0   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`))r3   r0   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   r2   r3   r0   z--multi-geom
store_truez?Treat the geometry in the data source as a geometry collection.)r2   r0   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.)r2   r   r0   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_argumentsCommand.add_arguments,   sk   M0JKL/MN#1	 	 	
 	#L	 	 	
 	W 	 	

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

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

 	K 	 	
r!   c                 6  ^ UR                  S5      UR                  S5      pC [        R                  " U5      nSSKJnJn  UR                  5        V	V
s0 s H  u  pU	[        U5      ;   d  M  U
c  M  X_M     nn	n
U" XT40 UD6 Vs/ s H  oPM     nnUS   (       a  US   US   US   S	.nU" U40 UD6nUR                  5        V	V
s0 s H  u  pX_M	     sn
n	mUR                  S
S
SU-  SUR                  5       -  /5        UR                  U4S jXRS      R                   5       5        UR                  SUS   < SXS      < S3S/5        SR                  U5      $ ! [        R                   a  n[	        U5      eS nAff = fs  sn
n	f s  snf s  sn
n	f )Nr/   r1   r   )_ogrinspectmappingr>   	geom_namer5   
multi_geom)r?   r5   r@    z7# Auto-generated `LayerMapping` dictionary for %s modelz%s_mapping = {c              3   @   >#    U  H  nS TU   < SU< S3v   M     g7f)    '': '',Nr   ).0ogr_fldrev_mappings     r   	<genexpr>!Command.handle.<locals>.<genexpr>   s"      >G &1%97C>s   rC   rD   rE   }
)popr   
DataSourceGDALExceptionr   #django.contrib.gis.utils.ogrinspectr=   r>   itemsr   extendr(   fieldsjoin)r   argsoptionsr/   r1   dsmsgr=   r>   kvogr_optionssoutputkwargsmapping_dictrH   s                   @r   handleCommand.handleo   s   ")++m"<gkk,>WZ	$-B 	M
  
'M+.. 34 AD' 	 

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

 I Bs5   E# F
.F
3F
F	F#F7FFr   N)	r   r   r   r   r0   requires_system_checksr:   r`   r    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>rh      s?     # A .
1 
1<x <A!k A!r!   