import re
import socket
import subprocess32


def create_batches(li, n):
    '''
    Separate a list into several n-sized sub-lists, i.e. batches.

    Parameters
    ----------
    li: list
        usually list of files
    n: int
        batch size

    Returns
    -------
    List[list]
        batches
    '''
    n = max(1, n)
    return [li[i:i + n] for i in range(0, len(li), n)]


class Cluster(object):
    '''
    Class for cluster job handling.
    '''

    def __init__(self, output_dir):
        '''
        Initialize Cluster class.
        
        Parameters
        ----------
        output_dir: str
            path to directory were output log files should be saved
        '''
        self._on_brutus = None
        self.output_dir = output_dir

    @property
    def on_brutus(self):
        '''
        Are we on Brutus?

        Returns
        -------
        bool
        '''
        if self._on_brutus is None:
            hostname = socket.gethostname()
            if re.search(r'brutus', hostname):
                self._on_brutus = True
            else:
                self._on_brutus = False
        return self._on_brutus

    def submit(self, command):
        '''
        Submit a standard 8h job. Runs locally if not on the cluster.

        Parameters
        ----------
        command: List[str]
            elements of the bash command, e.g. ['find', '-name', 'bla*']
        '''
        if self.on_brutus:
            bsub = [
                 'bsub', '-W', '8:00', '-o', self.output_dir,
                 '-R', 'rusage[mem=4000,scratch=4000]'
            ]
            subprocess32.call(bsub + command)
        else:
            subprocess32.call(command)

@@ -3,16 +3,66 @@
 port re%0A
+import os%0Aimport yaml%0Aimport time%0Aimport datetime%0A
 import s
@@ -433,16 +433,1090 @@
 , n)%5D%0A%0A%0A
+def create_timestamp():%0A    '''%0A    Create timestamp in the form %22year-month-day_hour_minute_second%22.%0A    Returns%0A    -------%0A    str%0A        timestamp%0A    '''%0A    return datetime.fromtimestamp(time.time()).strftime('%25Y-%25m-%25d_%25H-%25M-%25S')%0A%0A%0Adef write_joblist(filename, joblist):%0A    '''%0A    Write joblist to YAML file.%0A%0A    Parameters%0A    ----------%0A    filename: str%0A        name of the YAML file%0A    joblist: List%5Bdict%5D%0A        job descriptions%0A    '''%0A    with open(filename, 'w') as joblist_file:%0A            joblist_file.write(yaml.dump(joblist, default_flow_style=False))%0A%0A%0Adef read_joblist(filename):%0A    '''%0A    Read joblist to YAML file.%0A%0A    Parameters%0A    ----------%0A    filename: str%0A        name of the YAML file%0A%0A    Returns%0A    -------%0A    List%5Bdict%5D%0A        job descriptions%0A%0A    Raises%0A    ------%0A    OSError%0A        when %60filename%60 does not exist%0A    '''%0A    if not os.path.exists(filename):%0A        raise OSError('Joblist file does not exist: %25s' %25 filename)%0A    with open(filename, 'r') as joblist_file:%0A            return yaml.load(joblist_file.read())%0A%0A%0A
 class Cl

Move functions related to job submission to cluster module