def indices(self):
     l = getLogger("{}.{}".format(self.__class__.__name__, inspect_stack()[0][3]))
     if self._indices is None:
         self._indices = [x for x in self.stats.get(u'_all', {}).get(u'indices', {}).keys() if x.startswith(u'logstash')]
         self._indices.sort()
         l.debug('indices: %r', self._indices)
     return self._indices
コード例 #2
0
def current_usage(path):
    l = getLogger('{0}'.format(inspect_stack()[0][3]))
    filesystem, blocks, blocks_used, blocks_avail, percentage, mountpoint = \
        check_output(['/bin/df', path]).split('\n')[1].split()
    usage = int(percentage[:-1])
    l.debug("usage: %r", usage)
    return usage
 def es(self):
     l = getLogger("{}.{}".format(self.__class__.__name__, inspect_stack()[0][3]))
     if self._es is None:
         uri = '{0}:{1}'.format(self.host, self.port)
         l.debug('connecting to: %r', uri)
         self._es = Elastic(uri)
     return self._es
コード例 #4
0
    def _setup_patches(self, patch_args):
        """Creates mock instance attributes.

        Naming is as follows:
        @patch_object(object, attr) gets mock_object_attr
        @patch_dict(dictname) gets mock_dict_dictname
        @patch(thing) gets mock_thing

        Yes, you could name things such that they clobber each other,
        and no, this module won't protect you against that.
        So... it's probably a good idea if you Don't Do That.
        """

        l = getLogger("{0}.{1}".format(self.__class__.__name__,
                                       inspect_stack()[0][3]))
        l.debug("self.patches: {0!r} patch_args: {1!r}".format(
            self.patches, patch_args))

        self.assertEquals(
            len(self.patches[self.__class__.__name__]), len(patch_args),
            "self.patches[{0!r}] = {1!r}. This is not equal to {2!r}".format(
                self.__class__.__name__,
                self.patches.get(
                    self.__class__.__name__,
                    "missing patches for {0!r}".format(
                        self.__class__.__name__)), patch_args))

        for (cls, attr), mock in zip(self.patches[self.__class__.__name__],
                                     reversed(patch_args)):
            m = self.pretty_attribute.match(attr)
            readable_attr = m.group("tail") if m else attr
            mock_name = "mock_{0}".format(readable_attr) if cls is None \
                else "mock_{0}_{1}".format(cls.__name__, readable_attr)
            l.debug("setting {0!r} to {1!r}".format(mock_name, mock))
            setattr(self, mock_name, mock)
コード例 #5
0
 def stats(self):
     l = getLogger("{}.{}".format(self.__class__.__name__,
                                  inspect_stack()[0][3]))
     if self._stats is None:
         self._stats = self.es.get('_stats')
         l.debug('stats: %r', self._stats)
     return self._stats
def current_usage(path):
    l = getLogger('{0}'.format(inspect_stack()[0][3]))
    filesystem, blocks, blocks_used, blocks_avail, percentage, mountpoint = \
        check_output(['/bin/df', path]).split('\n')[1].split()
    usage = int(percentage[:-1])
    l.debug("usage: %r", usage)
    return usage
コード例 #7
0
    def _setup_patches(self, patch_args):
        """Creates mock instance attributes.

        Naming is as follows:
        @patch_object(object, attr) gets mock_object_attr
        @patch_dict(dictname) gets mock_dict_dictname
        @patch(thing) gets mock_thing

        Yes, you could name things such that they clobber each other,
        and no, this module won't protect you against that.
        So... it's probably a good idea if you Don't Do That.
        """

        l = getLogger("{0}.{1}".format(self.__class__.__name__, inspect_stack()[0][3]))
        l.debug("self.patches: {0!r} patch_args: {1!r}".format(self.patches, patch_args))

        self.assertEquals(len(self.patches[self.__class__.__name__]), len(patch_args),
                "self.patches[{0!r}] = {1!r}. This is not equal to {2!r}".format(
                    self.__class__.__name__,
                    self.patches.get(self.__class__.__name__, "missing patches for {0!r}". format(self.__class__.__name__)),
                    patch_args))

        for (cls, attr), mock in zip(self.patches[self.__class__.__name__], reversed(patch_args)):
            m = self.pretty_attribute.match(attr)
            readable_attr = m.group("tail") if m else attr
            mock_name = "mock_{0}".format(readable_attr) if cls is None \
                else "mock_{0}_{1}".format(cls.__name__, readable_attr)
            l.debug("setting {0!r} to {1!r}".format(mock_name, mock))
            setattr(self, mock_name, mock)
コード例 #8
0
ファイル: debug.py プロジェクト: superstes/growautomation
    def __init__(self,
                 typ: str = None,
                 addition: str = None,
                 src_file: str = None,
                 debug: (int, bool) = None):
        if typ is None:
            typ = 'core'

        if src_file is None:
            self.name = inspect_getfile(inspect_stack()[1][0])

        else:
            self.name = src_file

        if debug is None:
            self.debug = True if config.AGENT.debug == 1 else False

        else:
            if type(debug) == bool:
                self.debug = debug

            else:
                self.debug = True if debug == 1 else False

        self.log_dir = f"{config.AGENT.path_log}/{typ}/{now('%Y')}"
        self.log_level = config.AGENT.log_level

        if addition is None:
            self.log_file = f"{self.log_dir}/{now('%m')}_{typ}.log"

        else:
            self.log_file = f"{self.log_dir}/{now('%m')}_{typ}_{addition.replace(' ', '_')}.log"

        self.status = self._check()
コード例 #9
0
 def __init__(self):
     super(B, self).__init__()
     l = getLogger('{0}.{1}'.format(self.__class__.__name__,
                                    inspect_stack()[0][3]))
     l.debug('B instantiated')
     l.info('B info')
     l.error('B exploding!!!')
コード例 #10
0
 def es(self):
     l = getLogger("{}.{}".format(self.__class__.__name__,
                                  inspect_stack()[0][3]))
     if self._es is None:
         uri = '{0}:{1}'.format(self.host, self.port)
         l.debug('connecting to: %r', uri)
         self._es = Elastic(uri)
     return self._es
コード例 #11
0
ファイル: debug.py プロジェクト: superstes/growautomation
def device_log(output: str, add: str, level: int = 1) -> bool:
    _src = inspect_getfile(inspect_stack()[1][0])

    if config.AGENT.device_log == 1:
        return MultiLog([
            Log(src_file=_src),
            Log(typ='device', addition=add, src_file=_src)
        ]).write(output=output, level=level)

    else:
        return Log(src_file=_src).write(output=output, level=level)
コード例 #12
0
 def indices(self):
     l = getLogger("{}.{}".format(self.__class__.__name__,
                                  inspect_stack()[0][3]))
     if self._indices is None:
         self._indices = [
             x for x in self.stats.get(u'_all', {}).get(
                 u'indices', {}).keys() if x.startswith(u'logstash')
         ]
         self._indices.sort()
         l.debug('indices: %r', self._indices)
     return self._indices
コード例 #13
0
def get_current_func_name():
    """
    获取当前被调用的函数名
    eg:
    class MyClass:
        def function_one(self):
            print("%s.%s invoked" % (self.__class__.__name__, get_current_function_name()))
    a = MyClass()
    a.function_one()
    :return:
    """
    return inspect_stack()[1][3]
コード例 #14
0
ファイル: debug.py プロジェクト: superstes/growautomation
def log(output: str,
        level: int = 1,
        logger_instance: Log = None,
        src_file: str = None) -> bool:
    # wrapper function so we don't need always to call the .write method
    if logger_instance is None:
        if src_file is None:
            src_file = inspect_getfile(inspect_stack()[1][0])

        return Log(src_file=src_file).write(output=output, level=level)

    else:
        return logger_instance.write(output=output, level=level)
コード例 #15
0
ファイル: basemenu.py プロジェクト: nephomaniac/simplecli
 def dprint(self, buf):
     if self.debug:
         stack = inspect_stack()
         caller_method = stack[1][0].f_code.co_name
         buf = "({0}:{1}): {2}".format(self.name, caller_method, buf)
         if self.logger:
             self.logger.setLevel(DEBUG)
             self.logger.debug(buf)
         else:
             if not buf.endswith("\n"):
                 buf += "\n"
             self.stderr.write(magenta(buf))
             self.stderr.flush()
コード例 #16
0
 def dprint(self, buf):
     if self.debug:
         stack = inspect_stack()
         caller_method = stack[1][0].f_code.co_name
         buf = "({0}:{1}): {2}".format(self.name, caller_method, buf)
         if self.logger:
             self.logger.setLevel(DEBUG)
             self.logger.debug(buf)
         else:
             if not buf.endswith("\n"):
                 buf += "\n"
             self.stderr.write(magenta(buf))
             self.stderr.flush()
コード例 #17
0
ファイル: parse_me.py プロジェクト: kmorse/hackfest
def real_parser(iostream):
    """Receipt parser. This could use a little work.
    """
    l = getLogger("{}".format(inspect_stack()[1][3]))
    r = dict()
    line = iostream.readline()
    while line:
        l.debug("read: %r", line)
        m = re.match(r"Store #(?P<store>\d+) +(?:eat|tko|tkc) +(?P<month>\d\d)/(?P<day>\d\d)/(?P<year>\d+) (?P<hour>\d\d):(?P<minute>\d\d):(?P<second>\d\d) *\n", line)
        if m:
            l.debug("match: %r", m.groups())
            store, month, day, year, hour, minute, second  = [int(x) for x in m.groups()]
            r["store_number"] = store
            r["date"] = datetime(2000 + year, month, day, hour, minute, second).isoformat(sep=" ")
            break
        else:
            l.debug("no match")
        line = iostream.readline()
    # I should probably parse a little more of the receipt...
    return r
コード例 #18
0
    def get_memberUserObjects(self, ids_only=False):
        """ Get the user objects corresponding to the membership list,
assuming we can."""
        member_groups = self.getProperty('member_groups',
                                         ['%s_member' % self.listId()])
        uids = []
        for gid in member_groups:
            group = self.acl_users.getGroupById(gid)
            uids += group.getUsers()

        if ids_only:
            retval = uids
        else:
            m = 'Getting all the user-objects in "%s"' % self.listId()
            log.warning(m)
            s = inspect_stack()[:2]
            log.warning(s)
            users = []
            for uid in uids:
                user = self.acl_users.getUser(uid)
                if user:
                    users.append(user)
            retval = users
        return retval
コード例 #19
0
    def get_memberUserObjects(self, ids_only=False):
        """ Get the user objects corresponding to the membership list,
assuming we can."""
        member_groups = self.getProperty('member_groups',
                                         ['%s_member' % self.listId()])
        uids = []
        for gid in member_groups:
            group = self.acl_users.getGroupById(gid)
            uids += group.getUsers()

        if ids_only:
            retval = uids
        else:
            m = 'Getting all the user-objects in "%s"' % self.listId()
            log.warning(m)
            s = inspect_stack()[:2]
            log.warning(s)
            users = []
            for uid in uids:
                user = self.acl_users.getUser(uid)
                if user:
                    users.append(user)
            retval = users
        return retval
コード例 #20
0
 def my_method(self):
     l = getLogger("{0}.{1}".format(self.__class__.__name__,
                                    inspect_stack()[0][3]))
     l.debug('debug output in my_method')
     l.info('info input in my_method')
コード例 #21
0
 def __init__(self):
     l = getLogger("{0}.{1}".format(self.__class__.__name__, inspect_stack()[0][3]))
     l.debug('A instantiated')
     l.info('A info')
     l.error('A exploding!!!')
コード例 #22
0
 def my_interesting_method(self):
     super(B, self).my_interesting_method()
     l = getLogger('{0}.{1}'.format(self.__class__.__name__, inspect_stack()[0][3]))
     l.debug('debug output in my_interesting_method')
     l.info('info input in my_interesting_method')
コード例 #23
0
 def __init__(self):
     super(B, self).__init__()
     l = getLogger('{0}.{1}'.format(self.__class__.__name__, inspect_stack()[0][3]))
     l.debug('B instantiated')
     l.info('B info')
     l.error('B exploding!!!')
コード例 #24
0
 def my_noisy_method(self):
     l = getLogger("{0}.{1}".format(self.__class__.__name__, inspect_stack()[0][3]))
     for x in range(1, 10):
         l.info('noisy %d', x)
     l.error('a real warning message!!!')
コード例 #25
0
ファイル: debug.py プロジェクト: superstes/growautomation
def web_log(output: str, level: int = 1) -> bool:
    _src = inspect_getfile(inspect_stack()[1][0])
    debug = config.SERVER.debug
    return Log(typ='web', src_file=_src, debug=debug).write(output=output,
                                                            level=level)
コード例 #26
0
def get_caller_name(level):
	"""level = 0 returns current function name"""
	from inspect import stack as inspect_stack
	return inspect_stack()[level + 1][3]
コード例 #27
0
 def delete_oldest_index(self):
     l = getLogger("{}.{}".format(self.__class__.__name__,
                                  inspect_stack()[0][3]))
     oldest_index = self.indices.pop(0)
     l.debug('deleting %r', oldest_index)
     return self.es.delete(oldest_index)
コード例 #28
0
 def my_noisy_method(self):
     l = getLogger("{0}.{1}".format(self.__class__.__name__,
                                    inspect_stack()[0][3]))
     for x in range(1, 10):
         l.info('noisy %d', x)
     l.error('a real warning message!!!')
コード例 #29
0
 def my_method(self):
     l = getLogger("{0}.{1}".format(self.__class__.__name__, inspect_stack()[0][3]))
     l.debug('debug output in my_method')
     l.info('info input in my_method')
コード例 #30
0
ファイル: debug.py プロジェクト: superstes/growautomation
def fns_log(output: str, level: int = 1) -> bool:
    _src = inspect_getfile(inspect_stack()[1][0])
    return Log(src_file=_src).write(output=output, level=level, system=True)
 def stats(self):
     l = getLogger("{}.{}".format(self.__class__.__name__, inspect_stack()[0][3]))
     if self._stats is None:
         self._stats = self.es.get('_stats')
         l.debug('stats: %r', self._stats)
     return self._stats
コード例 #32
0
 def __init__(self):
     l = getLogger("{0}.{1}".format(self.__class__.__name__,
                                    inspect_stack()[0][3]))
     l.debug('A instantiated')
     l.info('A info')
     l.error('A exploding!!!')
コード例 #33
0
 def my_interesting_method(self):
     super(B, self).my_interesting_method()
     l = getLogger('{0}.{1}'.format(self.__class__.__name__,
                                    inspect_stack()[0][3]))
     l.debug('debug output in my_interesting_method')
     l.info('info input in my_interesting_method')
 def delete_oldest_index(self):
     l = getLogger("{}.{}".format(self.__class__.__name__, inspect_stack()[0][3]))
     oldest_index = self.indices.pop(0)
     l.debug('deleting %r', oldest_index)
     return self.es.delete(oldest_index)