コード例 #1
0
 def _post_(self, *z, verbose=True, stdout=DEVNULL, stderr=DEVNULL, **zz):
     retval = self.f(*z, stdout=stdout, stderr=stderr, **zz)
     if verbose:
         #msg=self.verbose_msg + ("SUCCESS" if retval==0 else "FAILED")
         msg = self.verbose_msg + ("SUCCESS" if retval == 0 else "FAILED")
         log(msg, level=INFO)
     return (retval)
コード例 #2
0
 def call_1(self, *z, def_zz=def_zz, **zz):
     retval = ""  #self.f(*z,**zz)
     if type(retval) is int:
         if verbose:
             log("success" if retval == 0 else "failed")
         return (retval)
     else:
         return retval
コード例 #3
0
        def get_call(cls, def_zz={}):
            log(cls, def_zz)
            call_0 = cls.get_call_0(cls, def_zz=def_zz)
            call_1 = cls.get_call_1(cls, def_zz=def_zz)

            def call(*z, **zz):
                call_0(*z, **zz)
                return call_1(*z, **zz)

            return call
コード例 #4
0
 def _post_(self, *z, verbose=True, shorten_msg="tw", msg=None, **zz):
     retval = self.f(*z, **zz)
     if verbose:
         result = ("SUCCESS" if retval == 0 else "FAILED")
         msg = self._get_msg0_(*z,
                               msg=msg,
                               verbose=verbose,
                               result=result,
                               **zz)
         log(msg, level=self.loglevel)
     return (retval)
コード例 #5
0
 def _post_(self, *z, verbose=True, stdout=None, stderr=DEVNULL, **zz):
     if verbose:
         try:
             retval = self.f(*z, stderr=stderr, **zz)
             msg = self.verbose_msg + "SUCCESS"
             log(msg, level=INFO)
             return retval
         except Exception as e:
             msg = self.verbose_msg + "FAILED"
             log(msg, level=INFO)
             raise
     else:
         return self.f(*z, stderr=stderr, **zz)
コード例 #6
0
def call(*z,
         shorten_msg='tw',
         verbose=True,
         msg=None,
         stdout=DEVNULL,
         stderr=DEVNULL,
         loglevel=INFO,
         log2stderr=False,
         **zz):
    retval = subprocess_call(*z, stdout=stdout, stderr=stderr, **zz)
    if verbose:
        result = ("SUCCESS" if retval == 0 else "FAILED")
        msg = _get_msg0_(*z, msg=msg, verbose=verbose, result=result, **zz)
        log(msg, level=loglevel, log2stderr=log2stderr)
    return (retval)
コード例 #7
0
 def __init__(self,
              *z,
              stdout=DEVNULL,
              stderr=DEVNULL,
              verbose=True,
              loglevel=INFO,
              msg=None,
              log2stderr=False,
              **zz):
     if verbose:
         log(_get_msg0_(msg=("BGRND: " + str(z)) if msg is None else msg,
                        verbose=verbose,
                        result="",
                        log2stderr=stderr),
             level=INFO)
     super().__init__(*z, stdout=stdout, stderr=stderr, **zz)
コード例 #8
0
def check_func(*z,
               func=None,
               verbose=True,
               shorten_msg="tw",
               stdout="not allowed",
               loglevel=INFO,
               msg=None,
               log2stderr=False,
               **zz):
    if verbose:
        exc = None
        try:
            retval = func(*z, **zz)
            result = "SUCCESS"
        except Exception as e:
            result = "FAILED"
            exc = e
        msg = _get_msg0_(*z, msg=msg, verbose=verbose, result=result, **zz)
        log(msg, level=loglevel, log2stderr=log2stderr)
        if not exc is None:
            raise exc
    return retval
コード例 #9
0
 def call_0(*z, def_zz=def_zz, **zz):
     global stderr
     global stdout
     if not 'stderr' in zz.keys():
         zz['stderr'] = stderr
     if not 'stdout' in zz.keys():
         zz['stdout'] = stdout
     elif self.no_stdout:
         zz.pop("stdout")
     if def_zz['verbose'] and def_zz['msg'] is None:
         msg = str(z)
     end = " ... "
     head = "CMD: "
     if verbose and shorten_msg == 'tw':
         if isatty(0):
             maxlen = get_terminal_size().columns - len(end) - len(
                 head)
         else:
             maxlen = DEFAULT_MAXLEN - len(end) - len(head)
         if len(msg) > maxlen:
             msg = msg[:maxlen]
     if verbose:
         log(head + msg, end=end)
コード例 #10
0
 def _post_(self,
            *z,
            verbose=True,
            shorten_msg="tw",
            stdout="not allowed",
            msg=None,
            **zz):
     if verbose:
         exc = None
         try:
             retval = self.f(*z, **zz)
             result = "SUCCESS"
         except Exception as e:
             result = "FAILED"
             exc = e
         msg = self._get_msg0_(*z,
                               msg=msg,
                               verbose=verbose,
                               result=result,
                               **zz)
         log(msg, level=self.loglevel)
         if not exc is None:
             raise exc
     return retval
コード例 #11
0
 def init(self, f, *z, def_zz=def_zz, **zz):
     self.f = f
     log("##############")
コード例 #12
0
 def __init__(self, *z, exclude_kwargs=[], initdec=False, **zz):
     log("__init__", self.__class__.__name__)
コード例 #13
0
 def __init__(self, *z, **zz):
     log("uisufi")
コード例 #14
0
 def __new__(cls, *z, **zz):
     log("__new__", cls.__name__)
コード例 #15
0
 def __new__(cls, *z, exclude_kwargs=[], **zz):
     log("__new__", cls.__name__)
     d = cls.DecoratorGenerator(*z, exclude_kwargs=exclude_kwargs, **zz)
     c = d.Decorator
     log("__new__", cls.__name__)
     return d.Decorator.__new__(c, *z, **zz)
コード例 #16
0
 def _post_(self, *z, stdout=DEVNULL, stderr=DEVNULL, verbose=True, **zz):
     self.f(*z, stdout=stdout, stderr=stderr, **zz)
     if verbose:
         log("BGRND: " + self.verbose_msg, level=INFO)