<commit_before>import sys

from zope.interface import implements
import yaml

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

from vumidash.gecko_imager import GeckoImageServer


class Options(usage.Options):
    optFlags = [
        ["config-help", None, "Print out help on the YAML configuration file"
                              " and exit"],
        ]

    optParameters = [
        ["config", "c", None, "The YAML configuration file"],
        ]

    def opt_config_help(self):
        print GeckoImageServer.__doc__
        print "See above for YAML configuration file parameters."
        sys.exit(0)


class Gecko2ImageServiceMaker(object):
    implements(IServiceMaker, IPlugin)
    tapname = "gecko2image"
    description = "Serve Geckoboard dashboards as static images"
    options = Options

    def makeService(self, options):
        config_file = options.pop("config")
        if not config_file:
            raise ValueError("please specify --config")

        with file(config_file, 'r') as stream:
            config = yaml.load(stream)

        web_path = config["web_path"]
        port = config["port"]
        selenium_remote = config["selenium_remote"]
        dashboards = config["dashboards"]
        update_interval = config["update_interval"]

        gecko_imager = GeckoImageServer(web_path, port, selenium_remote,
                                        dashboards, update_interval)
        return gecko_imager


# service maker instance for twistd

gecko2image = Gecko2ImageServiceMaker()
<commit_msg>Avoid importing selenium in gecko2image.<commit_after>import sys

from zope.interface import implements
import yaml

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

# NOTE: We avoid importing vumidash.gecko_imager at the module level so
#       that twistd can import this module even when selenium isn't available.


class Options(usage.Options):
    optFlags = [
        ["config-help", None, "Print out help on the YAML configuration file"
                              " and exit"],
    ]

    optParameters = [
        ["config", "c", None, "The YAML configuration file"],
    ]

    def opt_config_help(self):
        from vumidash.gecko_imager import GeckoImageServer
        print GeckoImageServer.__doc__
        print "See above for YAML configuration file parameters."
        sys.exit(0)


class Gecko2ImageServiceMaker(object):
    implements(IServiceMaker, IPlugin)
    tapname = "gecko2image"
    description = "Serve Geckoboard dashboards as static images"
    options = Options

    def makeService(self, options):
        from vumidash.gecko_imager import GeckoImageServer

        config_file = options.pop("config")
        if not config_file:
            raise ValueError("please specify --config")

        with file(config_file, 'r') as stream:
            config = yaml.load(stream)

        web_path = config["web_path"]
        port = config["port"]
        selenium_remote = config["selenium_remote"]
        dashboards = config["dashboards"]
        update_interval = config["update_interval"]

        gecko_imager = GeckoImageServer(web_path, port, selenium_remote,
                                        dashboards, update_interval)
        return gecko_imager


# service maker instance for twistd

gecko2image = Gecko2ImageServiceMaker()

{'fraction_non_alphanumeric': 0.07696759259259259, 'fraction_numerical': 0.00318287037037037, 'mean_word_length': 2.778142076502732, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2951579', 'n_tokens_mistral': 985, 'n_tokens_neox': 918, 'n_words': 267}