import os
import os.path
try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup
import distutils.cmd
import tempfile
import shutil
from wand.version import VERSION_INFO


def readme():
    with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as f:
        return f.read()


class upload_doc(distutils.cmd.Command):
    """Uploads the documentation to GitHub pages."""

    description = __doc__
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        path = tempfile.mkdtemp()
        build = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             'build', 'sphinx', 'html')
        os.chdir(path)
        os.system('git clone git@github.com:StyleShare/wand.git .')
        os.system('git checkout gh-pages')
        os.system('git rm -r .')
        os.system('touch .nojekyll')
        os.system('cp -r ' + build + '/* .')
        os.system('git stage .')
        os.system('git commit -a -m "Documentation updated."')
        os.system('git push origin gh-pages')
        shutil.rmtree(path)


setup(name='Wand',
      packages=['wand'],
      data_files=[('', ['README.rst'])],
      version=VERSION_INFO,
      description='Ctypes-based simple MagickWand API binding for Python',
      long_description=readme(),
      license='MIT License',
      author='Hong Minhee',
      author_email='dahlia' '@' 'stylesha.re',
      maintainer='StyleShare',
      maintainer_email='dev' '@' 'stylesha.re',
      url='http://styleshare.github.com/wand/',
      tests_require=['Attest'],
      test_loader='attest:auto_reporter.test_loader',
      test_suite='wandtests.tests',
      extras_require={'doc': ['Sphinx >=1.0']},
      classifiers=[
        'Development Status :: 3 - Alpha',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Topic :: Multimedia :: Graphics'
      ],
      cmdclass={'upload_doc': upload_doc})

