# Path: Logger.py
# class Logger:
# 
#     sh1 = None
#     sh2 = None
# 
#     def __init__(self, filename=None):
# 
#         # get logger name
#         print inspect.stack()
#         frm = inspect.stack()[1]
#         mod = inspect.getmodule(frm[2])
#         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 = MyFormatter()
#             fmt.converter = time.gmtime # to convert timestamps to UTC
# #            if filename:
# #                sh = logging.FileHandler(filename, mode='a')
# #            else:
# #                sh = logging.StreamHandler(sys.stdout)
#             self.sh1 = logging.FileHandler(filename, mode='a')
#             self.sh2 = logging.StreamHandler(sys.stdout)
#             self.sh1.setLevel(logging.DEBUG)
#             self.sh1.setFormatter(fmt)
#             self.sh2.setLevel(logging.DEBUG)
#             self.sh2.setFormatter(fmt)
# 
#             # make logger
#             self.log = logging.getLogger(modName)
#             self.log.propagate = False
#             self.log.addHandler(self.sh1)
#             self.log.addHandler(self.sh2)
#             loggerMap[modName] = self.log
# 
#     def info(self, msg):
#         self.log.info(msg)
#         #self.sh1.flush()
#         #self.sh2.flush()
# 
#     def debug(self, msg):
#         self.log.debug(msg)
# 
#     def warning(self, msg):
#         self.log.warning(msg)
# 
#     def error(self, msg):
#         self.log.error(msg)
# 
#     def critical(self, msg):
#         self.log.critical(msg)


import commands
import os
import shutil
import sys
import time
import traceback
import json
import pickle
import logging
from Logger import Logger
            from pandayoda.yodacore import Database

        self.__copyInputFiles = copyInputFiles

        self.__mode = None
        self.__jobs = {}
        self.__jobsFile = None
        self.__eventRanges = None
        self.__eventRangesFile = None
        self.__jobid = None
        self.__stageout_threads = 1
        self.__pandaJobStateFile = None

        self.__pluginName = 'pbs'
        self.__plugin = None
        self.__localSetup = None

        self.__firstJobWorkDir = None

    def __init__(self, globalWorkingDir=None, localWorkingDir=None, logFileName=None, copyInputFiles=False):
        self.__globalWorkingDir = globalWorkingDir
        # self.__globalYodaDir = os.path.join(globalWorkingDir, 'Yoda')
        self.__globalYodaDir = self.__globalWorkingDir
        if not os.path.exists(self.__globalYodaDir):
            os.makedirs (self.__globalYodaDir)
        self.__localWorkingDir = localWorkingDir
        if self.__localWorkingDir is None:
            self.__localWorkingDir = self.__globalYodaDir

        self.__jobStateFile = os.path.join(self.__globalYodaDir, 'HPCManagerState.json')
        self.__logFileName = logFileName

# Path: Logger.py
# class Logger:
# 
#     sh1 = None
#     sh2 = None
# 
#     def __init__(self, filename=None):
# 
#         # get logger name
#         print inspect.stack()
#         frm = inspect.stack()[1]
#         mod = inspect.getmodule(frm[2])
#         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 = MyFormatter()
#             fmt.converter = time.gmtime # to convert timestamps to UTC
# #            if filename:
# #                sh = logging.FileHandler(filename, mode='a')
# #            else:
# #                sh = logging.StreamHandler(sys.stdout)
#             self.sh1 = logging.FileHandler(filename, mode='a')
#             self.sh2 = logging.StreamHandler(sys.stdout)
#             self.sh1.setLevel(logging.DEBUG)
#             self.sh1.setFormatter(fmt)
#             self.sh2.setLevel(logging.DEBUG)
#             self.sh2.setFormatter(fmt)
# 
#             # make logger
#             self.log = logging.getLogger(modName)
#             self.log.propagate = False
#             self.log.addHandler(self.sh1)
#             self.log.addHandler(self.sh2)
#             loggerMap[modName] = self.log
# 
#     def info(self, msg):
#         self.log.info(msg)
#         #self.sh1.flush()
#         #self.sh2.flush()
# 
#     def debug(self, msg):
#         self.log.debug(msg)
# 
#     def warning(self, msg):
#         self.log.warning(msg)
# 
#     def error(self, msg):
#         self.log.error(msg)
# 
#     def critical(self, msg):
#         self.log.critical(msg)


# Path: HPC/HPCManager.py
import commands
import os
import shutil
import sys
import time
import traceback
import json
import pickle
import logging
from Logger import Logger
            from pandayoda.yodacore import Database


        self.__copyInputFiles = copyInputFiles

        self.__mode = None
        self.__jobs = {}
        self.__jobsFile = None
        self.__eventRanges = None
        self.__eventRangesFile = None
        self.__jobid = None
        self.__stageout_threads = 1
        self.__pandaJobStateFile = None

        self.__pluginName = 'pbs'
        self.__plugin = None
        self.__localSetup = None

        self.__firstJobWorkDir = None

    def __init__(self, globalWorkingDir=None, localWorkingDir=None, logFileName=None, copyInputFiles=False):
        self.__globalWorkingDir = globalWorkingDir
        # self.__globalYodaDir = os.path.join(globalWorkingDir, 'Yoda')
        self.__globalYodaDir = self.__globalWorkingDir
        if not os.path.exists(self.__globalYodaDir):
            os.makedirs (self.__globalYodaDir)
        self.__localWorkingDir = localWorkingDir
        if self.__localWorkingDir is None:
            self.__localWorkingDir = self.__globalYodaDir

        self.__jobStateFile = os.path.join(self.__globalYodaDir, 'HPCManagerState.json')
        self.__logFileName = logFileName

        self.__log= Logger(logFileName)