Exemple #1
0
 def __init__(self, irc):
     self.__parent = super(RSS, self)
     self.__parent.__init__(irc)
     # Scheme: {name: url}
     self.feed_names = callbacks.CanonicalNameDict()
     # Scheme: {url: feed}
     self.feeds = {}
     if os.path.isfile(announced_headlines_filename):
         with open(announced_headlines_filename) as fd:
             announced = load_announces_db(fd)
     else:
         announced = {}
     for name in self.registryValue('feeds'):
         self.assert_feed_does_not_exist(name)
         self.register_feed_config(name)
         try:
             url = self.registryValue(registry.join(['feeds', name]))
         except registry.NonExistentRegistryEntry:
             self.log.warning('%s is not a registered feed, removing.',name)
             continue
         try:
             self.register_feed(name, url, True, True, announced.get(name, []))
         except InvalidFeedUrl:
             self.log.error('%s is not a valid feed, removing.', name)
             continue
     world.flushers.append(self._flush)
Exemple #2
0
 def __init__(self, irc):
     self.__parent = super(RSS, self)
     self.__parent.__init__(irc)
     # Scheme: {name: url}
     self.feed_names = callbacks.CanonicalNameDict()
     # Scheme: {url: feed}
     self.feeds = {}
     if os.path.isfile(announced_headlines_filename):
         with open(announced_headlines_filename) as fd:
             announced = load_announces_db(fd)
     else:
         announced = {}
     for name in self.registryValue("feeds"):
         self.assert_feed_does_not_exist(name)
         self.register_feed_config(name)
         try:
             url = self.registryValue(registry.join(["feeds", name]))
         except registry.NonExistentRegistryEntry:
             self.log.warning("%s is not a registered feed, removing.", name)
             continue
         try:
             self.register_feed(name, url, True, True, announced.get(name, []))
         except InvalidFeedUrl:
             self.log.error("%s is not a valid feed, removing.", name)
             continue
     world.flushers.append(self._flush)
Exemple #3
0
    def read_fortunes(self, name):
        assert name in self.registryValue('databases')
        url = self.registryValue(registry.join(['databases', name]))

        if utils.web.urlRe.match(url):
            fd = utils.web.getUrlFd(url)
        else:
            fd = open(url, 'rb')
        try:
            parts = [[]]
            for line in fd.readlines():
                if line in (b'%\n', b'%\r\n', b'%\r'):
                    parts.append([])
                else:
                    for encoding in ('utf8', 'iso-8859-15',
                                     utils.web.getEncoding(line)):
                        if encoding is None:
                            continue
                        try:
                            line = line.decode(encoding)
                            break
                        except:
                            continue
                    else:
                        print(repr(line))
                        continue
                    parts[-1].append(line.strip())
        finally:
            fd.close()
        return parts
    def read_fortunes(self, name):
        assert name in self.registryValue('databases')
        url = self.registryValue(registry.join(['databases', name]))

        if utils.web.urlRe.match(url):
            fd = utils.web.getUrlFd(url)
        else:
            fd = open(url, 'rb')
        try:
            parts = [[]]
            for line in fd.readlines():
                if line in (b'%\n', b'%\r\n', b'%\r'):
                    parts.append([])
                else:
                    for encoding in ('utf8', 'iso-8859-15',
                            utils.web.getEncoding(line)):
                        if encoding is None:
                            continue
                        try:
                            line = line.decode(encoding)
                            break
                        except:
                            continue
                    else:
                        print(repr(line))
                        continue
                    parts[-1].append(line.strip())
        finally:
            fd.close()
        return parts
Exemple #5
0
        def f(self, irc, msg, args, optlist, host):
            """[--c <count>] [--i <interval>] [--t <ttl>] [--W <timeout>] [--4|--6] <host or ip>

            Sends an ICMP echo request to the specified host.
            The arguments correspond with those listed in ping(8). --c is
            limited to 10 packets or less (default is 5). --i is limited to 5
            or less. --W is limited to 10 or less.
            --4 and --6 can be used if and only if the system has a unified
            ping command.
            """
            pingCmd = self.registryValue(registry.join([command, 'command']))
            if not pingCmd:
                irc.error('The ping command is not configured.  If one '
                          'is installed, reconfigure '
                          'supybot.plugins.Unix.%s.command appropriately.' %
                          command,
                          Raise=True)
            else:
                try:
                    host = host.group(0)
                except AttributeError:
                    pass

                args = [pingCmd]
                for opt, val in optlist:
                    if opt == 'c' and val > 10: val = 10
                    if opt == 'i' and val > 5: val = 5
                    if opt == 'W' and val > 10: val = 10
                    args.append('-%s' % opt)
                    if opt not in ('4', '6'):
                        args.append(str(val))
                if '-c' not in args:
                    args.append('-c')
                    args.append('5')
                args.append(host)
                try:
                    with open(os.devnull) as null:
                        inst = subprocess.Popen(args,
                                                stdout=subprocess.PIPE,
                                                stderr=subprocess.PIPE,
                                                stdin=null)
                except OSError as e:
                    irc.error('It seems the configured ping command was '
                              'not available (%s).' % e,
                              Raise=True)
                result = inst.communicate()
                if result[1]:  # stderr
                    irc.error(' '.join(result[1].decode('utf8').split()))
                else:
                    response = result[0].decode('utf8').split("\n")
                    if response[1]:
                        irc.reply(
                            ' '.join(response[1].split()[3:5]).split(':')[0] +
                            ': ' + ' '.join(response[-3:]))
                    else:
                        irc.reply(' '.join(response[0].split()[1:3]) + ': ' +
                                  ' '.join(response[-3:]))
Exemple #6
0
 def _addTrac(self, name, url):
     self.registryValue('tracs').add(name)
     group = self.registryValue('tracs', value=False)
     if url is None:
         try:
             url = self.registryValue(registry.join(['tracs', name]))
         except registry.NonExistentRegistryEntry:
             return
     self.tracs[name] = url
     group.register(name, registry.String(url, ''))
Exemple #7
0
 def _addTrac(self, name, url):
     self.registryValue('tracs').add(name)
     group = self.registryValue('tracs', value=False)
     if url is None:
         try:
             url = self.registryValue(registry.join(['tracs', name]))
         except registry.NonExistentRegistryEntry:
             return
     self.tracs[name] = url
     group.register(name, registry.String(url, ''))
Exemple #8
0
 def format_entry(self, channel, feed, entry, is_announce):
     key_name = "announceFormat" if is_announce else "format"
     if feed.name in self.registryValue("feeds"):
         specific_key_name = registry.join(["feeds", feed.name, key_name])
         template = self.registryValue(specific_key_name, channel) or self.registryValue(key_name, channel)
     else:
         template = self.registryValue(key_name, channel)
     date = entry.get("published_parsed")
     date = utils.str.timestamp(date)
     s = string.Template(template).substitute(entry, feed_name=feed.name, date=date)
     return self._normalize_entry(s)
Exemple #9
0
 def AddEvent(self, ename, etitle, eurl, echeckinterval, eannouncetime, echan, emsg):
     self.registryValue("events").add(ename)
     group = self.registryValue("events", value=False)
     group.register(ename)
     sgroup = self.registryValue(registry.join(["events", ename]), value=False)
     sgroup.register('title', registry.String(etitle, ''))
     sgroup.register('url', registry.String(eurl, ''))
     sgroup.register('checkinterval', registry.Integer(echeckinterval, ''))
     sgroup.register('announcetime', registry.Integer(eannouncetime, ''))
     sgroup.register('announcechannel', registry.String(echan, ''))
     sgroup.register('announcemsg', registry.String(emsg, ''))
     self.feedreader.events[ename] = (echan, etitle, echeckinterval, eannouncetime, eurl, emsg)
Exemple #10
0
        def f(self, irc, msg, args, optlist, host):
            """[--c <count>] [--i <interval>] [--t <ttl>] [--W <timeout>] [--4|--6] <host or ip>

            Sends an ICMP echo request to the specified host.
            The arguments correspond with those listed in ping(8). --c is
            limited to 10 packets or less (default is 5). --i is limited to 5
            or less. --W is limited to 10 or less.
            --4 and --6 can be used if and only if the system has a unified
            ping command.
            """
            pingCmd = self.registryValue(registry.join([command, 'command']))
            if not pingCmd:
               irc.error('The ping command is not configured.  If one '
                         'is installed, reconfigure '
                         'supybot.plugins.Unix.%s.command appropriately.' %
                         command, Raise=True)
            else:
                try: host = host.group(0)
                except AttributeError: pass

                args = [pingCmd]
                for opt, val in optlist:
                    if opt == 'c' and val > 10: val = 10
                    if opt == 'i' and val >  5: val = 5
                    if opt == 'W' and val > 10: val = 10
                    args.append('-%s' % opt)
                    if opt not in ('4', '6'):
                        args.append(str(val))
                if '-c' not in args:
                    args.append('-c')
                    args.append(str(self.registryValue('ping.defaultCount')))
                args.append(host)
                try:
                    with open(os.devnull) as null:
                        inst = subprocess.Popen(args,
                                                stdout=subprocess.PIPE,
                                                stderr=subprocess.PIPE,
                                                stdin=null)
                except OSError as e:
                    irc.error('It seems the configured ping command was '
                              'not available (%s).' % e, Raise=True)
                result = inst.communicate()
                if result[1]: # stderr
                    irc.error(' '.join(result[1].decode('utf8').split()))
                else:
                    response = result[0].decode('utf8').split("\n");
                    if response[1]:
                        irc.reply(' '.join(response[1].split()[3:5]).split(':')[0]
                                  + ': ' + ' '.join(response[-3:]))
                    else:
                        irc.reply(' '.join(response[0].split()[1:3])
                                  + ': ' + ' '.join(response[-3:]))
Exemple #11
0
 def format_entry(self, channel, feed, entry, is_announce):
     key_name = 'announceFormat' if is_announce else 'format'
     if feed.name in self.registryValue('feeds'):
         specific_key_name = registry.join(['feeds', feed.name, key_name])
         template = self.registryValue(specific_key_name, channel) or \
                 self.registryValue(key_name, channel)
     else:
         template = self.registryValue(key_name, channel)
     date = entry.get('published_parsed')
     date = utils.str.timestamp(date)
     return string.Template(template).safe_substitute(feed_name=feed.name,
                                                      date=date,
                                                      **entry)
Exemple #12
0
 def format_entry(self, channel, feed, entry, is_announce):
     key_name = 'announceFormat' if is_announce else 'format'
     if feed.name in self.registryValue('feeds'):
         specific_key_name = registry.join(['feeds', feed.name, key_name])
         template = self.registryValue(specific_key_name, channel) or \
                 self.registryValue(key_name, channel)
     else:
         template = self.registryValue(key_name, channel)
     date = entry.get('published_parsed')
     date = utils.str.timestamp(date)
     return string.Template(template).safe_substitute(
             feed_name=feed.name,
             date=date,
             **entry)
Exemple #13
0
        def f(self, irc, msg, args, optlist, host):
            """[--c <count>] [--i <interval>] [--t <ttl>] [--W <timeout>] <host or ip>
            Sends an ICMP echo request to the specified host.
            The arguments correspond with those listed in ping(8). --c is
            limited to 10 packets or less (default is 5). --i is limited to 5
            or less. --W is limited to 10 or less.
            """
            pingCmd = self.registryValue(registry.join([command, "command"]))
            if not pingCmd:
                irc.error(
                    "The ping command is not configured.  If one "
                    "is installed, reconfigure "
                    "supybot.plugins.Unix.%s.command appropriately." % command,
                    Raise=True,
                )
            else:
                try:
                    host = host.group(0)
                except AttributeError:
                    pass

                args = [pingCmd]
                for opt, val in optlist:
                    if opt == "c" and val > 10:
                        val = 10
                    if opt == "i" and val > 5:
                        val = 5
                    if opt == "W" and val > 10:
                        val = 10
                    args.append("-%s" % opt)
                    args.append(str(val))
                if "-c" not in args:
                    args.append("-c")
                    args.append("5")
                args.append(host)
                try:
                    with open(os.devnull) as null:
                        inst = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=null)
                except OSError as e:
                    irc.error("It seems the configured ping command was " "not available (%s)." % e, Raise=True)
                result = inst.communicate()
                if result[1]:  # stderr
                    irc.error(" ".join(result[1].decode("utf8").split()))
                else:
                    response = result[0].decode("utf8").split("\n")
                    if response[1]:
                        irc.reply(" ".join(response[1].split()[3:5]).split(":")[0] + ": " + " ".join(response[-3:]))
                    else:
                        irc.reply(" ".join(response[0].split()[1:3]) + ": " + " ".join(response[-3:]))
 def __init__(self, irc):
     self.__parent = super(HackerspaceStatus, self)
     self.__parent.__init__(irc)
     # Schema is space : [src, command]
     self.hackerspace_names = callbacks.CanonicalNameDict()
     self.locks = {}
     self.lastRequest = {}
     self.cachedStatus = {}
     self.gettingLockLock = threading.Lock()
     for space in self.registryValue('hackerspace_status'):
         try:
             src = self.registryValue(registry.join(['hackerspace_status', space]))
         except registry.NonExistentRegistryEntry:
             self.log.warning('%s is not registered.',space)
             continue
         self.makeStatusCommand(space, src)
         self.getStatus(src) # So announced feeds don't announce on startup.
Exemple #15
0
 def __init__(self, irc):
     self.__parent = super(RSS, self)
     self.__parent.__init__(irc)
     # Schema is feed : [url, command]
     self.feedNames = callbacks.CanonicalNameDict()
     self.locks = {}
     self.lastRequest = {}
     self.cachedFeeds = {}
     self.gettingLockLock = threading.Lock()
     for name in self.registryValue("feeds"):
         self._registerFeed(name)
         try:
             url = self.registryValue(registry.join(["feeds", name]))
         except registry.NonExistentRegistryEntry:
             self.log.warning("%s is not a registered feed, removing.", name)
             continue
         self.makeFeedCommand(name, url)
         self.getFeed(url)  # So announced feeds don't announce on startup.
Exemple #16
0
 def __init__(self, irc):
     self.__parent = super(LHC, self)
     self.__parent.__init__(irc)
     # Schema is feed : [url, command]
     self.feedNames = callbacks.CanonicalNameDict()
     self.locks = {}
     self.lastRequest = {}
     self.cachedFeeds = {}
     self.gettingLockLock = threading.Lock()
     for name in self.registryValue('feeds'):
         self._registerFeed(name)
         try:
             url = self.registryValue(registry.join(['feeds', name]))
         except registry.NonExistentRegistryEntry:
             self.log.warning('%s is not a registered feed, removing.',name)
             continue
         self.makeFeedCommand(name, url)
         self.getFeed('http://lblogbook.cern.ch/Shift/elog.rdf') # So announced feeds don't announce on startup.
Exemple #17
0
 def formatter(name):
     key = registry.join(['databases', name])
     url = self.plugin.registryValue(key)
     return format('%s %u', name, url)
 def formatter(name):
     key = registry.join(['databases', name])
     url = self.plugin.registryValue(key)
     return format('%s %u', name, url)