<commit_before>from circus.plugins import CircusPlugin
from zmq.eventloop import ioloop
from honcho.procfile import Procfile

import os.path


class ProcfileWatcher(CircusPlugin):
    name = "procfile_watcher"

    def __init__(self, *args, **config):
        super(ProcfileWatcher, self).__init__(*args, **config)
        self.loop_rate = config.get("loop_rate", 1)  # in seconds
        self.procfile_path = config.get("app_path", "/home/application/current/Procfile")
        self.period = ioloop.PeriodicCallback(self.look_after, self.loop_rate * 1000, self.loop)

    def handle_init(self):
        self.period.start()

    def handle_stop(self):
        self.period.stop()

    def handle_recv(self, data):
        pass

    def look_after(self):
        if os.path.exists(self.procfile_path):
            with open(self.procfile_path) as file:
                procfile = Procfile(file.read())
                commands = self.call("status")["statuses"].keys()
                for name, cmd in procfile.commands.items():
                    if name not in commands:
                        self.call("add", name=name, cmd=cmd, start=True)<commit_msg>procfile watcher: added method to add command.<commit_after>from circus.plugins import CircusPlugin
from zmq.eventloop import ioloop
from honcho.procfile import Procfile

import os.path


class ProcfileWatcher(CircusPlugin):
    name = "procfile_watcher"

    def __init__(self, *args, **config):
        super(ProcfileWatcher, self).__init__(*args, **config)
        self.loop_rate = config.get("loop_rate", 1)  # in seconds
        self.procfile_path = config.get("app_path", "/home/application/current/Procfile")
        self.period = ioloop.PeriodicCallback(self.look_after, self.loop_rate * 1000, self.loop)

    def handle_init(self):
        self.period.start()

    def handle_stop(self):
        self.period.stop()

    def handle_recv(self, data):
        pass

    def add_command(self, name, cmd):
        options = {
            "name": name,
            "cmd": cmd,
        }
        self.call("add", **options)

    def look_after(self):
        if os.path.exists(self.procfile_path):
            with open(self.procfile_path) as file:
                procfile = Procfile(file.read())
                commands = self.call("status")["statuses"].keys()
                for name, cmd in procfile.commands.items():
                    if name not in commands:
                        self.add_command(name=name, cmd=cmd)
{'fraction_non_alphanumeric': 0.11544650040225261, 'fraction_numerical': 0.004022526146419952, 'mean_word_length': 2.5427350427350426, 'pattern_counts': {'":': 2, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4480480', 'n_tokens_mistral': 773, 'n_tokens_neox': 728, 'n_words': 162}