####################################################################################################
#
# PySpice - A Spice package for Python
# Copyright (C) 2020 Fabrice Salvaire
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################

####################################################################################################

from pathlib import Path
import shutil

from invoke import task

####################################################################################################

# https://github.com/conda-forge/pyspice-feedstock

# enable anaconda environment
#   source .../miniconda3/bin/activate

@task()
def conda_build(ctx):
    with ctx.cd('anaconda'):
        ctx.run('conda build .')
        # ctx.run('conda build purge')

@task()
def conda_login(ctx):
    path = Path(__file__).parent.joinpath('anaconda-login.txt')
    with open(path) as fh:
        username = fh.readline().strip()
        password = fh.readline().strip()
    print('"{}" "{}"'.format(username, password))
    ctx.run('anaconda login --username="{}" --password="{}"'.format(username, password))

@task(conda_build, conda_login)
def conda_upload(ctx):
    result = ctx.run('conda build . --output')
    path = str(result.stdout).strip()
    ctx.run('anaconda upload {}'.format(path))
