# Path: dax/errors.py
# class XnatToolsError(DaxError):
#     """Xnat Tools Exception."""
#     def __init__(self, message):
#         Exception.__init__(self, 'Error in xnat_tools: %s' % message)
# 
# class XnatToolsUserError(DaxError):
#     """Xnat Tools Exception."""
#     def __init__(self, script, message):
#         print(('\n%s: error: %s' % (script, message)))
#         sys.exc_info()[-1]
#         sys.exit(self)


import logging
import os
import sys
from .errors import XnatToolsError, XnatToolsUserError
    from argparse import ArgumentParser, RawTextHelpFormatter
    """
    if txt_file:
        print(('INFO: Export data from text file %s ...' % txt_file))
        obj_list = list()
        if not os.path.exists(txt_file):
            err = 'file %s does not exist.'
            raise XnatToolsUserError(exe_name, err % txt_file)
        else:
            with open(txt_file, 'r') as input_file:
                for line in input_file:
                    obj_list.append(line.strip().split('\n')[0])
    else:
        obj_list = None
    return obj_list


def write_csv(csv_string, csv_file, exe_name=''):
    """
    Method to write the report as a csv file
     with the values from REDCap

    :param csv_string: data to write in the csv
    :param csv_file: csv filepath
    :param exe_name: name of executable running the function for error
    :return: None
    """
    print('INFO: Writing report ...')
    basedir = os.path.basedir(csv_file)
    if not os.path.exists(basedir):
        err = 'Path %s not found for report. Give an existing parent folder.'

# Path: dax/errors.py
# class XnatToolsError(DaxError):
#     """Xnat Tools Exception."""
#     def __init__(self, message):
#         Exception.__init__(self, 'Error in xnat_tools: %s' % message)
# 
# class XnatToolsUserError(DaxError):
#     """Xnat Tools Exception."""
#     def __init__(self, script, message):
#         print(('\n%s: error: %s' % (script, message)))
#         sys.exc_info()[-1]
#         sys.exit(self)


# Path: dax/xnat_tools_utils.py
import logging
import os
import sys
from .errors import XnatToolsError, XnatToolsUserError
    from argparse import ArgumentParser, RawTextHelpFormatter

    """
    if txt_file:
        print(('INFO: Export data from text file %s ...' % txt_file))
        obj_list = list()
        if not os.path.exists(txt_file):
            err = 'file %s does not exist.'
            raise XnatToolsUserError(exe_name, err % txt_file)
        else:
            with open(txt_file, 'r') as input_file:
                for line in input_file:
                    obj_list.append(line.strip().split('\n')[0])
    else:
        obj_list = None
    return obj_list


def write_csv(csv_string, csv_file, exe_name=''):
    """
    Method to write the report as a csv file
     with the values from REDCap

    :param csv_string: data to write in the csv
    :param csv_file: csv filepath
    :param exe_name: name of executable running the function for error
    :return: None
    """
    print('INFO: Writing report ...')
    basedir = os.path.basedir(csv_file)
    if not os.path.exists(basedir):
        err = 'Path %s not found for report. Give an existing parent folder.'

        raise XnatToolsUserError(exe_name, err % csv_file)