Exemplo n.º 1
0
 def group(self, field, dic):
     from startups.misc import attrgetter
     if isinstance(dic, dict):
         for k, v in dic.items():
             v = groupby(attrgetter(field), v)
     else:
         v = groupby(attrgetter(field), dic)
     return v
Exemplo n.º 2
0
def _groupby(key, seq, **kwargs):
    """
	
	:param key:
	:param seq:
	:return:
	
	"""
    from collections import defaultdict
    from startups.misc import attrgetter

    fields_list = kwargs.get('fields_list', defaultdict(set))
    field_order = kwargs.get('field_order', list(fields_list))

    d = defaultdict(MessageList)
    attr = key[:]
    key = attrgetter(key)
    for item in seq:
        d[key(item)].append(item)

    fields_list[attr].update(d)

    field = attr
    return MessageList(dict(d),
                       fields_list=fields_list,
                       field_order=list(fields_list),
                       field=field)
Exemplo n.º 3
0
 def visit_table(
         self,
         layout):  #TOD pythonize, startups.core.ignore_parameterize('%')
     row_names = None
     report_id = attrgetter('parent.report_id', default='')(layout)
     titleset = set(layout.parent) - set([layout])
     if titleset and len(titleset) == 1:
         title = titleset.pop()
     table_content = self.get_table_content(layout)
     cols = layout.cols
     if layout.rheaders:
         header_row = table_content.pop(0)
     if layout.cheaders:
         row_names = [row[0][:] for row in table_content]
         header_row.pop(0)
     result = []
     for row in table_content:
         if layout.cheaders:
             row_name = row.pop(0)
             jrow = dict(zip(header_row, row))
             drow = {row_name: jrow}
             result.append(drow)
         else:
             jrow = list(zip(header_row, row))
             result.append(jrow)
     return {report_id: result}
Exemplo n.º 4
0
 def groupby(self, key, seq):
     from collections import defaultdict
     from startups.misc import attrgetter
     d = defaultdict(list)
     key = attrgetter(key)
     for item in seq:
         d[key(item)].append(item)
     return d
Exemplo n.º 5
0
    def grouped(self, *fields):  #TODO!!!!
        """
		
		:param fields:
		:return:
		TODO check it is being passed `ReporterMessage`
		"""
        #fields_list = self.fields_list = fields
        from toolz import groupby
        from startups.misc import attrgetter
        from collections import defaultdict
        self.fields_list = defaultdict(set)
        self.field_order = []

        for field in fields:
            if not self.fields_list:
                self._grouped = groupby(attrgetter(field), self.msgs)

                self.fields_list[field] = set(self._grouped.keys())
                self.field_order.append(field)

            else:
                for order in self.field_order:
                    for key in self.fields_list[order]:
                        if self._grouped.get(key):
                            print(key)
                            srt = self._grouped[key]
                            srt = self.group(field, srt)
                            self._grouped[key] = srt
                        #print(self._grouped[key])
                        #self._grouped[key] = groupby(attrgetter(field), self._grouped[key])
                        for subfield in self._grouped.get(key):
                            self.fields_list[field].add(subfield)
                self.field_order.append(field)

                #for k, v in self._grouped.items():
            #pylint.utils.get_module_and_frameid
            #
            #	grpkey = self._grouped[k]
            #
            #	self._grouped[k] = groupby(attrgetter(field), self._grouped[k])
            #	print(k, len(self._grouped[k]))
            #	for subfield in self._grouped[k]:
            #		self.fields_list[field].add(subfield)

            #for name in self.fields_list[-1:]:
            #	print(name, self.fields_list.index(name))
            #for k,v in self._grouped.items():
            #
            #	self._grouped = groupby(attrgetter(field), self.msgs)

        return self._grouped
Exemplo n.º 6
0
	def __init__(self, output=sys.stdout):
		"""Initializes with `messages`, and a holding container for
		options, and defaults.

		:param output: sys.stdout as default
		"""
		super(Reporter, self).__init__(output)
		#BaseReporter.__init__(self)
		self.messages = OrderedSet([])
		self.msgs = self.messages.items
		self.options = dict(module = set([]))
		self.current_module = None
		self.current_file = None
		self.default_template = '{symbol}: {msg} ({fullname})|{abspath}:{line}:{column}'
		self._template = attrgetter('linter.config.msg_template')(self)
		if not self._template:
			self._template = self.line_format[:]
		
		self.nodes = collections.defaultdict(set)
Exemplo n.º 7
0
REGISTRY.register([IMessage], IMessageComp, '', MessageComp)

classImplements(resolve('lintful.plugins.base', 'ReporterMessage'), IMessage)
classImplements(resolve('pylint.utils', '_MsgBase'), IMessage)

GSM.registerUtility(resolve('pylint.utils', '_MsgBase'), IMessage, '')
GSM.registerUtility(resolve('lintful.plugins.base', 'ReporterMessage'), IMessage, '')



#I.GSM.getAllUtilitiesRegisteredFor



	
REGISTERED_UTILITIES = sorted(GSM.registeredUtilities(), key=attrgetter('provided.__identifier__'))


INTERFACES = list(GSM._utility_registrations_cache._cache)

#print(list(ReporterMessage.__implemented__))

#GSM.utilities.registered([], I.IMessage)




#verifyClass(IMessage, ReporterMessage)

#implementedBy(ReporterMessage)(IMessage)