from setuptools.command.install import install
import setuptools
from shutil import copy
from pathlib import Path
import subprocess


class UserHomeData(install):

    def run(self):
        service_dir = Path.home().joinpath('.config/systemd/user')
        service_dir.mkdir(exist_ok=True, parents=True)
        for f in Path(__file__).parent.joinpath('systemd').glob('*.service'):
            copy(f, service_dir.joinpath(f.name))
        #subprocess.run(['systemctl', 'daemon-reload'])
        install.run(self)


setuptools.setup(
    name='crawler_cluster',
    version='0.1.3',
    license="MIT",
    author='Dan Kelleher',
    author_email='kelleherjdan@gmail.com',
    maintainer='Dan Kelleher',
    maintainer_email='kelleherjdan@gmail.com',
    include_package_data=True,
    description='Fault tolerant, stealthy, distributed web crawling.',
    long_description=Path(__file__).parent.joinpath('README.md').read_text(),
    long_description_content_type='text/markdown',
    packages=['crawler_cluster'],
    url='https://github.com/djkelleher/crawler_cluster',
    scripts=[
        'bin/redis_list_to_json',
        'bin/set_worker_init_func',
        'bin/start_queue_worker',
    ],
    extras_require={
        'test': ['pytest', 'pytest_asyncio'],
    },
    install_requires=Path('requirements.txt').read_text().splitlines(),
    cmdclass={'install': UserHomeData},
    classifiers=[
        'Programming Language :: Python',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',
        'License :: OSI Approved :: MIT License',
        'Intended Audience :: Developers',
        'Intended Audience :: Science/Research',
        'Operating System :: OS Independent', 'Topic :: Internet',
        'Topic :: Internet :: WWW/HTTP :: Browsers',
        'Topic :: Scientific/Engineering :: Information Analysis'
    ])
