예제 #1
0
def get_jobs_info(fn, write_method=options.write_method):
    """
    reads qstat YAML file and populates four lists. Returns the lists
    ex read_qstat_yaml
    """
    job_ids, usernames, job_states, queue_names = [], [], [], []

    with open(fn) as fin:
        try:
            qstats = (write_method.endswith('yaml')
                      ) and yaml.load_all(fin) or json.load(fin)
        except StopIteration:
            logging.warning('File %s is empty. (No jobs found or Error!)')
        else:
            for qstat in qstats:
                job_ids.append(str(qstat['JobId']))
                usernames.append(qstat['UnixAccount'])
                job_states.append(qstat['S'])
                queue_names.append(qstat['Queue'])
    # os.remove(fn)  # that DELETES the file!! why did I do that?!!
    logging.debug(
        'job_ids, usernames, job_states, queue_names lengths: '
        '%(job_ids)s, %(usernames)s, %(job_states)s, %(queue_names)s' % {
            "job_ids": len(job_ids),
            "usernames": len(usernames),
            "job_states": len(job_states),
            "queue_names": len(queue_names)
        })
    return job_ids, usernames, job_states, queue_names
예제 #2
0
def get_jobs_info(fn, write_method=options.write_method):
    """
    reads qstat YAML file and populates four lists. Returns the lists
    ex read_qstat_yaml
    """
    job_ids, usernames, job_states, queue_names = [], [], [], []

    with open(fn) as fin:
        try:
            qstats = (write_method.endswith('yaml')) and yaml.load_all(fin) or json.load(fin)
        except StopIteration:
            logging.warning('File %s is empty. (No jobs found or Error!)')
        else:
            for qstat in qstats:
                job_ids.append(str(qstat['JobId']))
                usernames.append(qstat['UnixAccount'])
                job_states.append(qstat['S'])
                queue_names.append(qstat['Queue'])
    # os.remove(fn)  # that DELETES the file!! why did I do that?!!
    logging.debug('job_ids, usernames, job_states, queue_names lengths: '
        '%(job_ids)s, %(usernames)s, %(job_states)s, %(queue_names)s'
        % {
        "job_ids": len(job_ids),
        "usernames": len(usernames),
        "job_states": len(job_states),
        "queue_names": len(queue_names)
        }
    )
    return job_ids, usernames, job_states, queue_names
예제 #3
0
def _read_pbsnodes_yaml(fn, write_method):
    """
    Parses the pbsnodes yaml file
    :param fn: str
    :return: list
    """
    pbs_nodes = []

    with open(fn) as fin:
        _nodes = (write_method.endswith('yaml')) and yaml.load_all(fin) or json.load(fin)
        for node in _nodes:
            pbs_nodes.append(node)
    # pbs_nodes.pop() if not pbs_nodes[-1] else None # until i figure out why the last node is None
    # this doesn't seem to be the case anymore, DONT KNOW WHY!!
    return pbs_nodes
예제 #4
0
def _read_qstatq_yaml(fn, write_method=options.write_method):
    """
    Reads the generated qstatq yaml file and extracts
    the information necessary for building the
    user accounts and pool mappings table.
    """
    qstatq_list = []
    logging.debug("Opening %s" % fn)
    with open(fn, 'r') as fin:
        qstatqs_total = (write_method.endswith('yaml')) and yaml.load_all(fin) or json.load(fin)
        for qstatq in qstatqs_total:
            qstatq_list.append(qstatq)
        total = qstatq_list.pop()
        total_running_jobs, total_queued_jobs = total['Total_running'], total['Total_queued']
    return int(eval(total_running_jobs)), int(eval(total_queued_jobs)), qstatq_list
예제 #5
0
파일: plugin_pbs.py 프로젝트: mbarszcz/qtop
def _read_pbsnodes_yaml(fn, write_method):
    """
    Parses the pbsnodes yaml file
    :param fn: str
    :return: list
    """
    pbs_nodes = []

    with open(fn) as fin:
        _nodes = (write_method.endswith('yaml')
                  ) and yaml.load_all(fin) or json.load(fin)
        for node in _nodes:
            pbs_nodes.append(node)
    # pbs_nodes.pop() if not pbs_nodes[-1] else None # until i figure out why the last node is None
    # this doesn't seem to be the case anymore, DONT KNOW WHY!!
    return pbs_nodes
예제 #6
0
파일: plugin_pbs.py 프로젝트: mbarszcz/qtop
def _read_qstatq_yaml(fn, write_method=options.write_method):
    """
    Reads the generated qstatq yaml file and extracts
    the information necessary for building the
    user accounts and pool mappings table.
    """
    qstatq_list = []
    logging.debug("Opening %s" % fn)
    with open(fn, 'r') as fin:
        qstatqs_total = (write_method.endswith('yaml')
                         ) and yaml.load_all(fin) or json.load(fin)
        for qstatq in qstatqs_total:
            qstatq_list.append(qstatq)
        total = qstatq_list.pop()
        total_running_jobs, total_queued_jobs = total['Total_running'], total[
            'Total_queued']
    return int(eval(total_running_jobs)), int(
        eval(total_queued_jobs)), qstatq_list