ó
	GĎOc           @   sn   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z m Z d   Z d   Z	 d e f d     YZ
 d S(	   i˙˙˙˙N(   t   make_option(   t   gdal(   t   LabelCommandt   CommandErrorc         C   sD   y t  |  } Wn t k
 r) | } n Xt | j |  j |  d S(   s}   
    Callback for `make_option` for the `ogrinspect` `layer_key`
    keyword option which may be an integer or a string.
    N(   t   intt
   ValueErrort   setattrt   valuest   dest(   t   optiont   optt   valuet   parserR   (    (    sJ   ../Django//lib/python/django/contrib/gis/management/commands/ogrinspect.pyt   layer_option   s
    
c         C   sW   | j    d k r t } n" g  | j d  D] } | ^ q+ } t | j |  j |  d S(   sł   
    Callback for `make_option` for `ogrinspect` keywords that require
    a string list.  If the string is 'True'/'true' then the option
    value will be a boolean instead.
    t   truet   ,N(   t   lowert   Truet   splitR   R   R   (   R	   R
   R   R   R   t   s(    (    sJ   ../Django//lib/python/django/contrib/gis/management/commands/ogrinspect.pyt   list_option   s    	"t   Commandc           B   s  e  Z d  Z d Z e j e d d d d d d d d e d	 e d
 d e d d d d d d d d e d	 e d
 d e d d d d d d	 d d
 d e d d d d d d d d e	 d	 d d
 d e d d d d d d	 e d
 d e d d d d
 d e d d d d d  d	 e
 d
 d! e d" d d# d d d d d e d	 e d
 d$ e d% d d& d
 d' e d( d d d d) d
 d* f
 Z e Z d+   Z RS(,   sł   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 Zipcodes   [data_source] [model_name]s   --blankR   t   blankt   typet   stringt   actiont   callbackt   defaultt   helps   Use a comma separated list of OGR field names to add the `blank=True` option to the field definition.  Set with`true` to apply to all applicable fields.s	   --decimalt   decimals   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.s   --geom-namet	   geom_namet   geomsD   Specifies the model name for the Geometry Field (defaults to `geom`)s   --layert	   layer_keyi    s   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.s   --multi-geomt
   store_truet
   multi_geoms?   Treat the geometry in the data source as a geometry collection.s   --name-fieldt
   name_fields@   Specifies a field name to return for the `__unicode__` function.s   --no-importst   store_falset   importssD   Do not include `from django.contrib.gis.db import models` statement.s   --nullt   nulls   Use a comma separated list of OGR field names to add the `null=True` option to the field definition.  Set with`true` to apply to all applicable fields.s   --sridt   sridsf   The SRID to use for the Geometry Field.  If it can be determined, the SRID of the data source is used.s	   --mappingt   mappings8   Generate mapping dictionary for use with `LayerMapping`.c         O   s<  y | \ } } Wn$ t  k
 r6 t d |  j   n Xt j sO t d   n  t g  | j   D]$ \ } } | d  k	 r_ | | f ^ q_  } y t j |  } Wn" t j	 k
 rĂ } t |   n X| j
 d t  }	 | j
 d t  }
 | j
 d t  } d d l m } m } g  | | | |  D] } | ^ q#} |	 r+i | d d 6| d	 d	 6| d
 d
 6} | | |  } t g  | j   D] \ } } | | f ^ q } | j d d | d | j   g  | j g  | | d	 j D] } d | | | f ^ qŢ | j d | d | | d f d g  n  d j |  d S(   Ns#   Invalid arguments, must provide: %ss4   GDAL is required to inspect geospatial data sources.R(   t	   verbosityt   settingsi˙˙˙˙(   t   _ogrinspectR(   R   R    R"   t    s7   # Auto-generated `LayerMapping` dictionary for %s models   %s_mapping = {s       '%s' : '%s',t   }s   
(   R   R   t   argsR   t   HAS_GDALt   dictt   itemst   Nonet
   DataSourcet   OGRExceptiont   popt   Falset#   django.contrib.gis.utils.ogrinspectR+   R(   t   extendR   t   fieldst   join(   t   selfR.   t   optionst   data_sourcet
   model_namet   kt   vt   dst   msgt   show_mappingR)   R*   R+   R(   R   t   outputt   kwargst   mapping_dictt   rev_mappingt   ogr_fld(    (    sJ   ../Django//lib/python/django/contrib/gis/management/commands/ogrinspect.pyt   handleK   s6    	=%19,(   t   __name__t
   __module__R   R.   R   t   option_listR    R   R6   R   R   t   requires_model_validationRI   (    (    (    sJ   ../Django//lib/python/django/contrib/gis/management/commands/ogrinspect.pyR      s:   (   t   ost   optparseR    t   django.contrib.gisR   t   django.core.management.baseR   R   R   R   R   (    (    (    sJ   ../Django//lib/python/django/contrib/gis/management/commands/ogrinspect.pyt   <module>   s   		