#!/usr/bin/env python3

import os
import pip
from shutil import copyfile, which


RESEARCH_DIR = 'research'
DATA_DIR = os.path.join(RESEARCH_DIR, 'data')


if not os.path.exists('config.ini'):
    copyfile('config.ini.example', 'config.ini')

requirements = os.path.join(RESEARCH_DIR, 'requirements.txt')  # local install
if not os.path.exists(requirements):
    requirements = 'requirements.txt'  # Docker

pip.main(['install', '--upgrade', '-r', requirements])

if which('unzip') == None:
    print('The following executables are needed and were not found: unzip')

print('Downloading datasets (this might take several minutes depending on your internet connection)')

# This is imported here because serenata_toolbox is only installed when pip.main is called (line 9)
from serenata_toolbox.datasets import fetch_latest_backup
os.makedirs(DATA_DIR, exist_ok=True)
fetch_latest_backup(DATA_DIR)
