# Path: HPC/Logger.py
# class Logger:
#     def __init__(self, filename=None):
#         # get logger name
#         frm = inspect.stack()[1]
#         mod = inspect.getmodule(frm[0])
#         if mod == None or mod.__name__ == '__main__':
#             modName = 'main'
#         else:
#             modName = '.'.join(mod.__name__.split('.')[-2:])
#         global loggerMap
#         if modName in loggerMap:
#             # use existing logger
#             self.log = loggerMap[modName]
#         else:
#             # make handler
#             fmt = logging.Formatter('%(asctime)s|%(process)s|%(name)s|%(levelname)s| %(message)s',"%Y-%m-%d %H:%M:%S")
#             fmt.converter = time.gmtime
#             if filename:
#                 sh = logging.FileHandler(filename, mode='a')
#             else:
#                 sh = logging.StreamHandler(sys.stdout)
#             sh.setLevel(logging.DEBUG)
#             fmt.converter = time.gmtime
#             sh.setFormatter(fmt)
#             # make logger
#             self.log = logging.getLogger(modName)
#             self.log.propagate = False
#             self.log.addHandler(sh)
#             loggerMap[modName] = self.log
# 
# 
#     def info(self,msg):
#         self.log.info(msg)
# 
#     def debug(self,msg):
#         self.log.debug(msg)
# 
#     def warning(self,msg):
#         self.log.warning(msg)
# 
#     def error(self,msg):
#         self.log.error(msg)
# 
# Path: HPC/HPCManagerPlugins/plugin.py
# class Plugin:
#     def __init__(self, logFileName):
#         self.__log= Logger(logFileName)
# 
#     def isLocalProcess(self):
#         return False
# 
#     def getName(self):
#         return 'plugin'
# 
#     def getHPCResources(self, partition, max_nodes=None, min_nodes=2, min_walltime_m=30):
#         pass
# 
#     def submitJob(self):
#         pass
# 
#     def poll(self, jobid):
#         pass
# 
#     def delete(self, jobid):
#         pass


import commands
import os
import subprocess
import time
import traceback
from HPC.Logger import Logger
from HPC.HPCManagerPlugins.plugin import Plugin
            if '[' in nodelist:
                numNames = []
                tmp = nodelist
                preName, numList = tmp.split('[')
                numList,postName = numList.split(']')
                for items in numList.split(","):
                    if not '-' in items:
                        numNames.append(preName + items + postName)
                    else:
                        start, end = items.split('-')
                        numLen = len(start)
                        for i in range(int(start), int(end) + 1):
                            num = str(i).zfill(numLen)
                            numNames.append(preName + str(num) + postName)
                return ','.join(numNames)
            else:
                return nodelist
        except:
            self.__log.debug(traceback.format_exc())
            return nodelist

    def submitJob(self, globalWorkingDir, globalYodaDir, localWorkingDir, queue, repo, mppwidth, mppnppn, walltime, nodes, localSetup=None, cpuPerNode=None, dumpEventOutputs=False):

        nodelist = ""
        if os.environ.has_key('SLURM_NODELIST'):
            nodelist = os.environ['SLURM_NODELIST']
        elif os.environ.has_key('PBS_NODELIST'):
            nodelist = os.environ['PBS_NODELIST']
        nodelist = self.convertNodeList(nodelist)


# Path: HPC/Logger.py
# class Logger:
#     def __init__(self, filename=None):
#         # get logger name
#         frm = inspect.stack()[1]
#         mod = inspect.getmodule(frm[0])
#         if mod == None or mod.__name__ == '__main__':
#             modName = 'main'
#         else:
#             modName = '.'.join(mod.__name__.split('.')[-2:])
#         global loggerMap
#         if modName in loggerMap:
#             # use existing logger
#             self.log = loggerMap[modName]
#         else:
#             # make handler
#             fmt = logging.Formatter('%(asctime)s|%(process)s|%(name)s|%(levelname)s| %(message)s',"%Y-%m-%d %H:%M:%S")
#             fmt.converter = time.gmtime
#             if filename:
#                 sh = logging.FileHandler(filename, mode='a')
#             else:
#                 sh = logging.StreamHandler(sys.stdout)
#             sh.setLevel(logging.DEBUG)
#             fmt.converter = time.gmtime
#             sh.setFormatter(fmt)
#             # make logger
#             self.log = logging.getLogger(modName)
#             self.log.propagate = False
#             self.log.addHandler(sh)
#             loggerMap[modName] = self.log
# 
# 
#     def info(self,msg):
#         self.log.info(msg)
# 
#     def debug(self,msg):
#         self.log.debug(msg)
# 
#     def warning(self,msg):
#         self.log.warning(msg)
# 
#     def error(self,msg):
#         self.log.error(msg)
# 
# Path: HPC/HPCManagerPlugins/plugin.py
# class Plugin:
#     def __init__(self, logFileName):
#         self.__log= Logger(logFileName)
# 
#     def isLocalProcess(self):
#         return False
# 
#     def getName(self):
#         return 'plugin'
# 
#     def getHPCResources(self, partition, max_nodes=None, min_nodes=2, min_walltime_m=30):
#         pass
# 
#     def submitJob(self):
#         pass
# 
#     def poll(self, jobid):
#         pass
# 
#     def delete(self, jobid):
#         pass


# Path: HPC/HPCManagerPlugins/mpi.py
import commands
import os
import subprocess
import time
import traceback
from HPC.Logger import Logger
from HPC.HPCManagerPlugins.plugin import Plugin

            if '[' in nodelist:
                numNames = []
                tmp = nodelist
                preName, numList = tmp.split('[')
                numList,postName = numList.split(']')
                for items in numList.split(","):
                    if not '-' in items:
                        numNames.append(preName + items + postName)
                    else:
                        start, end = items.split('-')
                        numLen = len(start)
                        for i in range(int(start), int(end) + 1):
                            num = str(i).zfill(numLen)
                            numNames.append(preName + str(num) + postName)
                return ','.join(numNames)
            else:
                return nodelist
        except:
            self.__log.debug(traceback.format_exc())
            return nodelist

    def submitJob(self, globalWorkingDir, globalYodaDir, localWorkingDir, queue, repo, mppwidth, mppnppn, walltime, nodes, localSetup=None, cpuPerNode=None, dumpEventOutputs=False):

        nodelist = ""
        if os.environ.has_key('SLURM_NODELIST'):
            nodelist = os.environ['SLURM_NODELIST']
        elif os.environ.has_key('PBS_NODELIST'):
            nodelist = os.environ['PBS_NODELIST']
        nodelist = self.convertNodeList(nodelist)


        submit_script = "#!/bin/bash -l" + "\n"