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

"""
Executable to update all tasks that need to be updated 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__ = "Updates tasks status for open tasks (NEED_INPUTS/\
JOB_RUNNING/JOB_FAILED/READY_TO_COMPLETE) "


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

    :return: parser object parsed
    """
    from argparse import ArgumentParser
    ap = ArgumentParser(prog='dax_update_tasks', 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_update_open_taks on locally \
(only one project).'
    ap.add_argument('--project', dest='project', help=_help, default=None)
    _help = 'list of sessions label from XNAT to run dax_update_open_taks \
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.')
    return ap.parse_args()


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

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