#!/usr/bin/env python
"""Replace the old Makefile system for testing and installing """

import os
import sys
from PDielec.preader     import main as main_preader
from PDielec.pdgui       import main as main_pdgui
from PDielec.checkcsv    import main as main_checkcsv
from PDielec.checkexcel  import main as main_checkexcel
from PDielec.p2cif       import main as main_p2cif
from PDielec.vibanalysis import main as main_vibanalysis
import numpy as np
import contextlib
from shutil import copyfile
import subprocess
import time

settings = {}
settings['padding'] = 50
settings['title'] = 'title'

debug = False
viewing = False
useLocal = True

test_preader = [
	'Castep/preader',
	'Vasp/preader',
	'Phonopy/preader',
	'Gulp/preader',
	'Crystal/preader',
	'AbInit/preader',
	'QE/preader',
    ]

test_p2cif = [
	'P2Cif/',
    ]

test_pdgui = [
	'Castep/AsparticAcid',
	'Castep/Isoleucine',
	'Castep/MgO',
	'Castep/Bubbles',
	'Castep/Na2SO42',
	'Castep/Castep17',
	'Vasp/F-Apatite',
	'Vasp/ZnO',
	'Vasp/Na2SO42',
	'Gulp/calcite',
	'Gulp/Na2SO42',
	'Crystal/Na2SO42',
	'Crystal/Leucine',
	'Crystal/Quartz',
	'Crystal/ZnO/Default',
	'Crystal/ZnO/CPHF',
	'Crystal/ZnO/NoEckart',
	'AbInit/AlAs',
	'AbInit/BaTiO3',
	'AbInit/Na2SO42',
	'QE/ZnO',
	'QE/Na2SO42',
	'QE/Cocaine',
	'Phonopy/ZnO',
	'Phonopy/Na2SO42',
	'SizeEffects/BaTiO3',
	'SizeEffects/MgO',
	'SizeEffects/ZnO',
	'Mie/MgO',
	'Mie/MgO_lognormal',
	'ATR/AlAs',
	'ATR/Na2SO42',
	'ATR/Na2SO42_fit',
	'Experiment/constant',
	'Experiment/fpsq',
	'Experiment/drude-lorentz',
	'Experiment/interpolation',
	'Experiment/Mayerhofer',
	'SingleCrystal/Bi2Se3',
	'SingleCrystal/Bi2Se3_film',
    ]

test_vibanalysis = [
	'VibAnalysis/AsparticAcid',
	'VibAnalysis/BaTiO3',
	'VibAnalysis/Cocaine',
	'VibAnalysis/F-Apatite',
	'VibAnalysis/Isoleucine',
	'VibAnalysis/Leucine',
    ]

benchmarks = [
	'Castep/AsparticAcid',
	'Castep/Isoleucine',
	'Castep/MgO',
	'Castep/Bubbles',
	'Castep/Na2SO42',
	'Vasp/F-Apatite',
	'Vasp/ZnO',
	'Vasp/Na2SO42',
	'Gulp/calcite',
	'Gulp/Na2SO42',
	'Crystal/Na2SO42',
	'Crystal/Leucine',
	'Crystal/Quartz',
	'Crystal/ZnO/Default',
	'Crystal/ZnO/CPHF',
	'Crystal/ZnO/NoEckart',
	'AbInit/AlAs',
	'AbInit/BaTiO3',
	'AbInit/Na2SO42',
	'QE/ZnO',
	'QE/Na2SO42',
	'QE/Cocaine',
	'Phonopy/ZnO',
	'Phonopy/Na2SO42',
	'SizeEffects/BaTiO3',
	'SizeEffects/MgO',
	'SizeEffects/ZnO',
	'Mie/MgO',
	'Mie/MgO_lognormal',
	'ATR/AlAs',
	'ATR/Na2SO42',
    ]

def usage():
    print('pdmake:', file=sys.stderr)
    print('  test' , file=sys.stderr)
    print('  tests' , file=sys.stderr)
    print('           run all the tests               ' , file=sys.stderr)
    print('  test-preader' , file=sys.stderr)
    print('           run all the preader tests' , file=sys.stderr)
    print('  test-pdgui' , file=sys.stderr)
    print('           run all the pdgui tests' , file=sys.stderr)
    print('  test-p2cif' , file=sys.stderr)
    print('           run all the p2cif tests' , file=sys.stderr)
    print('  test-vibanalysis' , file=sys.stderr)
    print('           run all the vibanalysis tests' , file=sys.stderr)
    print('  benchmarks      ' , file=sys.stderr)
    print('           run the benchmarks   ' , file=sys.stderr)
    print('  --regenerate      ' , file=sys.stderr)
    print('           regenerate all the test reference data' , file=sys.stderr)
    print('  --root directory  ' , file=sys.stderr)
    print('           sets the root directory for the installation' , file=sys.stderr)
    print('  --directory', file=sys.stderr)
    print('           Use the directory when listing the tests' , file=sys.stderr)
    print('  --padding 60', file=sys.stderr)
    print('           change the width of the output title field' , file=sys.stderr)
    print('  --view  ' , file=sys.stderr)
    print('           run pdgui with windowing on' , file=sys.stderr)
    print('  --usesystem ' , file=sys.stderr)
    print('           Force the use of system executables' , file=sys.stderr)
    print('  --debug ' , file=sys.stderr)
    print('           run with debug options switched on' , file=sys.stderr)
    if os.name != 'nt':
        print('  pypi      ' , file=sys.stderr)
        print('           Only use on linux installations...          ' , file=sys.stderr)
        print('           prepare for pypi uploading' , file=sys.stderr)
        print('  clean' , file=sys.stderr)
        print('           Only use on linux installations...          ' , file=sys.stderr)
        print('           clean up' , file=sys.stderr)
        print('  install' , file=sys.stderr)