# Copyright 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Transform description for generating bulkloader configuration from a
# bulk download of the datastore stats.
#

python_preamble:
- import: google.appengine.ext.bulkload.transform
- import: google.appengine.ext.bulkload.bulkloader_wizard
- import: google.appengine.api.datastore

transformers:
- kind: __Stat_PropertyType_PropertyName_Kind__
  connector: simpletext
  connector_options:
    mode: nonewline
    prolog: |
      # Autogenerated bulkloader.yaml file.
      # You must edit this file before using it. TODO: Remove this line when done.
      # At a minimum address the items marked with TODO:
      #  * Fill in connector and connector_options
      #  * Review the property_map.
      #    - Ensure the 'external_name' matches the name of your CSV column,
      #      XML tag, etc.
      #    - Check that __key__ property is what you want. Its value will become
      #      the key name on import, and on export the value will be the Key
      #      object.  If you would like automatic key generation on import and
      #      omitting the key on export, you can remove the entire __key__
      #      property from the property map.

      # If you have module(s) with your model classes, add them here. Also
      # change the kind properties to model_class.
      python_preamble:
      - import: base64
      - import: re
      - import: google.appengine.ext.bulkload.transform
      - import: google.appengine.ext.bulkload.bulkloader_wizard
      - import: google.appengine.ext.db
      - import: google.appengine.api.datastore
      - import: google.appengine.api.users

      transformers:
    template: |
      %(separator)s    - property: %(property_name)s
            external_name: %(property_name)s
            # Type: %(property_type)s Stats: %(count)s properties of this type in this kind.
      %(transforms)s
  sort_key_from_entity:
    "lambda entity: '_'.join((entity.get('kind_name', ''),
                              entity.get('property_name', ''),
                              entity.get('property_type', '')))"
  property_map:
    - property: __key__
      external_name: key
      export_transform: datastore.Key.name
    - property: kind_name
      external_name: kind_name
      default_value: MISSING_KIND_NAME
    - property: property_name
      external_name: property_name
    - property: property_type
      external_name: property_type
      export:
        - external_name: property_type
        - external_name: transforms
          export_transform: bulkloader_wizard.DatastoreTypeToTransforms
    - property: bytes
      external_name: bytes
    - property: count
      external_name: count
    - property: timestamp
      external_name: timestamp
      export_transform: transform.export_date_time('%Y%m%dT%H:%M')
  post_export_function: bulkloader_wizard.StatPostTransform()
