a
    Kcòf·  ã                   @   sh   d dl Z d dlmZ d dlmZmZ d dlmZ G dd„ de jƒZ	G dd„ de jƒZ
G d	d
„ d
eƒZdS )é    N)Úgdal)ÚBaseCommandÚCommandError©Úget_func_argsc                   @   s   e Zd ZdZddd„ZdS )ÚLayerOptionActionzy
    Custom argparse action for the `ogrinspect` `layer_key` keyword option
    which may be an integer or a string.
    Nc                 C   s<   zt || jt|ƒƒ W n  ty6   t || j|ƒ Y n0 d S ©N)ÚsetattrÚdestÚintÚ
ValueError©ÚselfÚparserÚ	namespaceÚvalueÚoption_string© r   ún/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/contrib/gis/management/commands/ogrinspect.pyÚ__call__   s    zLayerOptionAction.__call__)N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   c                   @   s   e Zd ZdZddd„ZdS )Ú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                 C   s4   |  ¡ dkrt|| jdƒ nt|| j| d¡ƒ d S )NÚtrueTú,)Úlowerr	   r
   Úsplitr   r   r   r   r      s    zListOptionAction.__call__)Nr   r   r   r   r   r      s   r   c                   @   s$   e Zd ZdZg Zdd„ Zdd„ ZdS )ÚCommandz³Inspects 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                 C   sÈ   |j ddd� |j ddd� |j dtddd	� |j d
tddd	� |j dddd� |j ddtddd� |j dddd� |j ddd� |j ddddd� |j d tdd!d	� |j d"d#d� |j d$dd%d� d S )&NÚdata_sourcezPath to the data source.)ÚhelpÚ
model_namezName of the model to create.z--blankFz–Use 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	--decimalzžUse 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-nameZgeomzDSpecifies the model name for the Geometry Field (defaults to `geom`))r%   r"   z--layerÚ	layer_keyr   zšThe 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_falseZimportszDDo not include `from django.contrib.gis.db import models` statement.)r$   r
   r"   z--nullz•Use 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   r   r   r   Úadd_arguments,   sp    üüýû	ýþüüþýzCommand.add_argumentsc              
      sF  |  d¡|  d¡ }}zt |¡}W n. tjyR } zt|ƒ‚W Y d }~n
d }~0 0 ddlm‰ m} ‡ fdd„| ¡ D ƒ}dd„ ˆ ||fi |¤ŽD ƒ}	|d	 �r<|d
 |d |d dœ}
||fi |
¤Ž}dd„ | ¡ D ƒ‰|	 	ddd| d| 
¡  g¡ |	 	‡fdd„||d  jD ƒ¡ |	 	d|d
 ||d
  f dg¡ d |	¡S )Nr!   r#   r   )Ú_ogrinspectÚmappingc                    s*   i | ]"\}}|t ˆ ƒv r|d ur||“qS r   r   ©Ú.0ÚkÚv)r+   r   r   Ú
<dictcomp>}   s   þz"Command.handle.<locals>.<dictcomp>c                 S   s   g | ]}|‘qS r   r   )r.   Úsr   r   r   Ú
<listcomp>‚   ó    z"Command.handle.<locals>.<listcomp>r,   Ú	geom_namer&   Ú
multi_geom)r5   r&   r6   c                 S   s   i | ]\}}||“qS r   r   r-   r   r   r   r1   �   r4   Ú z7# Auto-generated `LayerMapping` dictionary for %s modelz%s_mapping = {c                 3   s   | ]}d ˆ | |f V  qdS )ú    '%s': '%s',Nr   )r.   Zogr_fld)Úrev_mappingr   r   Ú	<genexpr>™   s   ÿz!Command.handle.<locals>.<genexpr>r8   Ú}Ú
)Úpopr   Z
DataSourceZGDALExceptionr   Z#django.contrib.gis.utils.ogrinspectr+   r,   ÚitemsÚextendr   ÚfieldsÚjoin)r   ÚargsÚoptionsr!   r#   ZdsÚmsgr,   Zogr_optionsÚoutputÚkwargsZmapping_dictr   )r+   r9   r   Úhandleo   sJ    
þ
ýÿ
ûÿ	þÿýÿzCommand.handleN)r   r   r   r"   Zrequires_system_checksr*   rG   r   r   r   r   r    #   s
   ÿCr    )ÚargparseZdjango.contrib.gisr   Zdjango.core.management.baser   r   Zdjango.utils.inspectr   ÚActionr   r   r    r   r   r   r   Ú<module>   s   