# Path: ugali/utils/logger.py
# class SpecialFormatter(logging.Formatter):
#     FORMATS = {'DEFAULT'       : "%(message)s",
#                logging.WARNING : "WARNING: %(message)s",
#                logging.ERROR   : "ERROR: %(message)s"}
#     def format(self, record):
# def file_found(filename,force):


import os
import subprocess, subprocess as sub
import getpass
import copy
import time
import resource
import numpy as np
    import argparse
from collections import OrderedDict as odict
from itertools import chain
from ugali.utils.logger import logger
        out = self.popen(cmd)
        stdout = out.communicate()[0]
        # There is an extra newline at the end
        return stdout.split('\n')[:-1]

    def bcomp(self, path):
        """ Return completed logfile(s).

        Parameters:
        -----------
        path : path to logfile(s)
        
        Returns:
        --------
        files : completed logfiles and message
        """
        cmd='grep -r "^Successfully completed." %s'%path
        out = self.popen(cmd)
        stdout = out.communicate()[0]
        # There is an extra newline at the end
        return stdout.split('\n')[:-1]

    def throttle(self,max_jobs=None,sleep=60):
        if max_jobs is None: max_jobs = self.max_jobs
        if max_jobs is None: return
        while True:
            njobs = self.njobs()
            if njobs < max_jobs:
                return
            else:

# Path: ugali/utils/logger.py
# class SpecialFormatter(logging.Formatter):
#     FORMATS = {'DEFAULT'       : "%(message)s",
#                logging.WARNING : "WARNING: %(message)s",
#                logging.ERROR   : "ERROR: %(message)s"}
#     def format(self, record):
# def file_found(filename,force):


# Path: ugali/utils/batch.py
import os
import subprocess, subprocess as sub
import getpass
import copy
import time
import resource
import numpy as np
    import argparse
from collections import OrderedDict as odict
from itertools import chain
from ugali.utils.logger import logger

        out = self.popen(cmd)
        stdout = out.communicate()[0]
        # There is an extra newline at the end
        return stdout.split('\n')[:-1]

    def bcomp(self, path):
        """ Return completed logfile(s).

        Parameters:
        -----------
        path : path to logfile(s)
        
        Returns:
        --------
        files : completed logfiles and message
        """
        cmd='grep -r "^Successfully completed." %s'%path
        out = self.popen(cmd)
        stdout = out.communicate()[0]
        # There is an extra newline at the end
        return stdout.split('\n')[:-1]

    def throttle(self,max_jobs=None,sleep=60):
        if max_jobs is None: max_jobs = self.max_jobs
        if max_jobs is None: return
        while True:
            njobs = self.njobs()
            if njobs < max_jobs:
                return
            else:

                logger.info('%i jobs already in queue, waiting...'%(njobs))