<commit_before>import pymel.all as pymel
import logging, logging.handlers
import sys
logger = logging.getLogger(__name__)

logLevelNames = [logging.getLevelName(n) for n in xrange(0,logging.CRITICAL+1,10)]
levelsDict = dict(zip(logLevelNames, range(0,logging.CRITICAL+1,10)))
levelsDict.update(dict(zip(range(0,logging.CRITICAL+1,10), logLevelNames)))

def refreshLoggerHierarchy():
    for v in logging.Logger.manager.loggerDict.values():
        try:
            del v.children
        except:pass

    for k, v in sorted(logging.Logger.manager.loggerDict.items()):
            if  not isinstance(v, logging.Logger):
                continue
            try:
                if v not in v.parent.children:
                    v.parent.children.append(v)
            except:
                v.parent.children = [v]

def initMenu():
    return LoggingMenu(parent=pymel.melGlobals["gMainWindow"])




class LoggingMenu(pymel.Menu):

    def refreshLoggingMenu(self):
        #pymel.Menu(self).deleteAllItems(1)
        self.buildSubMenu(self, logging.root)

    def changeLevel(self, item, level):
        logger.debug("Setting %s log level to %s" % (item, level))
        item.setLevel(levelsDict[level])

    def buildLevelMenu(self, parent, item):
        for level in logLevelNames:
            pymel.menuItem(p=parent, checkBox=levelsDict[item.level]==level, l=level, c=pymel.Callback(self.changeLevel, item, level))

    def buildSubMenu(self, parent, logger):
        #levelsMenu = pymel.menuItem(l="%s <%s>" % (logger.name, levelsDict[logger.level]),p=parent, sm=True)
        self.buildLevelMenu(parent, logger)
        pymel.menuItem(d=1,p=parent)
        try:
            if logger.children:
                pymel.menuItem(l="Child Loggers:",p=parent,en=0)
                for item in logger.children:
                    subMenu = pymel.menuItem(l=item.name, sm=True, p=parent, tearOff=True, aob=True, pmo=True)
                    subMenu.postMenuCommand(pymel.Callback(self.buildSubMenu, parent=subMenu, logger=item))
                    subMenu.setPostMenuCommandOnce(True)
        except: pass
        pymel.menuItem(d=1,p=parent)
        if logger.handlers:
            pymel.menuItem(l="Streams:",p=parent,en=0)
            for item in logger.handlers:
                levelsMenu = pymel.menuItem(l="%s <%s>" % (item.__class__.__name__, levelsDict[item.level]), p=parent, sm=True, aob=True)
                self.buildLevelMenu(levelsMenu, item)
                pymel.menuItem(d=1,p=levelsMenu)
                pymel.menuItem(l="Set Formatter", p=levelsMenu, c=pymel.Callback(self.setFormatter, item))
                pymel.menuItem(l="Remove", p=parent, ob=True, c=pymel.Callback(logger.removeHandler, item))
        pymel.menuItem(l="<New Stream...>", p=parent, c=lambda *x: self.addHandler(logger))

    def setFormatter(self, handler):
        tips = """
        name, levelno, levelname, pathname, filename, module, lineno, funcName, created,
        asctime, msecs, relativeCreated, thread, threadName, process, message
        """
        fmt = pymel.promptBox("Logging","Set Format:\n" + tips, "Set", "Cancel", tx=logging.BASIC_FORMAT)<commit_msg>fix bug preventing logging menus from displaying (calling old command)<commit_after>import pymel.all as pymel
import logging, logging.handlers
import sys
logger = logging.getLogger(__name__)

logLevelNames = [logging.getLevelName(n) for n in xrange(0,logging.CRITICAL+1,10)]
levelsDict = dict(zip(logLevelNames, range(0,logging.CRITICAL+1,10)))
levelsDict.update(dict(zip(range(0,logging.CRITICAL+1,10), logLevelNames)))

def refreshLoggerHierarchy():
    for v in logging.Logger.manager.loggerDict.values():
        try:
            del v.children
        except:pass

    for k, v in sorted(logging.Logger.manager.loggerDict.items()):
            if  not isinstance(v, logging.Logger):
                continue
            try:
                if v not in v.parent.children:
                    v.parent.children.append(v)
            except:
                v.parent.children = [v]

def initMenu():
    return LoggingMenu(parent=pymel.melGlobals["gMainWindow"])




class LoggingMenu(pymel.Menu):

    def refreshLoggingMenu(self):
        #pymel.Menu(self).deleteAllItems(1)
        self.buildSubMenu(self, logging.root)

    def changeLevel(self, item, level):
        logger.debug("Setting %s log level to %s" % (item, level))
        item.setLevel(levelsDict[level])

    def buildLevelMenu(self, parent, item):
        for level in logLevelNames:
            pymel.menuItem(p=parent, checkBox=levelsDict[item.level]==level, l=level, c=pymel.Callback(self.changeLevel, item, level))

    def buildSubMenu(self, parent, logger):
        #levelsMenu = pymel.menuItem(l="%s <%s>" % (logger.name, levelsDict[logger.level]),p=parent, sm=True)
        self.buildLevelMenu(parent, logger)
        pymel.menuItem(d=1,p=parent)
        try:
            if logger.children:
                pymel.menuItem(l="Child Loggers:",p=parent,en=0)
                for item in logger.children:
                    subMenu = pymel.menuItem(l=item.name, sm=True, p=parent, tearOff=True, aob=True, pmo=True)
                    subMenu.setPostMenuCommand(pymel.Callback(self.buildSubMenu, parent=subMenu, logger=item))
                    subMenu.setPostMenuCommandOnce(True)
        except: pass # this logger has no children
        pymel.menuItem(d=1,p=parent)
        if logger.handlers:
            pymel.menuItem(l="Streams:",p=parent,en=0)
            for item in logger.handlers:
                levelsMenu = pymel.menuItem(l="%s <%s>" % (item.__class__.__name__, levelsDict[item.level]), p=parent, sm=True, aob=True)
                self.buildLevelMenu(levelsMenu, item)
                pymel.menuItem(d=1,p=levelsMenu)
                pymel.menuItem(l="Set Formatter", p=levelsMenu, c=pymel.Callback(self.setFormatter, item))
                pymel.menuItem(l="Remove", p=levelsMenu, ob=True, c=pymel.Callback(logger.removeHandler, item))
        pymel.menuItem(l="<New Stream...>", p=parent, c=lambda *x: self.addHandler(logger))

    def setFormatter(self, handler):
        tips = """
        name, levelno, levelname, pathname, filename, module, lineno, funcName, created,
        asctime, msecs, relativeCreated, thread, threadName, process, message
        """
        fmt = pymel.promptBox("Logging","Set Format:\n" + tips, "Set", "Cancel", tx=logging.BASIC_FORMAT)
{'fraction_non_alphanumeric': 0.12818520820385332, 'fraction_numerical': 0.005593536357986327, 'mean_word_length': 2.8964891041162226, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1658687', 'n_tokens_mistral': 2098, 'n_tokens_neox': 2020, 'n_words': 387}