# 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()


import os
import commands
from pUtil import tolog
            from pickle import load
        from pickle import dump
                self.fileStateDictionary[filename] = ['not_transferred', 'copy_to_scratch']

        # write to file
        status = self.put()

    def hasOnlyCopyToScratch(self):
        """ Check if there are only copy_to_scratch transfer modes in the file dictionary """

        status = True

        # loop over all input files and see if there is any non-copy_to_scratch transfer mode
        for filename in self.fileStateDictionary.keys():
            # get the file states
            states = self.fileStateDictionary[filename]
            tolog("filename=%s states=%s"%(filename, str(states)))
            if states[1] != 'copy_to_scratch' and states[1] != 'no_transfer': # 'no_transfer' is set for DBRelease files
                tolog("Job does not have only copy-to-scratch transfers")
                status = False
                break
        return status

    def getFilesOfState(self, state="transferred"):
        """ Return a comma-separated list of files for a given transfer type """

        file_names = []

        # loop over all files
        for filename in self.fileStateDictionary.keys():
            # get the file states
            states = self.fileStateDictionary[filename]

# 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()


# Path: FileState.py
import os
import commands
from pUtil import tolog
            from pickle import load
        from pickle import dump

                self.fileStateDictionary[filename] = ['not_transferred', 'copy_to_scratch']

        # write to file
        status = self.put()

    def hasOnlyCopyToScratch(self):
        """ Check if there are only copy_to_scratch transfer modes in the file dictionary """

        status = True

        # loop over all input files and see if there is any non-copy_to_scratch transfer mode
        for filename in self.fileStateDictionary.keys():
            # get the file states
            states = self.fileStateDictionary[filename]
            tolog("filename=%s states=%s"%(filename, str(states)))
            if states[1] != 'copy_to_scratch' and states[1] != 'no_transfer': # 'no_transfer' is set for DBRelease files
                tolog("Job does not have only copy-to-scratch transfers")
                status = False
                break
        return status

    def getFilesOfState(self, state="transferred"):
        """ Return a comma-separated list of files for a given transfer type """

        file_names = []

        # loop over all files
        for filename in self.fileStateDictionary.keys():
            # get the file states
            states = self.fileStateDictionary[filename]

            tolog("filename=%s states=%s"%(filename,str(states)))