# Path: dax/dax_settings.py
# class DAX_Settings(object):
#     def __init__(self):
#         pass
# 
#     def get_user_home(self):
#         return os.path.expanduser('~')
# 
#     def get_xsitype_include(self):
#         return ['proc:genProcData']
# 
#     def get_cmd_submit(self):
#         return SLURM_SUBMIT
# 
#     def get_prefix_jobid(self):
#         return 'Submitted batch job'
# 
#     def get_suffix_jobid(self):
#         return ''
# 
#     def get_cmd_count_nb_jobs(self):
#         return SLURM_COUNTJOBS
# 
#     def get_cmd_get_job_status(self):
#         return Template(SLURM_JOBSTATUS)
# 
#     def get_queue_status(self):
#         return SLURM_QUEUED
# 
#     def get_running_status(self):
#         return SLURM_RUNNING
# 
#     def get_complete_status(self):
#         return SLURM_COMPLETE
# 
#     def get_cmd_get_job_memory(self):
#         return Template(SLURM_JOBMEM)
# 
#     def get_cmd_get_job_walltime(self):
#         return Template(SLURM_JOBTIME)
# 
#     def get_cmd_get_job_node(self):
#         return Template(SLURM_JOBNODE)
# 
#     def get_job_extension_file(self):
#         return SLURM_EXT
# 
#     def get_root_job_dir(self):
#         return '/tmp'
# 
#     def get_launcher_type(self):
#         return 'diskq-combined'
# 
#     def get_use_reference(self):
#         return False
# 
#     def get_email_opts(self):
#         return 'FAIL'
# 
#     def get_job_template(self, filepath):
#         filepath = os.path.expanduser(filepath)
# 
#         with open(filepath, 'r') as f:
#             data = f.read()
# 
#         return Template(data)
# 
# Path: dax/errors.py
# class ClusterError(DaxError):
#     """Basic exception for errors related to cluster raised by dax."""


import os
import time
import logging
import subprocess as sb
from datetime import datetime
from .dax_settings import DAX_Settings
from .errors import ClusterError
    jobinfo['walltime_used'] = get_job_walltime_used(jobid, diff_days)
    jobinfo['jobnode'] = get_job_node(jobid, diff_days)

    return jobinfo


def get_job_mem_used(jobid, diff_days):
    """
    Get the memory used for the task from cluster

    :param jobid: job id to check
    :param diff_days: difference of days between starting date and now
    :return: string with the memory usage, empty string if error
    """
    mem = ''
    # Check for blank jobid
    if not jobid:
        return mem

    cmd = DAX_SETTINGS.get_cmd_get_job_memory()\
                      .safe_substitute({'numberofdays': diff_days,
                                        'jobid': jobid})
    try:
        output = sb.check_output(cmd, stderr=sb.STDOUT, shell=True)
        if output.startswith(b'sacct: error'):
            raise ClusterError(output)
        if output:
            mem = output.strip()
            mem = mem.decode()


# Path: dax/dax_settings.py
# class DAX_Settings(object):
#     def __init__(self):
#         pass
# 
#     def get_user_home(self):
#         return os.path.expanduser('~')
# 
#     def get_xsitype_include(self):
#         return ['proc:genProcData']
# 
#     def get_cmd_submit(self):
#         return SLURM_SUBMIT
# 
#     def get_prefix_jobid(self):
#         return 'Submitted batch job'
# 
#     def get_suffix_jobid(self):
#         return ''
# 
#     def get_cmd_count_nb_jobs(self):
#         return SLURM_COUNTJOBS
# 
#     def get_cmd_get_job_status(self):
#         return Template(SLURM_JOBSTATUS)
# 
#     def get_queue_status(self):
#         return SLURM_QUEUED
# 
#     def get_running_status(self):
#         return SLURM_RUNNING
# 
#     def get_complete_status(self):
#         return SLURM_COMPLETE
# 
#     def get_cmd_get_job_memory(self):
#         return Template(SLURM_JOBMEM)
# 
#     def get_cmd_get_job_walltime(self):
#         return Template(SLURM_JOBTIME)
# 
#     def get_cmd_get_job_node(self):
#         return Template(SLURM_JOBNODE)
# 
#     def get_job_extension_file(self):
#         return SLURM_EXT
# 
#     def get_root_job_dir(self):
#         return '/tmp'
# 
#     def get_launcher_type(self):
#         return 'diskq-combined'
# 
#     def get_use_reference(self):
#         return False
# 
#     def get_email_opts(self):
#         return 'FAIL'
# 
#     def get_job_template(self, filepath):
#         filepath = os.path.expanduser(filepath)
# 
#         with open(filepath, 'r') as f:
#             data = f.read()
# 
#         return Template(data)
# 
# Path: dax/errors.py
# class ClusterError(DaxError):
#     """Basic exception for errors related to cluster raised by dax."""


# Path: dax/cluster.py
import os
import time
import logging
import subprocess as sb
from datetime import datetime
from .dax_settings import DAX_Settings
from .errors import ClusterError

    jobinfo['walltime_used'] = get_job_walltime_used(jobid, diff_days)
    jobinfo['jobnode'] = get_job_node(jobid, diff_days)

    return jobinfo


def get_job_mem_used(jobid, diff_days):
    """
    Get the memory used for the task from cluster

    :param jobid: job id to check
    :param diff_days: difference of days between starting date and now
    :return: string with the memory usage, empty string if error
    """
    mem = ''
    # Check for blank jobid
    if not jobid:
        return mem

    cmd = DAX_SETTINGS.get_cmd_get_job_memory()\
                      .safe_substitute({'numberofdays': diff_days,
                                        'jobid': jobid})
    try:
        output = sb.check_output(cmd, stderr=sb.STDOUT, shell=True)
        if output.startswith(b'sacct: error'):
            raise ClusterError(output)
        if output:
            mem = output.strip()
            mem = mem.decode()


    except (sb.CalledProcessError, ClusterError):