# 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



class poe(Plugin):
    def __init__(self, logFileName):
        self.__log= Logger(logFileName)
        self.__failedPollTimes = 0

    def isLocalProcess(self):
        return True

    def getName(self):
        return 'poe'

    def getHPCResources(self, partition, max_nodes=None, min_nodes=2, min_walltime_m=30):
        return None

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

        submit_script = "#!/bin/bash -l" + "\n"
        submit_script += "#@ tasks_per_node = 1" + "\n"
        submit_script += "source /etc/profile.d/modules.sh" + "\n"
        submit_script += "module load mpi4py" + "\n"
        if localSetup:

# 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/poe.py
import commands
import os
import subprocess
import time
import traceback
from HPC.Logger import Logger
from HPC.HPCManagerPlugins.plugin import Plugin




class poe(Plugin):
    def __init__(self, logFileName):
        self.__log= Logger(logFileName)
        self.__failedPollTimes = 0

    def isLocalProcess(self):
        return True

    def getName(self):
        return 'poe'

    def getHPCResources(self, partition, max_nodes=None, min_nodes=2, min_walltime_m=30):
        return None

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

        submit_script = "#!/bin/bash -l" + "\n"
        submit_script += "#@ tasks_per_node = 1" + "\n"
        submit_script += "source /etc/profile.d/modules.sh" + "\n"
        submit_script += "module load mpi4py" + "\n"
        if localSetup:

            submit_script += localSetup + "\n"