from setuptools import setup, find_packages
from os.path import join, isfile
from os import walk
import poseidonctrip


def read_file(filename):
    with open(filename) as fp:
        return fp.read().strip()


def read_requirements(filename):
    return [line.strip() for line in read_file(filename).splitlines()
            if not line.startswith('#')]


def package_files(directories):
    paths = []
    for item in directories:
        if isfile(item):
            paths.append(join('..', item))
            continue
        for (path, directories, filenames) in walk(item):
            for filename in filenames:
                paths.append(join('..', path, filename))
    return paths


setup(
    name='poseidonctrip',
    version=poseidonctrip.version(),
    description='distributed crawler',
    keywords=['poseidonctrip', 'scrapy', 'distributed'],
    author='hantmac',
    author_email='hantmac@outlook.com',
    url='http://pypi.python.org/pypi/poseidonctrip/',
    license='MIT',
    install_requires=read_requirements('requirements.txt'),
    packages=find_packages(),
    entry_points={
        'console_scripts': ['poseidonctrip = poseidonctrip.cmd:cmd']
    },
    package_data={
        '': package_files([
            'poseidonctrip/server/static',
            'poseidonctrip/server/core/templates',
            'poseidonctrip/templates',
            'poseidonctrip/VERSION'
        ])
    },
    publish=[
        'sudo python3 setup.py bdist_egg',
        'sudo python3 setup.py sdist',
        'sudo python3 setup.py bdist_egg upload'
        'sudo python3 setup.py sdist upload'
    ]
)
