Example #1
0
def loadPluginModule(name, ignoreDeprecation=False):
    """Loads (and returns) the module for the plugin with the given name."""
    files = []
    pluginDirs = conf.supybot.directories.plugins()[:]
    pluginDirs.append(_pluginsDir)
    for dir in pluginDirs:
        try:
            files.extend(os.listdir(dir))
        except EnvironmentError: # OSError, IOError superclass.
            log.warning('Invalid plugin directory: %s; removing.', dir)
            conf.supybot.directories.plugins().remove(dir)
    moduleInfo = imp.find_module(name, pluginDirs)
    try:
        module = imp.load_module(name, *moduleInfo)
    except:
        sys.modules.pop(name, None)
        keys = sys.modules.keys()
        for key in keys:
            if key.startswith(name + '.'):
                sys.modules.pop(key)
        raise
    if 'deprecated' in module.__dict__ and module.deprecated:
        if ignoreDeprecation:
            log.warning('Deprecated plugin loaded: %s', name)
        else:
            raise Deprecated, format('Attempted to load deprecated plugin %s',
                                     name)
    if module.__name__ in sys.modules:
        sys.modules[module.__name__] = module
    linecache.checkcache()
    return module
Example #2
0
 def _loadPlugins(self, irc):
     self.log.info('Loading plugins (connecting to %s).', irc.network)
     alwaysLoadImportant = conf.supybot.plugins.alwaysLoadImportant()
     important = conf.supybot.commands.defaultPlugins.importantPlugins()
     for (name, value) in conf.supybot.plugins.getValues(fullNames=False):
         if irc.getCallback(name) is None:
             load = value()
             if not load and name in important:
                 if alwaysLoadImportant:
                     s = '%s is configured not to be loaded, but is being '\
                         'loaded anyway because ' \
                         'supybot.plugins.alwaysLoadImportant is True.'
                     self.log.warning(s, name)
                     load = True
             if load:
                 # We don't load plugins that don't start with a capital
                 # letter.
                 if name[0].isupper() and not irc.getCallback(name):
                     # This is debug because each log logs its beginning.
                     self.log.debug('Loading %s.', name)
                     try:
                         m = plugin.loadPluginModule(name,
                                                     ignoreDeprecation=True)
                         plugin.loadPluginClass(irc, m)
                     except callbacks.Error, e:
                         # This is just an error message.
                         log.warning(str(e))
                     except (plugins.NoSuitableDatabase, ImportError), e:
                         s = 'Failed to load %s: %s' % (name, e)
                         if not s.endswith('.'):
                             s += '.'
                         log.warning(s)
                     except Exception, e:
                         log.exception('Failed to load %s:', name)
Example #3
0
def loadPluginModule(name, ignoreDeprecation=False):
    """Loads (and returns) the module for the plugin with the given name."""
    files = []
    pluginDirs = conf.supybot.directories.plugins()[:]
    pluginDirs.append(_pluginsDir)
    for dir in pluginDirs:
        try:
            files.extend(os.listdir(dir))
        except EnvironmentError: # OSError, IOError superclass.
            log.warning('Invalid plugin directory: %s; removing.', dir)
            conf.supybot.directories.plugins().remove(dir)
    if name not in files:
        matched_names = filter(lambda x: re.search(r'(?i)^%s$' % (name,), x),
                                files)
        if len(matched_names) == 1:
            name = matched_names[0]
        else:
            raise ImportError, name
    moduleInfo = imp.find_module(name, pluginDirs)
    try:
        module = imp.load_module(name, *moduleInfo)
    except:
        sys.modules.pop(name, None)
        raise
    if 'deprecated' in module.__dict__ and module.deprecated:
        if ignoreDeprecation:
            log.warning('Deprecated plugin loaded: %s', name)
        else:
            raise Deprecated, format('Attempted to load deprecated plugin %s',
                                     name)
    if module.__name__ in sys.modules:
        sys.modules[module.__name__] = module
    linecache.checkcache()
    return module
Example #4
0
    def _translate(self, from_lang, to_lang, text):
        q = unicode(text, 'utf8')
        q = q.encode('utf8')
        #raise Exception, q
        params = {
            'langpair': u'|'.join((from_lang, to_lang)),
            'q': q,
            'v': '1.0',
        }
        url = 'http://ajax.googleapis.com/ajax/services/language/translate?' + urlencode(
            params)
        response = self._getJsonResponse(url)
        if response['responseStatus'] == 404:
            log.warning('Waiting 1/2 second and retrying...')
            time.sleep(0.5)
            response = self._getJsonResponse(url)

        if response['responseStatus'] == 200:
            translation = unicode(
                BeautifulStoneSoup(
                    response['responseData']['translatedText'],
                    convertEntities=BeautifulStoneSoup.HTML_ENTITIES)).encode(
                        'utf8')
            return translation
        else:
            raise TranslationError(response['responseStatus'],
                                   response['responseDetails'], url)
Example #5
0
    def __init__(self, *args, **kwargs):
        IBugtracker.__init__(self, *args, **kwargs)
        self.lp = None

        # A word to the wise:
        # The Launchpad API is much better than the /+text interface we currently use,
        # it's faster and easier to get the information we need.
        # The current /+text interface is not really maintained by Launchpad and most,
        # or all, of the Launchpad developers hate it. For this reason, we are dropping
        # support for /+text in the future in favour of launchpadlib.
        # Terence Simpson (tsimpson) 2010-04-20

        try: # Attempt to use launchpadlib, python bindings for the Launchpad API
            from launchpadlib.launchpad import Launchpad
            cachedir = os.path.join(conf.supybot.directories.data.tmp(), 'lpcache')
            if hasattr(Launchpad, 'login_anonymously'):
                self.lp = Launchpad.login_anonymously("Ubuntu Bots - Bugtracker", 'production', cachedir)
            else: #NOTE: Most people should have a launchpadlib new enough for .login_anonymously
                self.lp = Launchpad.login("Ubuntu Bots - Bugtracker", '', '', 'production', cahedir)
        except ImportError:
            # Ask for launchpadlib to be installed
            supylog.warning("Please install python-launchpadlib, the old interface is deprecated")
        except Exception: # Something unexpected happened
            self.lp = None
            supylog.exception("Unknown exception while accessing the Launchpad API")
Example #6
0
 def doPost(self, handler, path, form):
     if not handler.address_string().endswith('.rs.github.com') and \
             not handler.address_string().endswith('.cloud-ips.com') and \
             not handler.address_string() == 'localhost' and \
             not handler.address_string().startswith('127.0.0.') and \
             not handler.address_string().startswith('192.30.252.') and \
             not handler.address_string().startswith('204.232.175.'):
         log.warning("""'%s' tried to act as a web hook for Github,
         but is not GitHub.""" % handler.address_string())
         self.send_response(403)
         self.send_header('Content-type', 'text/plain')
         self.end_headers()
         self.wfile.write(b('Error: you are not a GitHub server.'))
     else:
         headers = dict(self.headers)
         try:
             self.send_response(200)
             self.send_header('Content-type', 'text/plain')
             self.end_headers()
             self.wfile.write(b('Thanks.'))
         except socket.error:
             pass
         if 'X-GitHub-Event' in headers:
             event = headers['X-GitHub-Event']
         else:
             # WTF?
             event = headers['x-github-event']
         if event == 'ping':
             log.info('Got ping event from GitHub.')
             self.send_response(200)
             self.send_header('Content-type', 'text/plain')
             self.end_headers()
             self.wfile.write(b('Thanks.'))
             return
         self.plugin.announce.onPayload(headers, json.loads(form['payload'].value))
Example #7
0
 def doPost(self, handler, path, form):
     if not handler.address_string().endswith('.rs.github.com') and \
             not handler.address_string().endswith('.cloud-ips.com'):
         log.warning("""'%s' tryed to act as a web hook for Github,
         but is not GitHub.""" % handler.address_string())
     else:
         self.plugin.announce.onPayload(json.loads(form['payload'].value))
Example #8
0
 def flush(self):
     """Exports the database to a file."""
     try:
         with open(filename, 'wb') as f:
             pickle.dump(self.db, f, 2)
     except Exception as e:
         log.warning('LastFM: Unable to write database: %s', e)
Example #9
0
 def onPayload(self, payload):
     repo = '%s/%s' % (payload['repository']['owner']['name'],
                       payload['repository']['name'])
     announces = self._load()
     if repo not in announces:
         log.info('Commit for repo %s not announced anywhere' % repo)
         return
     for channel in announces[repo]:
         for irc in world.ircs:
             if channel in irc.state.channels:
                 break
         commits = payload['commits']
         if channel not in irc.state.channels:
             log.info('Cannot announce commit for repo %s on %s' %
                      (repo, channel))
         elif len(commits) == 0:
             log.warning('GitHub callback called without any commit.')
         else:
             hidden = None
             last_commit = commits[-1]
             if last_commit['message'].startswith('Merge ') and \
                     len(commits) > 5:
                 hidden = len(commits) + 1
                 payload['commits'] = [last_commit]
             for commit in payload['commits']:
                 msg = self._createPrivmsg(channel, payload, commit,
                                           hidden)
                 irc.queueMsg(msg)
Example #10
0
 def doPost(self, handler, path, form):
     if not handler.address_string().endswith('.rs.github.com') and \
             not handler.address_string().endswith('.cloud-ips.com') and \
             not handler.address_string() == 'localhost' and \
             not handler.address_string().startswith('127.0.0.') and \
             not handler.address_string().startswith('192.30.252.') and \
             not handler.address_string().startswith('204.232.175.'):
         log.warning("""'%s' tried to act as a web hook for Github,
         but is not GitHub.""" % handler.address_string())
         self.send_response(403)
         self.send_header('Content-type', 'text/plain')
         self.end_headers()
         self.wfile.write(b('Error: you are not a GitHub server.'))
     else:
         headers = dict(self.headers)
         try:
             self.send_response(200)
             self.send_header('Content-type', 'text/plain')
             self.end_headers()
             self.wfile.write(b('Thanks.'))
         except socket.error:
             pass
         if 'X-GitHub-Event' in headers:
             event = headers['X-GitHub-Event']
         else:
             # WTF?
             event = headers['x-github-event']
         if event == 'ping':
             log.info('Got ping event from GitHub.')
             self.send_response(200)
             self.send_header('Content-type', 'text/plain')
             self.end_headers()
             self.wfile.write(b('Thanks.'))
             return
         self.plugin.announce.onPayload(headers, json.loads(form['payload'].value))
Example #11
0
 def _loadPlugins(self, irc):
     self.log.info('Loading plugins (connecting to %s).', irc.network)
     alwaysLoadImportant = conf.supybot.plugins.alwaysLoadImportant()
     important = conf.supybot.commands.defaultPlugins.importantPlugins()
     for (name, value) in conf.supybot.plugins.getValues(fullNames=False):
         if irc.getCallback(name) is None:
             load = value()
             if not load and name in important:
                 if alwaysLoadImportant:
                     s = '%s is configured not to be loaded, but is being '\
                         'loaded anyway because ' \
                         'supybot.plugins.alwaysLoadImportant is True.'
                     self.log.warning(s, name)
                     load = True
             if load:
                 # We don't load plugins that don't start with a capital
                 # letter.
                 if name[0].isupper() and not irc.getCallback(name):
                     # This is debug because each log logs its beginning.
                     self.log.debug('Loading %s.', name)
                     try:
                         m = plugin.loadPluginModule(name,
                                                     ignoreDeprecation=True)
                         plugin.loadPluginClass(irc, m)
                     except callbacks.Error, e:
                         # This is just an error message.
                         log.warning(str(e))
                     except (plugins.NoSuitableDatabase, ImportError), e:
                         s = 'Failed to load %s: %s' % (name, e)
                         if not s.endswith('.'):
                             s += '.'
                         log.warning(s)
                     except Exception, e:
                         log.exception('Failed to load %s:', name)
Example #12
0
 def hook(self, subdir, callback):
     if subdir in self.callbacks:
         log.warning(('The HTTP subdirectory `%s` was already hooked but '
                 'has been claimed by another plugin (or maybe you '
                 'reloaded the plugin and it didn\'t properly unhook. '
                 'Forced unhook.') % subdir)
     self.callbacks[subdir] = callback
Example #13
0
 def flush(self):
     """Exports the database to a file."""
     try:
         with open(filename, 'wb') as f:
             pickle.dump(self.db, f, 2)
     except Exception as e:
         log.warning('LastFM: Unable to write database: %s', e)
Example #14
0
def checkCapability(hostmask,
                    capability,
                    users=users,
                    channels=channels,
                    ignoreOwner=False):
    """Checks that the user specified by name/hostmask has the capability given.
    """
    if world.testing and (not isinstance(hostmask, str) or '@' not in hostmask
                          or '__no_testcap__' not in hostmask.split('@')[1]):
        return _x(capability, True)
    try:
        u = users.getUser(hostmask)
        if u.secure and not u.checkHostmask(hostmask, useAuth=False):
            raise KeyError
    except KeyError:
        # Raised when no hostmasks match.
        return _checkCapabilityForUnknownUser(capability,
                                              users=users,
                                              channels=channels)
    except ValueError, e:
        # Raised when multiple hostmasks match.
        log.warning('%s: %s', hostmask, e)
        return _checkCapabilityForUnknownUser(capability,
                                              users=users,
                                              channels=channels)
Example #15
0
    def grabSeasonData(self):
        """Refreshes season/car/track data from the iRacing main page Javascript"""
        rawMainPageHTML = self.iRacingConnection.fetchMainPageRawHTML()

        if rawMainPageHTML is None:
            logger.warning('Unable to fetch iRacing homepage data.')
            return

        self.lastSeasonDataFetchTime = time.time()

        try:
            trackJSON = re.search("var TrackListing\\s*=\\s*extractJSON\\('(.*)'\\);", rawMainPageHTML).group(1)
            carJSON = re.search("var CarListing\\s*=\\s*extractJSON\\('(.*)'\\);", rawMainPageHTML).group(1)
            carClassJSON = re.search("var CarClassListing\\s*=\\s*extractJSON\\('(.*)'\\);", rawMainPageHTML).group(1)
            seasonJSON = re.search("var SeasonListing\\s*=\\s*extractJSON\\('(.*)'\\);", rawMainPageHTML).group(1)

            tracks = json.loads(trackJSON)
            cars = json.loads(carJSON)
            carClasses = json.loads(carClassJSON)
            seasons = json.loads(seasonJSON)

            for track in tracks:
                self.tracksByID[track['id']] = track
            for car in cars:
                self.carsByID[car['id']] = car
            for carClass in carClasses:
                self.carClassesByID[carClass['id']] = carClass
            for season in seasons:
                self.seasonsByID[season['seriesid']] = season

            logger.info('Loaded data for %i tracks, %i cars, %i car classes, and %i seasons.', len(self.tracksByID), len(self.carsByID), len(self.carClassesByID), len(self.seasonsByID))

        except AttributeError:
            logger.info('Unable to match track/car/season (one or more) listing regex in iRacing main page data.  It is possible that iRacing changed the JavaScript structure of their main page!  Oh no!')
Example #16
0
 def hook(self, subdir, callback):
     if subdir in self.callbacks:
         log.warning(('The HTTP subdirectory `%s` was already hooked but '
                 'has been claimed by another plugin (or maybe you '
                 'reloaded the plugin and it didn\'t properly unhook. '
                 'Forced unhook.') % subdir)
     self.callbacks[subdir] = callback
Example #17
0
 def onPayload(self, payload):
     repo = '%s/%s' % (payload['repository']['owner']['name'],
                       payload['repository']['name'])
     announces = self._load()
     if repo not in announces:
         log.info('Commit for repo %s not announced anywhere' % repo)
         return
     for channel in announces[repo]:
         for irc in world.ircs:
             if channel in irc.state.channels:
                 break
         commits = payload['commits']
         if channel not in irc.state.channels:
             log.info('Cannot announce commit for repo %s on %s' %
                      (repo, channel))
         elif len(commits) == 0:
             log.warning('GitHub callback called without any commit.')
         else:
             hidden = None
             last_commit = commits[-1]
             if last_commit['message'].startswith('Merge ') and \
                     len(commits) > 5:
                 hidden = len(commits) + 1
                 payload['commits'] = [last_commit]
             for commit in payload['commits']:
                 msg = self._createPrivmsg(channel, payload, commit,
                         hidden)
                 irc.queueMsg(msg)
Example #18
0
 def doPost(self, handler, path, form):
     if not handler.address_string().endswith('.rs.github.com') and \
             not handler.address_string().endswith('.cloud-ips.com'):
         log.warning("""'%s' tryed to act as a web hook for Github,
         but is not GitHub.""" % handler.address_string())
     else:
         self.plugin.announce.onPayload(json.loads(form['payload'].value))
Example #19
0
def loadPluginModule(name, ignoreDeprecation=False):
    """Loads (and returns) the module for the plugin with the given name."""
    files = []
    pluginDirs = conf.supybot.directories.plugins()[:]
    pluginDirs.append(_pluginsDir)
    for dir in pluginDirs:
        try:
            files.extend(os.listdir(dir))
        except EnvironmentError: # OSError, IOError superclass.
            log.warning('Invalid plugin directory: %s; removing.', dir)
            conf.supybot.directories.plugins().remove(dir)
    moduleInfo = imp.find_module(name, pluginDirs)
    try:
        module = imp.load_module(name, *moduleInfo)
    except:
        sys.modules.pop(name, None)
        raise
    if 'deprecated' in module.__dict__ and module.deprecated:
        if ignoreDeprecation:
            log.warning('Deprecated plugin loaded: %s', name)
        else:
            raise Deprecated, format('Attempted to load deprecated plugin %s',
                                     name)
    if module.__name__ in sys.modules:
        sys.modules[module.__name__] = module
    linecache.checkcache()
    return module
Example #20
0
 def doPost(self, handler, path, form):
     if (
         not handler.address_string().endswith(".rs.github.com")
         and not handler.address_string().endswith(".cloud-ips.com")
         and not handler.address_string() == "localhost"
         and not handler.address_string().startswith("127.0.0.")
         and not handler.address_string().startswith("192.30.252.")
         and not handler.address_string().startswith("204.232.175.")
     ):
         log.warning(
             """'%s' tried to act as a web hook for Github,
         but is not GitHub."""
             % handler.address_string()
         )
         self.send_response(403)
         self.send_header("Content-type", "text/plain")
         self.end_headers()
         self.wfile.write(b("Error: you are not a GitHub server."))
     else:
         headers = dict(self.headers)
         try:
             self.send_response(200)
             self.send_header("Content-type", "text/plain")
             self.end_headers()
             self.wfile.write(b("Thanks."))
         except socket.error:
             pass
         self.plugin.announce.onPayload(headers, json.loads(form["payload"].value))
Example #21
0
class ChannelUserDB(ChannelUserDictionary):
    def __init__(self, filename):
        ChannelUserDictionary.__init__(self)
        self.filename = filename
        try:
            fd = file(self.filename)
        except EnvironmentError, e:
            log.warning('Couldn\'t open %s: %s.', self.filename, e)
            return
        reader = csv.reader(fd)
        try:
            lineno = 0
            for t in reader:
                lineno += 1
                try:
                    channel = t.pop(0)
                    id = t.pop(0)
                    try:
                        id = int(id)
                    except ValueError:
                        # We'll skip over this so, say, nicks can be kept here.
                        pass
                    v = self.deserialize(channel, id, t)
                    self[channel, id] = v
                except Exception, e:
                    log.warning('Invalid line #%s in %s.', lineno,
                                self.__class__.__name__)
                    log.debug('Exception: %s', utils.exnToString(e))
        except Exception, e:  # This catches exceptions from csv.reader.
            log.warning('Invalid line #%s in %s.', lineno,
                        self.__class__.__name__)
            log.debug('Exception: %s', utils.exnToString(e))
Example #22
0
 def onPayload(self, headers, payload):
     if "full_name" in payload["repository"]:
         repo = payload["repository"]["full_name"]
     elif "name" in payload["repository"]["owner"]:
         repo = "%s/%s" % (payload["repository"]["owner"]["name"], payload["repository"]["name"])
     else:
         repo = "%s/%s" % (payload["repository"]["owner"]["login"], payload["repository"]["name"])
     event = headers["X-GitHub-Event"]
     announces = self._load()
     if repo not in announces:
         log.info("Commit for repo %s not announced anywhere" % repo)
         return
     for channel in announces[repo]:
         for irc in world.ircs:
             if channel in irc.state.channels:
                 break
         if event == "push":
             commits = payload["commits"]
             if channel not in irc.state.channels:
                 log.info("Cannot announce commit for repo %s on %s" % (repo, channel))
             elif len(commits) == 0:
                 log.warning("GitHub push hook called without any commit.")
             else:
                 hidden = None
                 last_commit = commits[-1]
                 if last_commit["message"].startswith("Merge ") and len(commits) > 5:
                     hidden = len(commits) + 1
                     commits = [last_commit]
                 payload2 = dict(payload)
                 for commit in commits:
                     payload2["__commit"] = commit
                     self._createPrivmsg(irc, channel, payload2, "push", hidden)
         else:
             self._createPrivmsg(irc, channel, payload, event)
Example #23
0
 def reload(self):
     """Reloads the channel database from its file."""
     if self.filename is not None:
         self.channels.clear()
         try:
             self.open(self.filename)
         except EnvironmentError, e:
             log.warning('ChannelsDictionary.reload failed: %s', e)
Example #24
0
 def flush(self):
     """Exports the database to a file."""
     try:
         with open(self.filename, "wb") as f:
             pickle.dump(self.db, f, 2)
     except Exception as e:
         log.warning("%s: Unable to write database: %s", self._plugin_name,
                     e)
Example #25
0
    def addChannel(self, channel, regex=None, default=False):
        """Adds a dedicated trigger regex for this provider for a channel.

        If default is set, this provider will match on #nnnn in this channel.
        At most one provider should be the default provider in any channel."""
        if channel in self.channels:
            log.warning("[%s] re-adding %s" % (self.name, channel))
        self.channels[channel] = {'re': regex, 'default': default}
Example #26
0
 def __init__(self, filename):
     ChannelUserDictionary.__init__(self)
     self.filename = filename
     try:
         fd = file(self.filename)
     except EnvironmentError, e:
         log.warning('Couldn\'t open %s: %s.', self.filename, e)
         return
Example #27
0
 def reload(self):
     """Reloads the channel database from its file."""
     if self.filename is not None:
         self.channels.clear()
         try:
             self.open(self.filename)
         except EnvironmentError, e:
             log.warning('ChannelsDictionary.reload failed: %s', e)
Example #28
0
 def __init__(self, filename):
     ChannelUserDictionary.__init__(self)
     self.filename = filename
     try:
         fd = file(self.filename)
     except EnvironmentError, e:
         log.warning('Couldn\'t open %s: %s.', self.filename, e)
         return
Example #29
0
 def onPayload(self, headers, payload):
     if 'reply_env' not in ircmsgs.IrcMsg.__slots__:
         log.error("Got event payload from GitHub, but your version "
                   "of Supybot is not compatible with reply "
                   "environments, so, the GitHub plugin can't "
                   "announce it.")
     if 'full_name' in payload['repository']:
         repo = payload['repository']['full_name']
     elif 'name' in payload['repository']['owner']:
         repo = '%s/%s' % (payload['repository']['owner']['name'],
                           payload['repository']['name'])
     else:
         repo = '%s/%s' % (payload['repository']['owner']['login'],
                           payload['repository']['name'])
     event = headers['X-GitHub-Event']
     announces = self._load()
     repoAnnounces = []
     for (dbRepo, network, channel) in announces:
         if dbRepo == repo:
             repoAnnounces.append((network, channel))
     if len(repoAnnounces) == 0:
         log.info('Commit for repo %s not announced anywhere' % repo)
         return
     for (network, channel) in repoAnnounces:
         # Compatability with DBs without a network
         if network == '':
             for irc in world.ircs:
                 if channel in irc.state.channels:
                     break
         else:
             irc = world.getIrc(network)
             if not irc:
                 log.warning('Received GitHub payload with announcing '
                             'enabled in %s on unloaded network %s.',
                             channel, network)
                 return
         if channel not in irc.state.channels:
             log.info(('Cannot announce event for repo '
                      '%s in %s on %s because I\'m not in %s.') %
                      (repo, channel, irc.network, channel))
         if event == 'push':
             commits = payload['commits']
             if len(commits) == 0:
                 log.warning('GitHub push hook called without any commit.')
             else:
                 hidden = None
                 last_commit = commits[-1]
                 if last_commit['message'].startswith('Merge ') and \
                         len(commits) > 5:
                     hidden = len(commits) + 1
                     commits = [last_commit]
                 payload2 = dict(payload)
                 for commit in commits:
                     payload2['__commit'] = commit
                     self._createPrivmsg(irc, channel, payload2,
                             'push', hidden)
         else:
             self._createPrivmsg(irc, channel, payload, event)
Example #30
0
    def fetchDriverStatusJSON(self, friends=True, studied=True, onlineOnly=False):
        url = '%s?friends=%d&studied=%d&onlineOnly=%d' % (self.URL_GET_DRIVER_STATUS, friends, studied, onlineOnly)
        response = self.requestURL(url)

        if response is None:
            logger.warning('Unable to fetch driver status from iRacing site.')
            return None

        return json.loads(response.text)
Example #31
0
 def do376(self, irc, msg):
     """Watch for the MOTD and login if we can"""
     if irc.state.supported.get('NETWORK', '') == 'UnderNet':
         if self.registryValue('auth.username') and self.registryValue('auth.password'):
             log.info("Attempting login to XService")
         else:
             log.warning("username and password not set, this plugin will not work")
             return
         self._login(irc)
Example #32
0
 def reload(self):
     if self.filename is not None:
         oldhostmasks = self.hostmasks.copy()
         self.hostmasks.clear()
         try:
             self.open(self.filename)
         except EnvironmentError, e:
             log.warning('IgnoresDB.reload failed: %s', e)
             # Let's be somewhat transactional.
             self.hostmasks.update(oldhostmasks)
Example #33
0
    def reloadpolls(self, irc, msg, args):
        """<takes no arguments>
        Reloads the Polls file.
        """
        try:
            self.polls = yaml.load(open(self.pollFile, 'r'), Loader=yamlordereddictloader.Loader)

        except FileNotFoundError as e:
            log.warning("Couldn't open file: %s" % e)
            raise
Example #34
0
 def reload(self):
     if self.filename is not None:
         oldhostmasks = self.hostmasks.copy()
         self.hostmasks.clear()
         try:
             self.open(self.filename)
         except EnvironmentError, e:
             log.warning('IgnoresDB.reload failed: %s', e)
             # Let's be somewhat transactional.
             self.hostmasks.update(oldhostmasks)
Example #35
0
 def do376(self, irc, msg):
     """Watch for the MOTD and login if we can"""
     if irc.state.supported.get("NETWORK", "") == "UnderNet":
         if self.registryValue("auth.username") and self.registryValue(
                 "auth.password"):
             log.info("Attempting login to XService")
         else:
             log.warning(
                 "username and password not set, this plugin will not work")
             return
         self._login(irc)
Example #36
0
    def __init__(self, irc):
        self.__parent = super(Vote, self)
        self.__parent.__init__(irc)
        self.pollFile = conf.supybot.directories.data.dirize('polls.yml')
        self._requests = {}
        try:
            self.polls = yaml.load(open(self.pollFile, 'r'), Loader=yamlordereddictloader.Loader)

        except FileNotFoundError as e:
            log.warning("Couldn't open file: %s" % e)
            raise
Example #37
0
 def flush(self):
     if self.filename is not None:
         fd = utils.file.AtomicFile(self.filename)
         now = time.time()
         for (hostmask, expiration) in self.hostmasks.items():
             if now < expiration or not expiration:
                 fd.write('%s %s' % (hostmask, expiration))
                 fd.write(os.linesep)
         fd.close()
     else:
         log.warning('IgnoresDB.flush called without self.filename.')
Example #38
0
 def reload(self):
     """Reloads the database from its file."""
     self.nextId = 0
     self.users.clear()
     self._nameCache.clear()
     self._hostmaskCache.clear()
     if self.filename is not None:
         try:
             self.open(self.filename)
         except EnvironmentError, e:
             log.warning('UsersDictionary.reload failed: %s', e)
Example #39
0
 def reload(self):
     """Reloads the database from its file."""
     self.nextId = 0
     self.users.clear()
     self._nameCache.clear()
     self._hostmaskCache.clear()
     if self.filename is not None:
         try:
             self.open(self.filename)
         except EnvironmentError, e:
             log.warning('UsersDictionary.reload failed: %s', e)
Example #40
0
 def flush(self):
     if self.filename is not None:
         fd = utils.file.AtomicFile(self.filename)
         now = time.time()
         for (hostmask, expiration) in self.hostmasks.items():
             if now < expiration or not expiration:
                 fd.write('%s %s' % (hostmask, expiration))
                 fd.write(os.linesep)
         fd.close()
     else:
         log.warning('IgnoresDB.flush called without self.filename.')
Example #41
0
 def _getJsonResponse(self,url,retries = 2):
     try:
         log.debug('Retrieving: %s' % (url))
         doc = web.getUrl(url, headers=HEADERS)
         log.debug('Response: %s' % (doc))
         response = simplejson.loads(doc)
         return response
     except web.Error, e:
         log.warning('Error: %s',str(e))
         if retries > 0:
             log.warning('Retries left: %d' % (retries))
             return self._getJsonResponse(url,retries=retries-1)
Example #42
0
 def _getJsonResponse(self, url, retries=2):
     try:
         log.debug('Retrieving: %s' % (url))
         doc = web.getUrl(url, headers=HEADERS)
         log.debug('Response: %s' % (doc))
         response = simplejson.loads(doc)
         return response
     except web.Error, e:
         log.warning('Error: %s', str(e))
         if retries > 0:
             log.warning('Retries left: %d' % (retries))
             return self._getJsonResponse(url, retries=retries - 1)
Example #43
0
 def __init__(self, irc):
     self.__parent = super(Bugtracker, self)
     self.__parent.__init__(irc)
     self.db = ircutils.IrcDict()
     for name in self.registryValue('bugtrackers'):
         registerBugtracker(name)
         group = self.registryValue('bugtrackers.%s' % name.replace('.','\\.'), value=False)
         if group.trackertype() in defined_bugtrackers:
             self.db[name] = defined_bugtrackers[group.trackertype()](name, group.url(), group.description(), group.trackertype())
         else:
             supylog.warning("Bugtracker: Unknown trackertype: %s (%s)" % (group.trackertype(), name))
     self.shorthand = utils.abbrev(list(self.db.keys()))
     self.shown = {}
Example #44
0
 def login(self, irc, msg, args):
     """takes no arguments
     Logins to Undernet's X Service"""
     if irc.state.supported.get('NETWORK', '') == 'UnderNet':
         if self.registryValue('auth.username') and self.registryValue('auth.password'):
             log.info("Attempting login to XService")
         else:
             log.warning("username and password not set, this plugin will not work")
             return
         self._login(irc)
     else:
         log.error("We're not on UnderNet, we can't use this.")
         irc.error("We're not on UnderNet, this is useless.")
Example #45
0
    def fetchDriverStatusJSON(self,
                              friends=True,
                              studied=True,
                              onlineOnly=False):
        url = '%s?friends=%d&studied=%d&onlineOnly=%d' % (
            self.URL_GET_DRIVER_STATUS, friends, studied, onlineOnly)
        response = self.requestURL(url)

        if response is None:
            logger.warning('Unable to fetch driver status from iRacing site.')
            return None

        return json.loads(response.text)
Example #46
0
 def flush(self):
     """Flushes the channel database to its file."""
     if not self.noFlush:
         if self.filename is not None:
             fd = utils.file.AtomicFile(self.filename)
             for (channel, c) in self.channels.iteritems():
                 fd.write('channel %s' % channel)
                 fd.write(os.linesep)
                 c.preserve(fd, indent='  ')
             fd.close()
         else:
             log.warning('ChannelsDictionary.flush without self.filename.')
     else:
         log.debug('Not flushing ChannelsDictionary because of noFlush.')
Example #47
0
    def sudo(self, irc, msg, args, command):
        """<commande> [<arg1> [<arg2> ...]]

        Runs the command following the Sudo rules."""
        name, rule = self.db.getRuleMatching(command)
        if name is None:
            log.warning('Sudo not granted to "%s"' % msg.prefix)
            irc.error(_('Sudo not granted.'))
        else:
            assert rule is not None
            log.info('Sudo granted to "%s" with rule %s' % (msg.prefix, name))
            msg.prefix = rule.hostmask
            tokens = callbacks.tokenize(command)
            self.Proxy(irc.irc, msg, tokens)
Example #48
0
    def sudo(self, irc, msg, args, command):
        """<commande> [<arg1> [<arg2> ...]]

        Runs the command fellowing the Sudo rules."""
        name, rule = self.db.getRuleMatching(command)
        if name is None:
            log.warning('Sudo not granted to "%s"' % msg.prefix)
            irc.error(_('Sudo not granted.'))
        else:
            assert rule is not None
            log.info('Sudo granted to "%s" with rule %s' % (msg.prefix, name))
            msg.prefix = rule.hostmask
            tokens = callbacks.tokenize(command)
            self.Proxy(irc.irc, msg, tokens)
Example #49
0
 def flush(self):
     """Flushes the channel database to its file."""
     if not self.noFlush:
         if self.filename is not None:
             fd = utils.file.AtomicFile(self.filename)
             for (channel, c) in self.channels.iteritems():
                 fd.write('channel %s' % channel)
                 fd.write(os.linesep)
                 c.preserve(fd, indent='  ')
             fd.close()
         else:
             log.warning('ChannelsDictionary.flush without self.filename.')
     else:
         log.debug('Not flushing ChannelsDictionary because of noFlush.')
Example #50
0
 def login(self, irc, msg, args):
     """takes no arguments
     Logins to Undernet's X Service"""
     if irc.state.supported.get("NETWORK", "") == "UnderNet":
         if self.registryValue("auth.username") and self.registryValue(
                 "auth.password"):
             log.info("Attempting login to XService")
         else:
             log.warning(
                 "username and password not set, this plugin will not work")
             return
         self._login(irc)
     else:
         log.error("We're not on UnderNet, we can't use this.")
         irc.error("We're not on UnderNet, this is useless.")
Example #51
0
    def sudo(self, irc, msg, args, command):
        """<command> [<arg1> [<arg2> ...]]

        Runs the command following the Sudo rules."""
        name, rule = self.db.getRuleMatching(command)
        bannedChars = conf.supybot.commands.nested.brackets()
        if name is None:
            log.warning('Sudo not granted to "%s"' % msg.prefix)
            irc.error(_('Sudo not granted.'))
        else:
            assert rule is not None
            log.info('Sudo granted to "%s" with rule %s' % (msg.prefix, name))
            msg.prefix = rule.hostmask
            tokens = callbacks.tokenize(command)
            msg.nick = msg.prefix.split('!')[0]
            self.Proxy(irc.irc, msg, tokens)
Example #52
0
    def sudo(self, irc, msg, args, command):
        """<command> [<arg1> [<arg2> ...]]

        Runs the command following the Sudo rules."""
        name, rule = self.db.getRuleMatching(command)
        bannedChars = conf.supybot.commands.nested.brackets()
        if name is None:
            log.warning('Sudo not granted to "%s"' % msg.prefix)
            irc.error(_('Sudo not granted.'))
        else:
            assert rule is not None
            log.info('Sudo granted to "%s" with rule %s' % (msg.prefix, name))
            msg.prefix = rule.hostmask
            tokens = callbacks.tokenize(command)
            msg.nick = msg.prefix.split('!')[0]
            self.Proxy(irc.irc, msg, tokens)
Example #53
0
    def schedule_event(self, f, config_value, name):
        # Like schedule.addPeriodicEvent, but capture the name of our config
        # variable in the closure rather than the value
        if name in schedule.schedule.events:
            log.warning('Event %s already scheduled; removing' % name)
            schedule.removeEvent(name)

        def wrapper():
            try:
                f()
            finally:
                return schedule.addEvent(
                    wrapper,
                    time.time() + self.registryValue(config_value), name)

        return wrapper()
Example #54
0
def checkCapability(hostmask, capability, users=users, channels=channels):
    """Checks that the user specified by name/hostmask has the capability given.
    """
    if world.testing:
        return _x(capability, True)
    try:
        u = users.getUser(hostmask)
        if u.secure and not u.checkHostmask(hostmask, useAuth=False):
            raise KeyError
    except KeyError:
        # Raised when no hostmasks match.
        return _checkCapabilityForUnknownUser(capability, users=users, channels=channels)
    except ValueError, e:
        # Raised when multiple hostmasks match.
        log.warning("%s: %s", hostmask, e)
        return _checkCapabilityForUnknownUser(capability, users=users, channels=channels)
Example #55
0
 def doPost(self, handler, path, form):
     if not handler.address_string().endswith('.rs.github.com') and \
             not handler.address_string().endswith('.cloud-ips.com') and \
             not handler.address_string() == 'localhost':
         log.warning("""'%s' tried to act as a web hook for Github,
         but is not GitHub.""" % handler.address_string())
         self.send_response(403)
         self.send_header('Content-type', 'text/plain')
         self.end_headers()
         self.wfile.write('Error: you are not a GitHub server.')
     else:
         self.send_response(200)
         self.send_header('Content-type', 'text/plain')
         self.end_headers()
         self.wfile.write('Thanks.')
         self.plugin.announce.onPayload(json.loads(form['payload'].value))
Example #56
0
    def grabSeasonData(self):
        """Refreshes season/car/track data from the iRacing main page Javascript"""
        rawMainPageHTML = self.iRacingConnection.fetchMainPageRawHTML()

        if rawMainPageHTML is None:
            logger.warning('Unable to fetch iRacing homepage data.')
            return

        self.lastSeasonDataFetchTime = time.time()

        try:
            trackJSON = re.search(
                "var TrackListing\\s*=\\s*extractJSON\\('(.*)'\\);",
                rawMainPageHTML).group(1)
            carJSON = re.search(
                "var CarListing\\s*=\\s*extractJSON\\('(.*)'\\);",
                rawMainPageHTML).group(1)
            carClassJSON = re.search(
                "var CarClassListing\\s*=\\s*extractJSON\\('(.*)'\\);",
                rawMainPageHTML).group(1)
            seasonJSON = re.search(
                "var SeasonListing\\s*=\\s*extractJSON\\('(.*)'\\);",
                rawMainPageHTML).group(1)

            tracks = json.loads(trackJSON)
            cars = json.loads(carJSON)
            carClasses = json.loads(carClassJSON)
            seasons = json.loads(seasonJSON)

            for track in tracks:
                self.tracksByID[track['id']] = track
            for car in cars:
                self.carsByID[car['id']] = car
            for carClass in carClasses:
                self.carClassesByID[carClass['id']] = carClass
            for season in seasons:
                self.seasonsByID[season['seriesid']] = season

            logger.info(
                'Loaded data for %i tracks, %i cars, %i car classes, and %i seasons.',
                len(self.tracksByID), len(self.carsByID),
                len(self.carClassesByID), len(self.seasonsByID))

        except AttributeError:
            logger.info(
                'Unable to match track/car/season (one or more) listing regex in iRacing main page data.  It is possible that iRacing changed the JavaScript structure of their main page!  Oh no!'
            )
Example #57
0
 def doPost(self, handler, path, form):
     if not handler.address_string().endswith('.rs.github.com') and \
             not handler.address_string().endswith('.cloud-ips.com') and \
             not handler.address_string() == 'localhost' and \
             not handler.address_string().startswith('192.30.252.') and \
             not handler.address_string().startswith('204.232.175.'):
         log.warning("""'%s' tried to act as a web hook for Github,
         but is not GitHub.""" % handler.address_string())
         self.send_response(403)
         self.send_header('Content-type', 'text/plain')
         self.end_headers()
         self.wfile.write(b('Error: you are not a GitHub server.'))
     else:
         self.send_response(200)
         self.send_header('Content-type', 'text/plain')
         self.end_headers()
         self.wfile.write(b('Thanks.'))
         self.plugin.announce.onPayload(json.loads(form['payload'].value))
Example #58
0
    def login(self):

        loginData = {
            'username': self.username,
            'password': self.password,
            'AUTOLOGIN': "******",
            'utcoffset': 800,
            'todaysdate': ''
        }

        try:
            response = self.session.post(
                "https://members.iracing.com/membersite/Login", data=loginData)

        except Exception as e:
            logger.warning("Caught exception logging in: " + str(e))
            return None

        return response
Example #59
0
def getChannelDb(irc, msg, args, state, **kwargs):
    channelSpecific = conf.supybot.databases.plugins.channelSpecific
    try:
        getChannel(irc, msg, args, state, **kwargs)
        channel = channelSpecific.getChannelLink(state.channel)
        state.channel = channel
        state.args[-1] = channel
    except (callbacks.ArgumentError, IndexError):
        if channelSpecific():
            raise
        channel = channelSpecific.link()
        if not conf.get(channelSpecific.link.allow, channel):
            log.warning(
                'channelSpecific.link is globally set to %s, but '
                '%s disallowed linking to its db.', channel, channel)
            raise
        else:
            channel = channelSpecific.getChannelLink(channel)
            state.channel = channel
            state.args.append(channel)
Example #60
0
def checkCapability(hostmask, capability, users=users, channels=channels):
    """Checks that the user specified by name/hostmask has the capability given.
    """
    if world.testing:
        return _x(capability, True)
    try:
        u = users.getUser(hostmask)
        if u.secure and not u.checkHostmask(hostmask, useAuth=False):
            raise KeyError
    except KeyError:
        # Raised when no hostmasks match.
        return _checkCapabilityForUnknownUser(capability,
                                              users=users,
                                              channels=channels)
    except ValueError, e:
        # Raised when multiple hostmasks match.
        log.warning('%s: %s', hostmask, e)
        return _checkCapabilityForUnknownUser(capability,
                                              users=users,
                                              channels=channels)