Esempio n. 1
0
 def _sendIfMsgs(self):
     if not self.zombie:
         msgs = [self.irc.takeMsg()]
         while msgs[-1] is not None:
             msgs.append(self.irc.takeMsg())
         del msgs[-1]
         self.outbuffer += ''.join(imap(str, msgs))
     if self.outbuffer:
         try:
             sent = self.conn.send(self.outbuffer)
             self.outbuffer = self.outbuffer[sent:]
             self.eagains = 0
         except socket.error, e:
             self._handleSocketError(e)
Esempio n. 2
0
 def _sendIfMsgs(self):
     if not self.zombie:
         msgs = [self.irc.takeMsg()]
         while msgs[-1] is not None:
             msgs.append(self.irc.takeMsg())
         del msgs[-1]
         self.outbuffer += ''.join(imap(str, msgs))
     if self.outbuffer:
         try:
             sent = self.conn.send(self.outbuffer)
             self.outbuffer = self.outbuffer[sent:]
             self.eagains = 0
         except socket.error, e:
             self._handleSocketError(e)
Esempio n. 3
0
                arg = '_%s.' % arg
                archPredicate = lambda s, arg=arg: (arg in s)
        predicates.append(archPredicate)
        for glob in globs:
            glob = fnmatch.translate(glob)
            predicates.append(re.compile(glob).search)
        packages = []
        try:
            fd = utils.web.getUrlFd('http://incoming.debian.org/')
        except utils.web.Error, e:
            irc.error(str(e), Raise=True)
        for line in fd:
            m = self._incomingRe.search(line)
            if m:
                name = m.group(1)
                if all(None, imap(lambda p: p(name), predicates)):
                    realname = utils.str.rsplit(name, '_', 1)[0]
                    packages.append(realname)
        if len(packages) == 0:
            irc.error('No packages matched that search.')
        else:
            irc.reply(format('%L', packages))

    incoming = thread(
        wrap(incoming, [
            getopts({
                'regexp': 'regexpMatcher',
                'arch': 'something'
            }),
            any('glob')
        ]))
Esempio n. 4
0
                arg = "_%s." % arg
                archPredicate = lambda s, arg=arg: (arg in s)
        predicates.append(archPredicate)
        for glob in globs:
            glob = fnmatch.translate(glob)
            predicates.append(re.compile(glob).search)
        packages = []
        try:
            fd = utils.web.getUrlFd("http://incoming.debian.org/")
        except utils.web.Error, e:
            irc.error(str(e), Raise=True)
        for line in fd:
            m = self._incomingRe.search(line)
            if m:
                name = m.group(1)
                if all(None, imap(lambda p: p(name), predicates)):
                    realname = utils.str.rsplit(name, "_", 1)[0]
                    packages.append(realname)
        if len(packages) == 0:
            irc.error("No packages matched that search.")
        else:
            irc.reply(format("%L", packages))

    incoming = thread(wrap(incoming, [getopts({"regexp": "regexpMatcher", "arch": "something"}), any("glob")]))

    def bold(self, s):
        if self.registryValue("bold", dynamic.channel):
            return ircutils.bold(s)
        return s

    _ptsUri = "http://packages.qa.debian.org/cgi-bin/soap-alpha.cgi"
Esempio n. 5
0
class Debian(callbacks.Plugin, PeriodicFileDownloader):
    threaded = True
    periodicFiles = {
        # This file is only updated once a week, so there's no sense in
        # downloading a new one every day.
        'Contents-i386.gz':
        ('ftp://ftp.us.debian.org/'
         'debian/dists/unstable/Contents-i386.gz', 604800, None)
    }
    contents = conf.supybot.directories.data.dirize('Contents-i386.gz')

    def file(self, irc, msg, args, optlist, glob):
        """[--{regexp,exact} <value>] [<glob>]

        Returns packages in Debian that includes files matching <glob>. If
        --regexp is given, returns packages that include files matching the
        given regexp.  If --exact is given, returns packages that include files
        matching exactly the string given.
        """
        self.getFile('Contents-i386.gz')
        # Make sure it's anchored, make sure it doesn't have a leading slash
        # (the filenames don't have leading slashes, and people may not know
        # that).
        if not optlist and not glob:
            raise callbacks.ArgumentError
        if optlist and glob:
            irc.error(
                'You must specify either a glob or a regexp/exact '
                'search, but not both.',
                Raise=True)
        for (option, arg) in optlist:
            if option == 'exact':
                regexp = arg.lstrip('/')
            elif option == 'regexp':
                regexp = arg
        if glob:
            regexp = fnmatch.translate(glob.lstrip('/'))
            regexp = regexp.rstrip('$')
            regexp = ".*%s.* " % regexp
        try:
            re_obj = re.compile(regexp, re.I)
        except re.error, e:
            irc.error(format('Error in regexp: %s', e), Raise=True)
        if self.registryValue('pythonZgrep'):
            fd = gzip.open(self.contents)
            r = imap(
                lambda tup: tup[0],
                ifilter(lambda tup: tup[0],
                        imap(lambda line: (re_obj.search(line), line), fd)))
        else:
            try:
                (r, w) = popen2.popen4(['zgrep', '-ie', regexp, self.contents])
                w.close()
            except TypeError:
                # We're on Windows.
                irc.error(
                    'This command won\'t work on this platform.  '
                    'If you think it should (i.e., you know that you '
                    'have a zgrep binary somewhere) then file a bug '
                    'about it at http://supybot.sf.net/ .',
                    Raise=True)
        packages = set()  # Make packages unique
        try:
            for line in r:
                if len(packages) > 100:
                    irc.error(
                        'More than 100 packages matched, '
                        'please narrow your search.',
                        Raise=True)
                try:
                    if hasattr(line, 'group'):  # we're actually using
                        line = line.group(0)  # pythonZgrep  :(
                    (filename, pkg_list) = line.split()
                    if filename == 'FILE':
                        # This is the last line before the actual files.
                        continue
                except ValueError:  # Unpack list of wrong size.
                    continue  # We've not gotten to the files yet.
                packages.update(pkg_list.split(','))
        finally:
            if hasattr(r, 'close'):
                r.close()
        if len(packages) == 0:
            irc.reply('I found no packages with that file.')
        else:
            irc.reply(format('%L', sorted(packages)))