#! /usr/bin/env python

from setuptools import setup, find_packages

import os
import time

from subprocess import Popen, PIPE

with open('README.asciidoc', 'r') as fin:
    with open('README', 'w') as fout:
        fout.write(fin.read())

try:
    # Attempt to try and get the version string using 'git describe'.
    cmd = 'git describe --abbrev=8 --dirty'
    ver = Popen(cmd.split(), stdout=PIPE).communicate()[0].strip()
except:
    # Not in a Git repository.
    ver = None
else:
    # Check if the checkout is dirty.
    if ver.endswith('dirty'):
        ver = ver[:-5] + time.strftime('%Y%m%d%H%M')

    # Write the version string to '__version__.py'
    with open('__version__.py', 'w') as f:
        f.write('# this file is autogenerated by setup.py\n')
        f.write('version = "{0}"\n'.format(ver))

try:
    # Try to get the version number from __version__.py
    import __version__
    ver = __version__.version
except ImportError:
    # Import failed, version is unknown.
    ver = 'unknown'


setup(
    name='Actions',
    version=ver,
    author='Corrin Meyer',
    author_email='corrin.meyer@gmail.com',
    description='Framework to execute a sequence of commands that can be invoked or revoked',
    url='http://github.com/cjmeyer/actions',
    test_suite='py.test',
    tests_require=['pytest', 'mock'],
    install_requires=['path.py', 'jinja2'],
    packages=find_packages(exclude=[]),
    zip_safe=True
)
