Esempio n. 1
0
    def get_maintainer(self, package):
        maintainer = pseudo_packages.get_maintainer(package)
        if maintainer is not None:
            return split_address(maintainer)

        if package in self.cache:
            candidate = self.depcache.get_candidate_ver(self.cache[package])
            if candidate is not None:
                records = apt_pkg.PackageRecords(self.cache)
                if records.lookup(candidate.file_list[0]):
                    return split_address(records.maintainer)

                # delete record iterator
                del records

        if package.startswith("src:"):
            package = package[4:]

        records = apt_pkg.SourceRecords()
        if records.lookup(package):
            version = records.version
            maintainer = records.maintainer
            while records.lookup(package) is not None:
                if apt_pkg.version_compare(records.version, version) > 0:
                    version = records.version
                    maintainer = records.maintainer

            return split_address(maintainer)

        raise NewDataSource.DataError(
            "Unable to get maintainer for {}.".format(package)
        )
Esempio n. 2
0
    def _email_callback(self, fileobj):
        try:
            emailmsg = parse_mail(fileobj)
            msg = get_message(emailmsg, new_queue=self.new_queue)

            if not msg:
                return

            txt = colourise(msg.for_irc())

            # Simple flood/duplicate detection
            if txt in self.last_n_messages:
                return
            self.last_n_messages.insert(0, txt)
            self.last_n_messages = self.last_n_messages[:20]

            maintainer_info = None
            if hasattr(msg, 'maintainer'):
                maintainer_info = (split_address(msg.maintainer), )
            else:
                maintainer_info = []
                for package in msg.package.split(','):
                    package = package.strip()
                    try:
                        maintainer_info.append(
                            self.apt_archive.get_maintainer(package))
                    except NewDataSource.DataError as e:
                        log.info("Failed to query maintainer for {}.".format(
                            package))

            for channel in self.irc.state.channels:
                package_regex = self.registryValue(
                    'package_regex',
                    channel,
                ) or 'a^'  # match nothing by default

                package_match = re.search(package_regex, msg.package)

                maintainer_match = False
                maintainer_regex = self.registryValue('maintainer_regex',
                                                      channel)
                if maintainer_regex and maintainer_info is not None and len(
                        maintainer_info) >= 0:
                    for mi in maintainer_info:
                        maintainer_match = re.search(maintainer_regex,
                                                     mi['email'])
                        if maintainer_match:
                            break

                if not package_match and not maintainer_match:
                    continue

                distribution_regex = self.registryValue(
                    'distribution_regex',
                    channel,
                )

                if distribution_regex:
                    if not hasattr(msg, 'distribution'):
                        # If this channel has a distribution regex, don't
                        # bother continuing unless the message actually has a
                        # distribution. This filters security messages, etc.
                        continue

                    if not re.search(distribution_regex, msg.distribution):
                        # Distribution doesn't match regex; don't send this
                        # message.
                        continue

                send_privmsg = self.registryValue('send_privmsg', channel)
                # Send NOTICE per default and if 'send_privmsg' is set for the
                # channel, send PRIVMSG instead.
                if send_privmsg:
                    ircmsg = supybot.ircmsgs.privmsg(channel, txt)
                else:
                    ircmsg = supybot.ircmsgs.notice(channel, txt)

                self.irc.queueMsg(ircmsg)

        except Exception as e:
            log.exception('Uncaught exception: %s ' % e)
Esempio n. 3
0
 def testSplitAddress2(self):
     addr = split_address("*****@*****.**")
     self.assertEqual(addr["name"], "")
     self.assertEqual(addr["email"], "*****@*****.**")
Esempio n. 4
0
 def testSplitAddress1(self):
     addr = split_address("Sebastian Ramacher <*****@*****.**>")
     self.assertEqual(addr["name"], "Sebastian Ramacher")
     self.assertEqual(addr["email"], "*****@*****.**")
Esempio n. 5
0
    def _email_callback(self, fileobj):
        try:
            emailmsg = parse_mail(fileobj)
            msg = get_message(emailmsg, new_queue=self.new_queue)

            if not msg:
                return

            txt = colourise(msg.for_irc())

            # Simple flood/duplicate detection
            if txt in self.last_n_messages:
                return
            self.last_n_messages.insert(0, txt)
            self.last_n_messages = self.last_n_messages[:20]

            maintainer_info = None
            if hasattr(msg, 'maintainer'):
                maintainer_info = (split_address(msg.maintainer), )
            else:
                maintainer_info = []
                for package in msg.package.split(','):
                    package = package.strip()
                    try:
                        maintainer_info.append(self.apt_archive.get_maintainer(package))
                    except NewDataSource.DataError as e:
                        log.info("Failed to query maintainer for {}.".format(package))

            for channel in self.irc.state.channels:
                package_regex = self.registryValue(
                    'package_regex',
                    channel,
                ) or 'a^'  # match nothing by default

                package_match = re.search(package_regex, msg.package)

                maintainer_match = False
                maintainer_regex = self.registryValue(
                    'maintainer_regex',
                    channel)
                if maintainer_regex and maintainer_info is not None and len(maintainer_info) >= 0:
                    for mi in maintainer_info:
                        maintainer_match = re.search(maintainer_regex, mi['email'])
                        if maintainer_match:
                            break

                if not package_match and not maintainer_match:
                    continue

                distribution_regex = self.registryValue(
                    'distribution_regex',
                    channel,
                )

                if distribution_regex:
                    if not hasattr(msg, 'distribution'):
                        # If this channel has a distribution regex, don't
                        # bother continuing unless the message actually has a
                        # distribution. This filters security messages, etc.
                        continue

                    if not re.search(distribution_regex, msg.distribution):
                        # Distribution doesn't match regex; don't send this
                        # message.
                        continue

                send_privmsg = self.registryValue('send_privmsg', channel)
                # Send NOTICE per default and if 'send_privmsg' is set for the
                # channel, send PRIVMSG instead.
                if send_privmsg:
                    ircmsg = supybot.ircmsgs.privmsg(channel, txt)
                else:
                    ircmsg = supybot.ircmsgs.notice(channel, txt)

                self.irc.queueMsg(ircmsg)

        except Exception as e:
            log.exception('Uncaught exception: %s ' % e)
Esempio n. 6
0
 def testSplitAddress2(self):
     addr = split_address('*****@*****.**')
     self.assertEqual(addr['name'], '')
     self.assertEqual(addr['email'], '*****@*****.**')
Esempio n. 7
0
 def testSplitAddress1(self):
     addr = split_address('Sebastian Ramacher <*****@*****.**>')
     self.assertEqual(addr['name'], 'Sebastian Ramacher')
     self.assertEqual(addr['email'], '*****@*****.**')