import os
from setuptools import setup, find_packages
from setuptools.command.install import install
# from setuptools.command.develop import develop

from solthermpi import __version__
from solthermpi.crontab import update_crontab
from solthermpi.config import config


class PostInstall(install):
    """
    Post-installation routine. Installs initial crontab and creates
    log directories.
    """

    def run(self):
        install.run(self)

        # create log directories
        cron_logpath = config.get("GENERAL", "cron_logpath")
        os.makedirs(cron_logpath, exist_ok=True)
        logdir_archive = config.get("GENERAL", "logdir_archive")
        os.makedirs(logdir_archive, exist_ok=True)

        # initialize crontab
        update_crontab(config)


setup(
    name='solthermpi',
    version=__version__,
    description="Soltherm raspberry pi monitoring scripts",
    author='Remo Goetschi, Meteotest',
    author_email="remo.goetschi@meteotest.ch",
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Programming Language :: Python :: 3.4',
    ],
    packages=find_packages(exclude=("examples", "examples.*")),
    # include_package_data=True,
    package_data={'solthermpi': ['*.ini', '*.txt']},
    install_requires=[],
    cmdclass={
        # 'develop': PostDevelop,
        'install': PostInstall,
    },
)
