#!/usr/bin/env python
'''
An abstraction of the IPython Parallel task interface.

Given a PBS_NODEFILE, this class launches the controller and engines via ssh
using a temporary profile.

Author: Monte Lunacek, monte.lunacek@colorado.edu

'''
import os
import subprocess
import time
import socket
import signal
import shutil
import sys
import argparse
import logging
import uuid
import jinja2 as jin
import datetime
import json

from IPython import parallel

# Template constants
ipcontroller = jin.Template('''
c = get_config()
c.HubFactory.ip = '*'

''')

ipengine = jin.Template('''
c = get_config()
c.EngineFactory.timeout = 300
c.IPEngineApp.log_to_file = True
c.IPEngineApp.log_level = 30
c.EngineFactory.ip = '*'

''')

class ClusterFormatter(logging.Formatter):
    def format(self, record):
        a = "{0}: {1}".format(datetime.date.today(), str(record.lineno).rjust(4))
        return "{0} {1}".format(a, record.msg)

def get_logger(debug):
    logger = logging.getLogger('ipcluster')