# 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 sys,os,ssl
import time
    import pika
from pUtil import tolog

    
                            
        #logger.debug(str(ssl_options_dict))
        # setup our connection parameters
        self.parameters = pika.ConnectionParameters(
                                                    host               = self.host,
                                                    port               = self.port,
                                                    virtual_host       = self.virtual_host,
                                                    credentials        = self.credentials,
                                                    socket_timeout     = self.socket_timeout,
                                                    ssl                = True,
                                                    ssl_options        = ssl_options_dict,
                                                   )
    
    def create_queue(self,name,routing_key):
        # declare a random queue which this job will use to receive messages
        # durable = survive reboots of the broker
        # exclusive = only current connection can access this queue
        # auto_delete = queue will be deleted after connection is closed
        self.channel.queue_declare(
                                   queue       = str(name),
                                   durable     = self.queue_is_durable,
                                   exclusive   = self.queue_is_exclusive,
                                   auto_delete = self.queue_is_auto_delete
                                  )
    
        # now bind this queue to the exchange, using a routing key
        # any message submitted to the exchange with the
        # routing key will appear on this queue
        self.channel.queue_bind(exchange=self.exchange_name,

# 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: MessageInterface.py
import sys,os,ssl
import time
    import pika
from pUtil import tolog

    
                            
        #logger.debug(str(ssl_options_dict))
        # setup our connection parameters
        self.parameters = pika.ConnectionParameters(
                                                    host               = self.host,
                                                    port               = self.port,
                                                    virtual_host       = self.virtual_host,
                                                    credentials        = self.credentials,
                                                    socket_timeout     = self.socket_timeout,
                                                    ssl                = True,
                                                    ssl_options        = ssl_options_dict,
                                                   )
    
    def create_queue(self,name,routing_key):
        # declare a random queue which this job will use to receive messages
        # durable = survive reboots of the broker
        # exclusive = only current connection can access this queue
        # auto_delete = queue will be deleted after connection is closed
        self.channel.queue_declare(
                                   queue       = str(name),
                                   durable     = self.queue_is_durable,
                                   exclusive   = self.queue_is_exclusive,
                                   auto_delete = self.queue_is_auto_delete
                                  )
    
        # now bind this queue to the exchange, using a routing key
        # any message submitted to the exchange with the
        # routing key will appear on this queue
        self.channel.queue_bind(exchange=self.exchange_name,

                                queue=str(name),
