#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Executable to test the python files you created for DAX:
    --processor path to the file for the processor
    --module path to the file for the module
    --settings path to the settings file
"""

from __future__ import print_function

from dax import dax_tools_utils as dax_tools


DESCRIPTION = """What is the script doing :
   * Test the dax files that the user created (processor.py/module.py/\
settings.py).

You can find information on github on how to write those files.
Three executables are available to generate the squeleton for the files:
 - GenerateModuleTemplate
 - GenerateProcessorTemplate
 - GenerateSettingsTemplate

You will need to name the object you want to test: 'test_obj' (see below).
Your module/processsor or launcher (for settings) object should be name \
'test_obj'.

E.G for module:
       from Module_Set_Scan_Type import Module_Set_Scan_Type
       test_obj = Module_Set_Scan_Type()

Examples:
  Run for module:
   * dax_test -p PROJECT --nb_sess 5 --file test_module.py
  Run for processor for PROJECT on 2 sessions Sess1 and Sess2:
   * dax_test -p PROJECT --nb_sess 5 --file test_processor.py --sessions \
Sess1,Sess2
  Run for settings without seing dax outputs and keep the log:
   * dax_test -p PROJECT --nb_sess 5 --file test_settings.py --hide --nodel
"""


def parse_args():
    """
    Method to parse arguments base on ArgumentParser

    :return: parser object parsed
    """
    from argparse import ArgumentParser, RawTextHelpFormatter
    ap = ArgumentParser(prog='dax_test', description=DESCRIPTION,
                        formatter_class=RawTextHelpFormatter)
    ap.add_argument('--host', dest='host', default=None,
                    help='Host for XNAT. Default: using $XNAT_HOST.')
    ap.add_argument('-u', '--username', dest='username', default=None,
                    help='Username for XNAT. Default: using $XNAT_USER.')
    ap.add_argument('-p', '--project', dest='project', required=True,
                    help='Project ID from XNAT to use for testing.')
    _help = 'list of sessions label from XNAT to test the dax files.'
    ap.add_argument('-s', '--sessions', dest='sessions',
                    help=_help, default=None)
    _help = 'Number of sessions to test dax files on. Default: 2. Max:5.'
    ap.add_argument('--nb_sess', dest='nb_sess',
                    help=_help, default=2, type=int)
    _help = 'Path to the test file written by the user containing test_obj. \
It can be the yaml file for a processor or settings.'
    ap.add_argument('--file', dest='test_file',
                    help=_help, required=True)
    _help = 'Keep temp files generated by dax_setup (in ~/.dax_test).'
    ap.add_argument('--nodel', dest='do_not_remove',
                    help=_help, action='store_false')
    _help = 'Hide dax outputs in a logfile in ~/.dax_test/dax_test.log.'
    ap.add_argument('--hide', dest='hide',
                    help=_help, action='store_true')
    return ap.parse_args()


if __name__ == '__main__':
    args = parse_args()

    print('Deprecated executable. Use dax test instead.')
    dax_tools.testing(args.test_file, args.project, args.sessions, args.host,
                      args.username, args.hide, args.do_not_remove,
                      args.nb_sess)
