def __call__(self, func_):
        ensureAnnotationEnabled = "Y"
        if (StringUtils.stringEqualsIgnoreCase("Y", ensureAnnotationEnabled)):
            from functools import wraps
            from inspect import getcallargs

            @wraps(f)
            def wrapper(*args, **kwargs):
                for arg, val in getcallargs(func_, *args, **kwargs).items():
                    print(arg, val)
                    if arg in func_.__annotations__:
                        templ = func_.__annotations__[arg]
                        print(templ)
                        # msg = "Argument {arg} to {f} does not match annotation type {t}"
                        # Check(val).is_a(templ).or_raise(EnsureError, msg.format(arg=arg, f=f, t=templ))
                return_val = func_(*args, **kwargs)
                if 'return' in func_.__annotations__:
                    templ = func_.__annotations__['return']
                    msg = "Return value of {f} does not match annotation type {t}"
                    # Check(return_val).is_a(templ).or_raise(EnsureError, msg.format(f=f, t=templ))
                return return_val

            return wrapper
        else:
            return func_
 def checkForLatestPackage(self, imported_files):
     checkLatestPackageEnabled = "N"
     if (StringUtils.stringEqualsIgnoreCase("Y",
                                            checkLatestPackageEnabled)):
         checkLatestVersionForPackageList = [
             self.__checkLatestVersionForPackage(package_name)
             for package_name in imported_files
         ]
         print(checkLatestVersionForPackageList)
Esempio n. 3
0
 def __call__(self,func_):
     printNothingEnabled = "Y"
     if(StringUtils.stringEqualsIgnoreCase("Y",printNothingEnabled)):
         @wraps(func_)
         def wrapper(*args, **kwargs):
             CommonUtils.blockPrint()
             return_val = func_(*args, **kwargs)
             CommonUtils.enablePrint()
             return return_val
         return wrapper
     else:
         return func_
 def __call__(self,func_):
     entryExitMethodLoggerEnabled = "Y"
     if(StringUtils.stringEqualsIgnoreCase("Y",entryExitMethodLoggerEnabled)):
         @wraps(func_)
         def wrapper(*args, **kwargs):
             #add logger for entry
             print("Entering",func_.__name__+"()")
             return_val = func_(*args, **kwargs)
             #add logger for exit
             print("exiting",func_.__name__+"()")
             return return_val
         return wrapper
     else:
         return func_
Esempio n. 5
0
 def install(self, package):
     if (StringUtils.isStrNotBlank(package)):
         try:
             print(package + " is installing")
             if hasattr(pip, 'main'):
                 pip.main(['install', package])
             else:
                 pip._internal.main(['install', package])
             print(package + " downloading complete")
         except Exception as ex:
             print(ex)
             print("Stopping python program")
             print(package + " package is not downloaded")
             CommonUtils.stopExecution()
     else:
         CommonUtils.askUserToStopExecution()
Esempio n. 6
0
    def __call__(self, func_):
        handleExceptionEnabled = "False"
        handleExceptionExitEnabled = "False"
        if (StringUtils.stringEqualsIgnoreCase("Y", handleExceptionEnabled)):

            @wraps(func_)
            def wrapper(*args, **kwargs):
                try:
                    return_val = func_(*args, **kwargs)
                    return return_val
                except Exception as ex:
                    print(ex)
                    return ex

            return wrapper
        else:
            return func_
Esempio n. 7
0
 def stopWarningWithConfigValue():
     warningEnabled = "Y"
     if (StringUtils.stringEqualsIgnoreCase("Y", warningEnabled)):
         CommonUtils.stopWarning()
Esempio n. 8
0
 def askUserToStopExecution():
     user_input = str(input("stop excecution [Y/N] : "))
     if StringUtils.stringEqualsIgnoreCase("Y", user_input):
         CommonUtils.stopExecution()
     else:
         pass