import json
from bs4 import BeautifulSoup
import configfetcher
import rqueue
from wblogging import LoggingSetupParser

parser = LoggingSetupParser(
    description="Read bugs from redis, format them and send them to irc",
)
parser.add_argument('--raise', dest='raise_errors', action='store_true',
                    help="Raise exceptions instead of just logging them")
parser.add_argument('files', metavar='file', nargs='*',
                    help="XACT files to parse (listen to phabricator otherwise)")
parser.add_argument('--ask', dest='ask_before_push', action='store_true',
                    help='Ask before pushing change to redis')
args = parser.parse_args()

logging.getLogger('requests').setLevel(logging.INFO)

logger = logging.getLogger('wikibugs.wb2-phab')


class Wikibugs2(object):
    def __init__(self, conf):
        """
        :param conf: Config
        :type conf: configfetcher.ConfigFetcher
        """
        self.conf = conf
        self.phab = phabricator.Phabricator(
            self.conf.get('PHAB_HOST'),
import json
from bs4 import BeautifulSoup
import configfetcher
import rqueue
from wblogging import LoggingSetupParser

parser = LoggingSetupParser(
    description="Read bugs from redis, format them and send them to irc",
)
parser.add_argument('--raise', dest='raise_errors', action='store_true',
                    help="Raise exceptions instead of just logging them")
parser.add_argument('files', metavar='file', nargs='*',
                    help="XACT files to parse (listen to phabricator otherwise)")
parser.add_argument('--ask', dest='ask_before_push', action='store_true',
                    help='Ask before pushing change to redis')
args = parser.parse_args()

logging.getLogger('requests').setLevel(logging.INFO)

logger = logging.getLogger('wikibugs.wb2-phab')


class Wikibugs2(object):
    def __init__(self, conf):
        """
        :param conf: Config
        :type conf: configfetcher.ConfigFetcher
        """
        self.conf = conf
        self.phab = phabricator.Phabricator(
            self.conf.get('PHAB_HOST'),
    for line in ssh.stdout:
        logger.info(line.decode())
        parsed = json.loads(line.decode())
        processed = process_event(parsed)
        if processed:
            logger.info(json.dumps(processed))
            try:
                msg = build_message(processed)
                channels = channel_filter(processed['repo'],
                                          processed['branch'])
                queue.put({
                    'raw': True,
                    'msg': msg,
                    'channels': list(channels)
                })
            except:
                logger.exception('Error queuing message')
        ssh.stdout.flush()


if __name__ == '__main__':
    parser = LoggingSetupParser(description='Sends events from Gerrit to IRC')
    parser.parse_args()

    while True:
        try:
            main()
        except:
            logger.exception('Error, probably SSH connection dropped.')
        stderr=subprocess.STDOUT
    )
    logger.info('Opened SSH connection')

    for line in ssh.stdout:
        logger.info(line.decode())
        parsed = json.loads(line.decode())
        processed = process_event(parsed)
        if processed:
            logger.info(json.dumps(processed))
            try:
                msg = build_message(processed)
                channels = channel_filter(processed['repo'], processed['branch'])
                queue.put({'raw': True, 'msg': msg, 'channels': list(channels)})
            except:
                logger.exception('Error queuing message')
        ssh.stdout.flush()


if __name__ == '__main__':
    parser = LoggingSetupParser(
        description='Sends events from Gerrit to IRC'
    )
    parser.parse_args()

    while True:
        try:
            main()
        except:
            logger.exception('Error, probably SSH connection dropped.')