#!/usr/bin/env python
#
# Haze
#
# Copyright 2015-2017 Joe Block <jpb@unixorn.net>
#
# 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.
#
"""
setup.py for haze
"""

import os
import shutil
from setuptools import setup, find_packages, Command

name = 'haze'
version = '0.0.18'


class CleanCommand(Command):
  """
  Add a clean option to setup.py's commands
  """
  description = 'Clean up'
  user_options = []


  def initialize_options(self):
    self.cwd = None


  def finalize_options(self):
    self.cwd = os.getcwd()


  def run(self):
    assert os.getcwd() == self.cwd, "Must be in package root: %s" % self.cwd
    if os.path.isdir('build'):
      shutil.rmtree('build')
    if os.path.isdir('dist'):
      shutil.rmtree('dist')



setup(
  name=name,
  author="Joe Block",
  author_email="jpb@unixorn.net",
  description="Haze is a collection of AWS utility functions",
  url="https://github.com/unixorn/haze",
  packages=find_packages(),
  install_requires=[
    "boto>=2.38.0",
    "logrus>=0.0.2"
  ],
  cmdclass={
    "clean": CleanCommand,
  },
  version=version,
  download_url="https://github.com/unixorn/haze/tarball/%s" % version,
  classifiers=[
    "Development Status :: 3 - Alpha",
    "Operating System :: POSIX",
    "License :: OSI Approved :: Apache Software License",
    "Programming Language :: Python :: 2.7",
    "Topic :: System :: Systems Administration",
  ],
  keywords=['aws', 'cloud'],
  entry_points={
    "console_scripts": [
      "haze = %s.cli.conductor:hazeDriver" % name,
      "haze-aws-account-id = %s.ec2:getAWSAccountID" % name,
      "haze-aws-ami-id = %s.cli.commands:awsAMIid" % name,
      "haze-aws-instance-id = %s.cli.commands:awsInstanceID" % name,
      "haze-aws-instance-type = %s.cli.commands:awsInstanceType" % name,
      "haze-aws-public-ipv4 = %s.cli.commands:awsPublicIPv4" % name,
      "haze-aws-read-instance-tag = %s.cli.commands:awsReadInstanceTag" % name,
      "haze-aws-read-metadata-key = %s.cli.awsmetadata:awsReadMetadataKey" % name,
      "haze-aws-region = %s.cli.commands:awsMyRegion" % name
    ]
  }
)

@@ -729,16 +729,302 @@
 ommand%0A%0A
+def system_call(command):%0A  %22%22%22Run a command and return stdout.%0A%0A  Would be better to use subprocess.check_output, but this works on 2.6,%0A  which is still the system Python on CentOS 7.%22%22%22%0A  p = subprocess.Popen(%5Bcommand%5D, stdout=subprocess.PIPE, shell=True)%0A  return p.stdout.read()%0A%0A%0A
 name = '
@@ -1043,16 +1043,69 @@
 n = 
-'0.0.18'
+%220.1.%25s%22 %25 (system_call('git rev-list HEAD --count').strip())
 %0A%0A%0Ac

Set version to be based on commit count