# Path: pUtil.py
# def tolog(msg, tofile=True, label='INFO', essential=False):
#     """ Write date+msg to pilot log and to stdout """
# 
#     try:
#         import inspect
# 
#         MAXLENGTH = 12
#         # getting the name of the module that is invoking tolog() and adjust the length
#         try:
#             module_name = os.path.basename(inspect.stack()[1][1])
#         except Exception, e:
#             module_name = "unknown"
#             #print "Exception caught by tolog(): ", e,
#         module_name_cut = module_name[0:MAXLENGTH].ljust(MAXLENGTH)
#         msg = "%i|%s| %s" % (os.getpid(),module_name_cut, msg)
# 
#         t = timeStampUTC(format='%Y-%m-%d %H:%M:%S')
#         if tofile:
#             appendToLog("%s|%s\n" % (t, msg))
# 
#         # remove backquotes from the msg since they cause problems with batch submission of pilot
#         # (might be present in error messages from the OS)
#         msg = msg.replace("`","'")
#         msg = msg.replace('"','\\"')
#         print "%s| %s" % (t, msg)
# 
#         # write any FAILED messages to stderr
#         if "!!FAILED!!" in msg:
#             try:
#                 print >> sys.stderr, "%s| %s" % (t, msg)
#             except:
#                 print "Failed to print to sys.stderr: %s" % (t, msg)
#     except:
#         print "!!WARNING!!4000!! %s" % traceback.format_exc()
# 
# def convert(data):
#     """ Convert unicode data to utf-8 """
# 
#     # Dictionary:
#     #   data = {u'Max': {u'maxRSS': 3664, u'maxSwap': 0, u'maxVMEM': 142260, u'maxPSS': 1288}, u'Avg': {u'avgVMEM': 94840, u'avgPSS': 850, u'avgRSS': 2430, u'avgSwap': 0}}
#     # convert(data)
#     #   {'Max': {'maxRSS': 3664, 'maxSwap': 0, 'maxVMEM': 142260, 'maxPSS': 1288}, 'Avg': {'avgVMEM': 94840, 'avgPSS': 850, 'avgRSS': 2430, 'avgSwap': 0}}
#     # String:
#     #   data = u'hello'
#     # convert(data)
#     #   'hello'
#     # List:
#     #   data = [u'1',u'2','3']
#     # convert(data)
#     #   ['1', '2', '3']
# 
#     import collections
#     if isinstance(data, basestring):
#         return str(data)
#     elif isinstance(data, collections.Mapping):
#         return dict(map(convert, data.iteritems()))
#     elif isinstance(data, collections.Iterable):
#         return type(data)(map(convert, data))
#     else:
#         return data
# 
# def readpar(parameter, alt=False, version=0, queuename=None):
#     """ Read 'parameter' from queuedata via SiteInformation class """
# 
#     from SiteInformation import SiteInformation
#     si = SiteInformation()
# 
#     return si.readpar(parameter, alt=alt, version=version, queuename=queuename)


import os
    import hashlib
from time import time
from commands import getoutput
from pUtil import tolog, convert, readpar
    from json import load
    from json import dump
    from json import load
        from json import load
    from glob import glob
    from re import compile, findall
                                    from re import compile
    from re import compile, findall
    from commands import getoutput
        from SiteMover import SiteMover
    from xml.dom import minidom

    directInLAN = useDirectAccessLAN()
    directInWAN = useDirectAccessWAN()
    directInType = 'None'

    directIn = False
    if directInLAN:
        directInType = 'LAN'
        directIn = True
    if directInWAN:
    # if (directInWAN and not analyjob) or (directInWAN and directInLAN and analyjob):
        directInType = 'WAN' # Overrides LAN if both booleans are set to True
        directIn = True

    return directIn, directInType

def _useDirectAccess(LAN=True, WAN=False):
    """ Should direct i/o be used over LAN or WAN? """

    useDA = False

    if LAN:
        par = 'direct_access_lan'
    elif WAN:
        par = 'direct_access_wan'
    else:
        tolog("!!WARNING!!3443!! Bad LAN/WAN combination: LAN=%s, WAN=%s" % (str(LAN), str(WAN)))
        par = ''

    if par != '':

# Path: pUtil.py
# def tolog(msg, tofile=True, label='INFO', essential=False):
#     """ Write date+msg to pilot log and to stdout """
# 
#     try:
#         import inspect
# 
#         MAXLENGTH = 12
#         # getting the name of the module that is invoking tolog() and adjust the length
#         try:
#             module_name = os.path.basename(inspect.stack()[1][1])
#         except Exception, e:
#             module_name = "unknown"
#             #print "Exception caught by tolog(): ", e,
#         module_name_cut = module_name[0:MAXLENGTH].ljust(MAXLENGTH)
#         msg = "%i|%s| %s" % (os.getpid(),module_name_cut, msg)
# 
#         t = timeStampUTC(format='%Y-%m-%d %H:%M:%S')
#         if tofile:
#             appendToLog("%s|%s\n" % (t, msg))
# 
#         # remove backquotes from the msg since they cause problems with batch submission of pilot
#         # (might be present in error messages from the OS)
#         msg = msg.replace("`","'")
#         msg = msg.replace('"','\\"')
#         print "%s| %s" % (t, msg)
# 
#         # write any FAILED messages to stderr
#         if "!!FAILED!!" in msg:
#             try:
#                 print >> sys.stderr, "%s| %s" % (t, msg)
#             except:
#                 print "Failed to print to sys.stderr: %s" % (t, msg)
#     except:
#         print "!!WARNING!!4000!! %s" % traceback.format_exc()
# 
# def convert(data):
#     """ Convert unicode data to utf-8 """
# 
#     # Dictionary:
#     #   data = {u'Max': {u'maxRSS': 3664, u'maxSwap': 0, u'maxVMEM': 142260, u'maxPSS': 1288}, u'Avg': {u'avgVMEM': 94840, u'avgPSS': 850, u'avgRSS': 2430, u'avgSwap': 0}}
#     # convert(data)
#     #   {'Max': {'maxRSS': 3664, 'maxSwap': 0, 'maxVMEM': 142260, 'maxPSS': 1288}, 'Avg': {'avgVMEM': 94840, 'avgPSS': 850, 'avgRSS': 2430, 'avgSwap': 0}}
#     # String:
#     #   data = u'hello'
#     # convert(data)
#     #   'hello'
#     # List:
#     #   data = [u'1',u'2','3']
#     # convert(data)
#     #   ['1', '2', '3']
# 
#     import collections
#     if isinstance(data, basestring):
#         return str(data)
#     elif isinstance(data, collections.Mapping):
#         return dict(map(convert, data.iteritems()))
#     elif isinstance(data, collections.Iterable):
#         return type(data)(map(convert, data))
#     else:
#         return data
# 
# def readpar(parameter, alt=False, version=0, queuename=None):
#     """ Read 'parameter' from queuedata via SiteInformation class """
# 
#     from SiteInformation import SiteInformation
#     si = SiteInformation()
# 
#     return si.readpar(parameter, alt=alt, version=version, queuename=queuename)


# Path: FileHandling.py
import os
    import hashlib
from time import time
from commands import getoutput
from pUtil import tolog, convert, readpar
    from json import load
    from json import dump
    from json import load
        from json import load
    from glob import glob
    from re import compile, findall
                                    from re import compile
    from re import compile, findall
    from commands import getoutput
        from SiteMover import SiteMover
    from xml.dom import minidom


    directInLAN = useDirectAccessLAN()
    directInWAN = useDirectAccessWAN()
    directInType = 'None'

    directIn = False
    if directInLAN:
        directInType = 'LAN'
        directIn = True
    if directInWAN:
    # if (directInWAN and not analyjob) or (directInWAN and directInLAN and analyjob):
        directInType = 'WAN' # Overrides LAN if both booleans are set to True
        directIn = True

    return directIn, directInType

def _useDirectAccess(LAN=True, WAN=False):
    """ Should direct i/o be used over LAN or WAN? """

    useDA = False

    if LAN:
        par = 'direct_access_lan'
    elif WAN:
        par = 'direct_access_wan'
    else:
        tolog("!!WARNING!!3443!! Bad LAN/WAN combination: LAN=%s, WAN=%s" % (str(LAN), str(WAN)))
        par = ''

    if par != '':

        da = readpar(par)