<commit_before># Write interface
from string import Template
import constants
import tools


class InterfacesWriter:
    ''' Short lived class to write interfaces file '''

    # Define templetes for blocks used in /etc/network/interfaces.
    _auto = Template('auto $name\n')
    _hotplug = Template('allow-hotplug $name\n')
    _iface = Template('iface $name $inet $source\n')
    _cmd = Template('\t$varient $value\n')

    _addressFields = ['address', 'network', 'netmask', 'broadcast', 'gateway']
    _prepFields = ['pre-up', 'up', 'down', 'post-down']
    _bridgeFields = ['ports', 'fd', 'hello', 'maxage', 'stp']

    def __init__(self, adapters=[]):
        self._adapters = adapters

    @property
    def adapters(self):
        return self._adapters

    @adapters.setter
    def adapters(self, value):
        self._adapters = value

    def backup_interfaces(self):
        ''' return True/False, command output '''

        return tools.safe_subprocess(["mv", constants.INTERFACES, constants.BACKUP])

    def write_interfaces(self):
        # Back up the old interfaces file.
        self.backup_interfaces()

        # Prepare to write the new interfaces file.
        with open(constants.INTERFACES, "a") as interfaces:
            # Loop through the provided networkAdaprers and write the new file.
            for adapter in self._adapters:
                # Get dict of details about the adapter.
                ifAttributes = adapter.export()

                self._write_auto(interfaces, adapter, ifAttributes)
                self._write_hotplug(interfaces, adapter, ifAttributes)
                self._write_inet(interfaces, adapter, ifAttributes)
                self._write_addressing(interfaces, adapter, ifAttributes)
                self._write_bridge(interfaces, adapter, ifAttributes)
                self._write_callbacks(interfaces, adapter, ifAttributes)

    def _write_auto(self, interfaces, adapter, ifAttributes):
        ''' Write if applicable '''
        try:
            if adapter.ifAttributes['auto'] is True:
                d = dict(name=ifAttributes['name'])
                interfaces.write(self._auto.substitute(d))
        except KeyError:
            pass
<commit_msg>interfacesWriter needs the filepath (both interfaces and backup files) to write into<commit_after># Write interface
from string import Template
import tools


class InterfacesWriter:
    ''' Short lived class to write interfaces file '''

    # Define templetes for blocks used in /etc/network/interfaces.
    _auto = Template('auto $name\n')
    _hotplug = Template('allow-hotplug $name\n')
    _iface = Template('iface $name $inet $source\n')
    _cmd = Template('\t$varient $value\n')

    _addressFields = ['address', 'network', 'netmask', 'broadcast', 'gateway']
    _prepFields = ['pre-up', 'up', 'down', 'post-down']
    _bridgeFields = ['ports', 'fd', 'hello', 'maxage', 'stp']

    def __init__(self, adapters, interfaces_path, backup_path):
        self._adapters = adapters
        self._interfaces_path = interfaces_path
        self._backup_path = backup_path

    @property
    def adapters(self):
        return self._adapters

    @adapters.setter
    def adapters(self, value):
        self._adapters = value

    def backup_interfaces(self):
        ''' return True/False, command output '''

        return tools.safe_subprocess(["mv", self._interfaces_path, self._backup_path])

    def write_interfaces(self):
        # Back up the old interfaces file.
        self.backup_interfaces()

        # Prepare to write the new interfaces file.
        with open(self._interfaces_path, "a") as interfaces:
            # Loop through the provided networkAdaprers and write the new file.
            for adapter in self._adapters:
                # Get dict of details about the adapter.
                ifAttributes = adapter.export()

                self._write_auto(interfaces, adapter, ifAttributes)
                self._write_hotplug(interfaces, adapter, ifAttributes)
                self._write_inet(interfaces, adapter, ifAttributes)
                self._write_addressing(interfaces, adapter, ifAttributes)
                self._write_bridge(interfaces, adapter, ifAttributes)
                self._write_callbacks(interfaces, adapter, ifAttributes)

    def _write_auto(self, interfaces, adapter, ifAttributes):
        ''' Write if applicable '''
        try:
            if adapter.ifAttributes['auto'] is True:
                d = dict(name=ifAttributes['name'])
                interfaces.write(self._auto.substitute(d))
        except KeyError:
            pass

{'fraction_non_alphanumeric': 0.10299219427580225, 'fraction_numerical': 0.0, 'mean_word_length': 2.6727707006369426, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1313325', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1226, 'n_words': 345}