Exemplo n.º 1
0
 def ConfigParameterNotSet(callobj, args, kwargs, e):
     # Custom message to BE SENT TO THE LOGGER
     message = ''.join(["OnlyPSfiles"])
     # Sends the message and original error to the LOGGER
     _log_error(message, e)
     ### METHOD ACTIONS
     return args, kwargs, None
Exemplo n.º 2
0
 def PassThroughException(callobj, args, kwargs, e):
     # Custom message to BE SENT TO THE LOGGER
     message = ("")
     # Sends the message and original error to the LOGGER
     _log_error(message, e)
     ### METHOD ACTIONS
     return args, kwargs, None
Exemplo n.º 3
0
 def InvalidUploadFileType(callobj, args, kwargs, e):
     # Custom message to BE SENT TO THE LOGGER
     message = ("")
     # Sends the message and original error to the LOGGER
     _log_error(message, e)
     ### METHOD ACTIONS
     return args, kwargs, None
Exemplo n.º 4
0
 def FatalError(callobj, args, kwargs, e):
     # Custom message to BE SENT TO THE LOGGER
     message = ("")
     # Sends the message and original error to the LOGGER
     _log_error(message, e)
     ### METHOD ACTIONS
     raise FatalException(e)
Exemplo n.º 5
0
 def OnlyPSfiles(callobj, args, kwargs, e):
     # Custom message to BE SENT TO THE LOGGER
     message = ''.join([
         "Currently, only Postscript(.PS) files are valid.",
         "File is not a valid postscript file.", "Halting process. "
     ])
     # Sends the message and original error to the LOGGER
     _log_error(message, e)
     ### METHOD ACTIONS
     return args, kwargs, None
Exemplo n.º 6
0
    def QRNoteTestError(callobj, args, kwargs, e):
        # Custom message to BE SENT TO THE LOGGER
        message = ''.join(["Unable to create Rserve connection. "])

        # Sends the message and original error to the LOGGER
        _log_error(message, e)

        ### METHOD ACTIONS
        log.info("This is being called from method actions")
        return args, kwargs, True
Exemplo n.º 7
0
 def UnknownUploadError(callobj, args, kwargs, e):
     # Custom message to BE SENT TO THE LOGGER
     message = ''.join([
         "An unknown error (IOError) occurred while ",
         "attempting to upload an image to the API. ",
         "Error will be logged and processing will continue."
     ])
     # Sends the message and original error to the LOGGER
     _log_error(message, e)
     ### METHOD ACTIONS
     return args, kwargs, None
Exemplo n.º 8
0
 def UploadTestOnly(callobj, args, kwargs, e):
     # Custom message to BE SENT TO THE LOGGER
     message = ''.join([
         "TESTING ONLY: ", "Image will not be uploaded. ",
         "Change parameter 'UPLOAD_STATE' to 'Live' ",
         "in config file to enable live uploads."
     ])
     # Sends the message and original error to the LOGGER
     _log_error(message, e)
     ### METHOD ACTIONS
     callobj.URL = "/AbCd3"
     return args, kwargs, None
Exemplo n.º 9
0
 def InvalidURLafterUpload(callobj, args, kwargs, e):
     # Custom message to BE SENT TO THE LOGGER
     message = ''.join([
         "Unknown error ocurred in qrnote.upload_image().\n",
         "Failing API upload and returning.\n",
         str(type(e)), ":",
         str(e.message)
     ])
     # Sends the message and original error to the LOGGER
     _log_error(message, e)
     ### METHOD ACTIONS
     callobj.URL = "None"
     return args, kwargs, None
Exemplo n.º 10
0
 def ConfigFileParseError(callobj, args, kwargs, e):
     # Create custom message to BE SENT TO THE LOGGER
     message = ("".join([
         "The configuration file contains errors. ",
         "Please verify the contents of the file. "
     ]))
     # Sends the message and original error to the LOGGER
     # Remove this line if you don't want an error displayed
     _log_error(message, e)
     ### METHOD ACTIONS
     # CODE BELOW TO CORRECT ISSUE
     # All code acts on the self object
     raise FatalException()
Exemplo n.º 11
0
 def APIUploadError(callobj, args, kwargs, e):
     # Custom message to BE SENT TO THE LOGGER
     message = ''.join([
         "An unknown error occurred attempting to upload ",
         "image file to the API server. ", "ARGS: ",
         str(args), "KWARGS: ",
         str(kwargs), "ERROR: ",
         str(e)
     ])
     # Sends the message and original error to the LOGGER
     _log_error(message, e)
     ### METHOD ACTIONS
     return args, kwargs, None
Exemplo n.º 12
0
 def ConfigFileNoOption(callobj, args, kwargs, e):
     # Create custom message to BE SENT TO THE LOGGER
     message = ("".join([
         "Unable to find the specified section or option",
         "(variable) in config file. ",
         "Please verify the contents of the file. "
     ]))
     # Sends the message and original error to the LOGGER
     # Remove this line if you don't want an error displayed
     _log_error(message, e)
     ### METHOD ACTIONS
     # CODE BELOW TO CORRECT ISSUE
     # All code acts on the self object
     return args, kwargs, None
Exemplo n.º 13
0
 def ConfigFileNotFound(callobj, args, kwargs, e):
     # Create custom message to BE SENT TO THE LOGGER
     message = ("".join([
         "The configuration file was not found. ",
         "Please verify the file exists in the ",
         "appropriate path and is readable."
     ]))
     # Sends the message and original error to the LOGGER
     # Remove this line if you don't want an error displayed
     _log_error(message, e)
     ### METHOD ACTIONS
     # CODE BELOW TO CORRECT ISSUE
     # All code acts on the self object
     raise FatalException()
Exemplo n.º 14
0
    def FileDoesNotExist(callobj, args, kwargs, e):
        # Custom message to BE SENT TO THE LOGGER
        message = ("The file passed does not exist. ")
        # Sends the message and original error to the LOGGER
        _log_error(message, e)
        ### METHOD ACTIONS
        result = False

        # Here a dialogue box could be raised to get the corrected path
        # The return gor to the tryhandler, which will try and run the original
        # calling method again with the original variable names...so it's
        # important the callobj.variable is changed before returning.The
        # callobj does not have to be returned. It is modified in place.
        # Just the modified kwargs needs to be changed.
        #         kwargs["file"] = raw_input("enter a correct path...")
        #         if <successful>: result = True

        return args, kwargs, result
Exemplo n.º 15
0
    def ProcessScannedFileFailure(callobj, args, kwargs, e):
        # Create custom message to BE SENT TO THE LOGGER
        try:
            filename = str(args[0])
            message = "".join([
                "A problem occurred trying to process receipt '", filename,
                "'. ", "The receipt will be moved to './scans/.errors' ",
                "for troubleshooting. \n", "Receipt skipped."
            ])
            _log_error(message, e)
            # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            # All code should act on the 'callobj' object
            # MUST RETURN: args, kwargs, <Some result, be it True/False/str/whatever>
            #
            #The following error is often indicative of the return being incorrect
            #
            # Traceback (most recent call last):
            #     File "test.py", line xx, in <module>
            #     object.method('arg1', 'arg2', kwarg1=1, kwarg2=2)
            #     File "/opt/qrnote/lib/errorhandler/trywrappers.py", line 218, in wrapped
            #     stack()
            #     TypeError: 'NoneType' object is not iterable
            src = callobj.config.scans_dir  #+ str(filename)
            dst = callobj.config.scans_dir + "/.errors/"
            # It should be nearly impossible for two scans to be generated with
            # the same name, but if someone copies a file it could happen
            # This checks for that error and avoids overwriting
            result = move_file(src, dst, filename)

        except IndexError as e:
            message = "".join([
                "No filename was passed into method ",
                " when attempting to process reciept. \n", "Receipt skipped."
            ])

            _log_error(message, e)

            result = None

        return args, kwargs, result
Exemplo n.º 16
0
    def TEMPLATE(callobj, args, kwargs, e):
        """
        :NAME:
            template(callobj, args, kwargs, e)
            
        :DESCRIPTION:
        ===========================================================================
        A HANDLER METHOD MUST RETURN: 
            args, kwargs, <Some result, be it True/False/str/whatever>
        ===========================================================================
        
            This is a template for special error handlers to be used by 
            ErrorHandler when called by the handlertry decorator. It both parses 
            the information to be passed to the callobj log, as well as controls 
            attempts to fix the problem.
            
            The method name "TEMPLATE" should be replaced with a human-readable
            name WHICH MATCHES the trigger phrase used in handlertry AND 
            matches the search line in the custom Error string (see usage).  
            
            =================================================================
            'ErrorHandler' calls the proper handler method based on the error 
            keyword matched in the error string passed to the ErrorHandler. 
            =================================================================
            
            The search is done as...
             if str(MethodName).lower() in str(error_string).lower():
            
            The error keyword MUST MATCH THE METHOD NAME. I.e. To match 'TEMPLATE'
            the error string would have to be something like ...
            'Error: TEMPLATE Your thing in line 222 didn't work'
            
            THIS MEANS if you have two methods, 'ERR1' AND 'ERR10', the following...
            'Error: ERR1 Your thing in line 222 didn't work'
            'Error: ERR10 Your thing in line 222 didn't work'
            
            ... will always match method ERR1 ...SO IT IS RECOMMENDED YOU NAME
            THE METHODS VERY UNIQUELY AND CAREFULLY.
            
            I.e. 'StringNotFoundInLogError' 
            
        ===========================================================================
        A HANDLER METHOD MUST RETURN: 
            args, kwargs, <Some result, be it True/False/str/whatever>
        
        The following error is often indicative of the return being incorrect...
        
        Traceback (most recent call last):
             File "test.py", line xx, in <module>
             object.method('arg1', 'arg2', kwarg1=1, kwarg2=2)
             File "/opt/qrnote/lib/errorhandler/trywrappers.py",line 218,in wrapped
             stack()
             TypeError: 'NoneType' object is not iterable
        ===========================================================================
            
               
        :ARGUMENTS:
            self:    The ErrorHandler class object (standard use of self).  
    
            callobj: The "self" class object that used the handlertry decorator
                     which, in turn, resulted in the call of this method. The 
                     handler method can then act directly on this object during it's 
                     attempts to correct the problem.  
                     
            args:    The "args" of the method decorated by handlertry. These
                     can be modified and passed back to the decorated method
                     for its attempts to re-run the method.
                     
            kwargs:  The "kwargs" of the method decorated by handlertry. These
                     can be modified and passed back to the decorated method
                     for its attempts to re-run the method.
                     
            e:       The original error raised by the method decorated by 
                     handlertry. I.e. when the decorator trywrappers.handlertry
                     run the function, it grabs excetions as follows:
                     
                     try:
                         <code>
                     except Exception as e:
                         <e passed here>>
        
        :VARIABLES:
            No userland variables. 
            
        :RETURNS:
            args:    The original passed in parameter 'args', AFTER any 
                     modifications performed by this method.  
            
            kwargs:  The original passed in parameter 'kwargs', AFTER any 
                     modifications performed by this method.  
            
            result:  Any result to be passed back to the original decorated 
                     object method which raised the original error as 'e'.
        
        ===========================================================================
        A HANDLER METHOD MUST RETURN: 
            args, kwargs, <Some result, be it True/False/str/whatever>
        
        The following error is often indicative of the return being incorrect...
        
        Traceback (most recent call last):
             File "test.py", line xx, in <module>
             object.method('arg1', 'arg2', kwarg1=1, kwarg2=2)
             File "/opt/qrnote/lib/errorhandler/trywrappers.py",line 218,in wrapped
             stack()
             TypeError: 'NoneType' object is not iterable
        ===========================================================================
                     
    
        :USAGE:
            <the following lines added to customErr above>
            elif 'TriggerPhrase' in str(e): 
                return self.TriggerPhrase(callobj, args, kwargs, e)
            
            def TriggerPhrase(callobj, args, kwargs, e):
                # Messages and corrective code placed in appropriate places here
                return args, kwargs, result
        """
        # Create custom message to BE SENT TO THE LOGGER
        message = ("".join([
            "Template message part 1 is a list item. ",
            "Template message part 2 is a list item."
        ]))

        # Sends the message and original error to the LOGGER
        # Remove this line if you don't want an error displayed
        _log_error(message, e)
        ### METHOD ACTIONS
        # CODE BELOW TO CORRECT ISSUE
        # All code should act on the 'callobj' object

        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # MUST RETURN: args, kwargs, <Some result, be it True/False/str/whatever>
        #
        #The following error is often indicative of the return being incorrect
        #
        # Traceback (most recent call last):
        #     File "test.py", line xx, in <module>
        #     object.method('arg1', 'arg2', kwarg1=1, kwarg2=2)
        #     File "/opt/qrnote/lib/errorhandler/trywrappers.py", line 218, in wrapped
        #     stack()
        #     TypeError: 'NoneType' object is not iterable

        #         return args, kwargs, True
        return args, kwargs, str(sys._getframe().f_code.co_name)