<commit_before>
import os
import socket
import subprocess
import sys
import time
import logging
from pyparsing import *
from lvsm import utils, genericdirector
from lvsm.modules import ldparser

logger = logging.getLogger('lvsm')


class Ldirectord(genericdirector.GenericDirector):
    """Handles ldirector-specific functionality like enable/disable actions.
    """
    def __init__(self, maintenance_dir, ipvsadm,
                 configfile='', restart_cmd='', nodes=''):
        super(Ldirectord, self).__init__(maintenance_dir, ipvsadm,
                                         configfile, restart_cmd, nodes)

    def disable(self, host, port='', reason=''):
        # Prepare a canned error message
        error_msg = "Problem disabling on remote node"
        if self.maintenance_dir:
            hostip = utils.gethostname(host)
            if not hostip:
                return False
            if port:
                # check that it's a valid port
                portnum = utils.getportnum(port)
                if portnum == -1:
                    return False
                hostport = hostip + ":" + str(portnum)
            else:
                hostport = hostip
            # go through maint_dir to see if host is already disabled
            filenames = os.listdir(self.maintenance_dir)
            for filename in filenames:
                f = self.convert_filename(filename)
                if hostport == f or hostip == f:
                    print "host is already disabled!"
                    return True
            try:
                f = open(self.maintenance_dir + "/" + hostport, 'w')
                f.write(reason)
            except IOError as e:
                logger.error(e)
                return False
<commit_msg>Extract maintenance dir from the config file<commit_after>
import os
import socket
import subprocess
import sys
import time
import logging
from pyparsing import *
from lvsm import utils, genericdirector
from lvsm.modules import ldparser

logger = logging.getLogger('lvsm')


class Ldirectord(genericdirector.GenericDirector):
    """Handles ldirector-specific functionality like enable/disable actions.
    """
    def __init__(self, ipvsadm, configfile='', restart_cmd='', nodes=''):
        super(Ldirectord, self).__init__(ipvsadm, configfile, restart_cmd, nodes)
        try:
            f = open(self.configfile)
        except OSError as e:
            logger.error(e)

        self.maintenance_dir = ""

        for line in f:
            if line.find("maintenancedir") > -1:
                s, sep, path = line.partition('=')
                self.maintenance_dir = path.strip()

    def disable(self, host, port='', reason=''):
        # Prepare a canned error message
        error_msg = "Problem disabling on remote node"
        if self.maintenance_dir:
            hostip = utils.gethostname(host)
            if not hostip:
                return False
            if port:
                # check that it's a valid port
                portnum = utils.getportnum(port)
                if portnum == -1:
                    return False
                hostport = hostip + ":" + str(portnum)
            else:
                hostport = hostip
            # go through maint_dir to see if host is already disabled
            filenames = os.listdir(self.maintenance_dir)
            for filename in filenames:
                f = self.convert_filename(filename)
                if hostport == f or hostip == f:
                    print "host is already disabled!"
                    return True
            try:
                f = open(self.maintenance_dir + "/" + hostport, 'w')
                f.write(reason)
            except IOError as e:
                logger.error(e)
                return False

{'fraction_non_alphanumeric': 0.08029582673005811, 'fraction_numerical': 0.000792393026941363, 'mean_word_length': 1.7382501807664497, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1522398', 'n_tokens_mistral': 1016, 'n_tokens_neox': 967, 'n_words': 302}