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

"""
Executable to build you sessions for a settings file describing which
project on XNAT and which pipelines to run on those projects.
"""

from __future__ import print_function

import dax
import sys
from dax import DAX_Settings

DAX_SETTINGS = DAX_Settings()
__description__ = "Builds all sessions scans and assessors data (create \
assessors/create inputs: e.g: generate NIFTI)."


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

    :return: parser object parsed
    """
    from argparse import ArgumentParser
    ap = ArgumentParser(prog='dax_build', description=__description__)
    ap.add_argument(dest='settings_path', help='Settings Path')
    ap.add_argument('--logfile', dest='logfile',
                    help='Logs file path if needed.', default=None)
    _help = 'Project ID from XNAT to run dax_build on locally (only one \
project).'
    ap.add_argument('--project', dest='project', help=_help, default=None)
    _help = 'list of sessions (labels) from XNAT to run dax_build on locally.'
    ap.add_argument('--sessions', dest='sessions', help=_help, default=None)
    ap.add_argument('--nodebug', dest='debug', action='store_false',
                    help='Avoid printing DEBUG information.')
    ap.add_argument('--mod', dest='mod_delta', default=None,
                    help='Run build if modified within this window')
    return ap.parse_args()


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

    print('Deprecated executable. Use dax build instead.')
    if DAX_SETTINGS.is_cluster_valid():
        dax.bin.build(args.settings_path, args.logfile, args.debug,
                      args.project, args.sessions, args.mod_delta)
    else:
        sys.stdout.write('Please edit your settings via dax_setup for the \
cluster section\n.')
