# Path: zaifbot/errors.py
# class ZaifBotError(Exception):
#     def __init__(self, message):
#         self.message = message
# 
#     def __str__(self):
#         return str(self.message)


import os
import sys
import subprocess
from zaifbot.errors import ZaifBotError


def install_ta_lib():
    if sys.platform.startswith('linux'):
        # fixme
        cwd = os.path.dirname(__file__)
        subprocess.call(['tar', '-xzf', 'ta-lib-0.4.0-src.tar.gz'], cwd=cwd)
        talib_path = os.path.join(cwd, 'ta-lib')
        subprocess.call(['./configure', '--prefix=/usr'], cwd=talib_path, shell=True)
        subprocess.call(['make'], cwd=talib_path, shell=True)
        subprocess.call(['sudo', 'make', 'install'], cwd=talib_path)
        subprocess.call(['pip', 'install', 'TA-Lib'])
        return

    if sys.platform.startswith('darwin'):
        subprocess.call(["brew", "install", "ta-lib"])
        subprocess.call(['pip', 'install', 'TA-Lib'])
        return

    if sys.platform.startswith('win'):
        bits = '32' if sys.maxsize < 2 ** 31 else '64'
        py_version = str(sys.version_info.major) + str(sys.version_info.minor)
        __install_talib_for_windows(bits, py_version)
        return


# Path: zaifbot/errors.py
# class ZaifBotError(Exception):
#     def __init__(self, message):
#         self.message = message
# 
#     def __str__(self):
#         return str(self.message)


# Path: zaifbot/setup/talib.py
import os
import sys
import subprocess
from zaifbot.errors import ZaifBotError



def install_ta_lib():
    if sys.platform.startswith('linux'):
        # fixme
        cwd = os.path.dirname(__file__)
        subprocess.call(['tar', '-xzf', 'ta-lib-0.4.0-src.tar.gz'], cwd=cwd)
        talib_path = os.path.join(cwd, 'ta-lib')
        subprocess.call(['./configure', '--prefix=/usr'], cwd=talib_path, shell=True)
        subprocess.call(['make'], cwd=talib_path, shell=True)
        subprocess.call(['sudo', 'make', 'install'], cwd=talib_path)
        subprocess.call(['pip', 'install', 'TA-Lib'])
        return

    if sys.platform.startswith('darwin'):
        subprocess.call(["brew", "install", "ta-lib"])
        subprocess.call(['pip', 'install', 'TA-Lib'])
        return

    if sys.platform.startswith('win'):
        bits = '32' if sys.maxsize < 2 ** 31 else '64'
        py_version = str(sys.version_info.major) + str(sys.version_info.minor)
        __install_talib_for_windows(bits, py_version)
        return


    raise ZaifBotError('zaifbot does not support your platform')