python decorators not taking the value from constant passed

Viewed 162

report.py

if __name__ == "__main__":    
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description = "CHECK-ACCESS REPORTING.")
    parser.add_argument('--input','-i', help='Filepath containing the Active Directory userlist')
    parser.add_argument('--timestamp', '-t', nargs='?',const="BLANK", help='filepath with environement varible set')        
    args, unknownargs = parser.parse_known_args(sys.argv[1:])

    timestampchecker(args.timestamp)
    #checking the value of cons.DISPLAYRESULT is TRUE        
    main()

timestampchecker function :

def timestampchecker(status):
    """ Check if the timestamp is to display or not from command line"""
    if status is not None:
        cons.DISPLAY_TIME_STAMP = True

This function checks if the user have set the -t arguments. If it is set I have defined one constant called cons.DISPLAYRESULT to true.

The function is working great and turning the constant value to True. But in the main function I have implemented this decorators which is not taking the true value but false

timer.py

def benchmarking(timestaus):
    def wrapper(funct):
        def timercheck(*args, **kwarg):
            if timestaus is True:
                starttime=time.time()
            funct(*args, **kwarg)
            if timestaus is True:
                print('Time Taken:',round(time.time()-starttime, 4))
        return timercheck
    return wrapper

I have decorated some method in main() method of report.py with the decorators above. For example This is the class being used in report.py and being decorated with above decorators

class NotAccountedReport:

    def __init__(self, pluginoutputpath):
        """ Path where the plugins result are stored need these files"""

        self.pluginoutputpath = pluginoutputpath

    @benchmarking(cons.DISPLAY_TIME_STAMP)
    def makeNotAccountableReport():
        #some functionality

here I have passed the constant value to the argument decorator which when tested though before called is converted to True is taking false and thus the decorators not being implemented. Where is the problem cant figure out

1 Answers
Related