Exemple #1
0
import logging
import optparse
import os
import re
import sys
import yaml

from oyoyo import helpers
from oyoyo.client import IRCApp, IRCClient
from oyoyo.cmdhandler import DefaultCommandHandler
import twitter as twitter_mod
import backcompat


Config = backcompat.namedtuple('Config', 'host nick port channels twitters')
Twitter = backcompat.namedtuple('Account', 'channel username cons_key cons_secret '
                                 'token_key token_secret')

class ConfigException(Exception):
    pass


class BotClient(IRCClient):
    def __init__(self, conf_file):
        conf_yaml = yaml.load(open(conf_file))

        # First load the twitters section into specific Twitter instances
        if 'twitters' not in conf_yaml:
            raise ConfigException('"twitter" section not found in file: "%s"' % conf_file)
    debug_ext = lambda: ( "exts: " + repr(a) + "( " + repr(aparts[1]) + " ) and "
                        + repr(b) + "( " + repr(bparts[1]) + " )"
                         )
    if aparts[1] == bparts[1]:
        debug(lambda: debug_ext() + " matches")
        return aparts[0], bparts[0]
    debug(lambda: debug_ext() + " don't match")
    return a, b


class DispatchStatus:
    okay, missing, non_leaf = range(3)


DispatchResult = namedtuple( 'DispatchResult'
                           , 'status match wildcards detail'.split()
                            )


def dispatch_abstract(listnodes, is_leaf, traverse, find_index, noext_matched,
        startnode, nodepath):
    """Given a list of nodenames (in 'nodepath'), return a DispatchResult.

    We try to traverse the directed graph rooted at 'startnode' using the
    functions:

       listnodes(joinedpath) - lists the nodes in the specified joined path

       is_leaf(node) - returns true iff the specified node is a leaf node

       traverse(joinedpath, newnode) - returns a new joined path by traversing