<commit_before>import sys

from zope.interface import implements

from twisted.plugin import IPlugin
from twisted.python import log
from twisted.python import usage
from twisted.application.service import IServiceMaker

from autobahn.wamp import WampClientFactory, WampClientProtocol
from autobahn.websocket import connectWS

from gunny.reveille.client import ReveilleClientProtocol
from gunny.reveille.service import PlayerService


class Options(usage.Options):
    optFlags = [
        ['nodaemon','n',  "don't daemonize, don't use default umask of 0077"],
    ]
    optParameters = [
        ["host", "h", '127.0.0.1', "The host to connect to."],
        ["port", "p", 9876, "The port number to connect to."],
    ]


class CoxswainMaker(object):
    implements(IServiceMaker, IPlugin)
    tapname = "coxswaind"
    description = "Play tracks from server."
    options = Options

    def makeService(self, options):
        """
        Construct a TCPServer from a factory defined in myproject.
        """
        #log.startLogging(sys.stderr)
        url = "ws://%s:%s/ws" % (options["host"], options["port"])
        log.msg('URL: %s' % url)
        factory = WampClientFactory(url)
        factory.protocol = ReveilleClientProtocol
        import pdb; pdb.set_trace()  # NOQA
        #return connectWS(factory)
        return PlayerService(factory)


# Now construct an object which *provides* the relevant interfaces
# The name of this variable is irrelevant, as long as there is *some*
# name bound to a provider of IPlugin and IServiceMaker.

coxswaind = CoxswainMaker()<commit_msg>Continue to refactor coxswaind to run independently.<commit_after>import sys

from zope.interface import implements

from twisted.plugin import IPlugin
from twisted.python import log
from twisted.python import usage
from twisted.application.service import IServiceMaker

from gunny.reveille.client import ReveilleCommandFactory
from gunny.reveille.client import ReveilleCommandProtocol
from gunny.reveille.service import CoxswainService


class EnqueueOptions(usage.Options):
    optParameters = [
        ['file', 'f', None, None],
    ]

    def __init__(self):
        usage.Options.__init__(self)
        self['files'] = []

    def opt_file(self, fname):
        self['files'].append(fname)

    opt_f = opt_file


class ToggleOptions(usage.Options):
    optParameters = []


class Options(usage.Options):
    subCommands = [
        ['enqueue', None, EnqueueOptions, "Queue File(s)"],
        ['toggle', None, ToggleOptions, "Toggle play/pause"],
    ]
    optParameters = [
        ["host", "h", '127.0.0.1', "The host to connect to."],
        ["port", "p", 9876, "The port number to connect to.", int],
    ]


class CoxswainMaker(object):
    implements(IServiceMaker, IPlugin)
    tapname = "coxswaind"
    description = "Play tracks from server."
    options = Options

    def makeService(self, options):
        """
        Construct a TCPServer from a factory defined in myproject.
        """
        #log.startLogging(sys.stderr)
        url = "ws://%s:%s/ws" % (options["host"], options["port"])
        log.msg('URL: %s' % url)
        factory = ReveilleCommandFactory(ReveilleCommandProtocol(), url)
        return factory.startFactory()


# Now construct an object which *provides* the relevant interfaces
# The name of this variable is irrelevant, as long as there is *some*
# name bound to a provider of IPlugin and IServiceMaker.

coxswaind = CoxswainMaker()
{'fraction_non_alphanumeric': 0.10647482014388489, 'fraction_numerical': 0.006906474820143885, 'mean_word_length': 3.405576679340938, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7561941', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1003, 'n_words': 309}