<commit_before>import avahi
import dbus
import time
import os
import daemon, daemon.pidlockfile
import lockfile

__all__ = ["ZeroconfService"]

class ZeroconfService:
    """A simple class to publish a network service with zeroconf using
    avahi.

    """

    def __init__(self, name, port, stype="_hydra-agent._tcp",
                 domain="", host="", text=""):
        self.name = name
        self.stype = stype
        self.domain = domain
        self.host = host
        self.port = port
        self.text = text

    def publish(self):
        bus = dbus.SystemBus()
        server = dbus.Interface(
                         bus.get_object(
                                 avahi.DBUS_NAME,
                                 avahi.DBUS_PATH_SERVER),
                        avahi.DBUS_INTERFACE_SERVER)

        g = dbus.Interface(
                    bus.get_object(avahi.DBUS_NAME,
                                   server.EntryGroupNew()),
                    avahi.DBUS_INTERFACE_ENTRY_GROUP)

        g.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC,dbus.UInt32(0),
                     self.name, self.stype, self.domain, self.host,
                     dbus.UInt16(self.port), self.text)

        g.Commit()
        self.group = g

    def unpublish(self):
        self.group.Reset()


def publish_daemon(args):
    with daemon.DaemonContext(pidfile = \
                   daemon.pidlockfile.PIDLockFile('/var/run/hydra-agent.pid')):
        service = ZeroconfService(name="%s" % os.uname()[1], port=22)
        service.publish()
        while True:
            time.sleep(86400)
        # don't need to call service.unpublish() since the service
        # will be unpublished when this daemon exits<commit_msg>Modify syntax to work with python 2.4<commit_after>import avahi
import dbus
import time
import os
import daemon, daemon.pidlockfile
import lockfile

__all__ = ["ZeroconfService"]

class ZeroconfService:
    """A simple class to publish a network service with zeroconf using
    avahi.

    """

    def __init__(self, name, port, stype="_hydra-agent._tcp",
                 domain="", host="", text=""):
        self.name = name
        self.stype = stype
        self.domain = domain
        self.host = host
        self.port = port
        self.text = text

    def publish(self):
        bus = dbus.SystemBus()
        server = dbus.Interface(
                         bus.get_object(
                                 avahi.DBUS_NAME,
                                 avahi.DBUS_PATH_SERVER),
                        avahi.DBUS_INTERFACE_SERVER)

        g = dbus.Interface(
                    bus.get_object(avahi.DBUS_NAME,
                                   server.EntryGroupNew()),
                    avahi.DBUS_INTERFACE_ENTRY_GROUP)

        g.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC,dbus.UInt32(0),
                     self.name, self.stype, self.domain, self.host,
                     dbus.UInt16(self.port), self.text)

        g.Commit()
        self.group = g

    def unpublish(self):
        self.group.Reset()


def publish_daemon(args):
    context = daemon.DaemonContext(pidfile = daemon.pidlockfile.PIDLockFile('/var/run/hydra-agent.pid'))
    context.open()
    try:
        service = ZeroconfService(name="%s" % os.uname()[1], port=22)
        service.publish()
        while True:
            time.sleep(86400)
        # don't need to call service.unpublish() since the service
        # will be unpublished when this daemon exits
    finally:
        context.close()
{'fraction_non_alphanumeric': 0.09909399773499433, 'fraction_numerical': 0.007927519818799546, 'mean_word_length': 1.7515576323987538, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6327596', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1025, 'n_words': 221}