<commit_before># Copyright (c) 2015 <NAME>.
# Uranium is released under the terms of the AGPLv3 or higher.

import urllib
import os

from UM.Signal import Signal, SignalEmitter
from UM.Resources import Resources

from UM.Settings.MachineDefinition import MachineDefinition
from UM.Settings.MachineSettings import MachineSettings
from UM.Settings.Profile import Profile
from UM.Settings.SettingsError import SettingsError

from UM.i18n import i18nCatalog
catalog = i18nCatalog("uranium")

class MachineManager(SignalEmitter):
    def __init__(self):
        super().__init__()

        self._machine_defintions = []
        self._machine_instances = []
        self._profiles = []

        self._active_machine = None
        self._active_profile = None

    machineDefinitionsChanged = Signal()

    def getMachineDefinitions(self):
        return self._machine_defintions

    def getAllMachineVariants(self, machine_id):
        variants = []
        for definition in self._machine_defintions:
            if definition.getId() == machine_id:
                variants.append(definition)

        return variants

    machineInstancesChanged = Signal()

    def getMachineInstance(self, index):
        return self._machine_instances[index]

    def getMachineInstances(self):
        return self._machine_instances

    def addMachineInstance(self, instance):
        if instance in self._machine_instances:
            return

        self._machine_instances.append(instance)
        self.machineInstancesChanged.emit()

    def removeMachineInstance(self, instance):
        if instance not in self._machine_instances:
            return

        self._machine_instances.remove(instance)

        try:
            path = Resources.getStoragePath(Resources.MachineInstances, urllib.parse.quote_plus(instance.getName()) + ".cfg")
            os.remove(path)
        except FileNotFoundError:
            pass

        self.machineInstancesChanged.emit()

    def findMachineInstance(self, name):
        for i in range(len(self._machine_instances)):
            if self._machine_instances[i].getName() == name:
                return i

        return -1

    ##  Get the currently active machine instance
    #   \returns active_machine \type{MachineSettings}
    def getActiveMachineInstance(self):
        return self._active_machine

    ##  Set the currently active machine
    #   \param active_machine \type{MachineSettings}
    def setActiveMachineInstance(self, machine):
        if machine == self._active_machine:
            return

        self._active_machine = machine
        self.activeMachineInstanceChanged.emit()

    activeMachineInstanceChanged = Signal()

    profilesChanged = Signal()

    def getProfiles(self):
        return self._profiles

    def addProfile(self, profile):
        if profile in self._profiles:
            return

        self._profiles.append(profile)
        self.profilesChanged.emit()

    def removeProfile(self, profile):
        if profile not in self._profiles:
            return

        self._profiles.remove(profile)
        self.profilesChanged.emit()

    def findProfile(self, name):
        for profile in self._profiles:
            if profile.getName() == name:
                return profile

        return None

    activeProfileChanged = Signal()

    def getActiveProfile(self):
        return self._active_profile

    def setActiveProfile(self, profile):
        if profile not in self._profiles or self._active_profile == profile:
            return

        self._active_profile = profile
        self.activeProfileChanged.emit()

    def loadMachineDefinitions(self):
        dirs = Resources.getAllPathsForType(Resources.MachineDefinitions)
        for dir in dirs:
            if not os.path.isdir(dir):
                continue

            for file_name in os.listdir(dir):
                data = None
                path = os.path.join(dir, file_name)<commit_msg>Add a loadAll method to MachineManager<commit_after># Copyright (c) 2015 Ultimaker B.V.
# Uranium is released under the terms of the AGPLv3 or higher.

import urllib
import os

from UM.Signal import Signal, SignalEmitter
from UM.Resources import Resources

from UM.Settings.MachineDefinition import MachineDefinition
from UM.Settings.MachineSettings import MachineSettings
from UM.Settings.Profile import Profile
from UM.Settings.SettingsError import SettingsError

from UM.i18n import i18nCatalog
catalog = i18nCatalog("uranium")

class MachineManager(SignalEmitter):
    def __init__(self):
        super().__init__()

        self._machine_defintions = []
        self._machine_instances = []
        self._profiles = []

        self._active_machine = None
        self._active_profile = None

    machineDefinitionsChanged = Signal()

    def getMachineDefinitions(self):
        return self._machine_defintions

    def getAllMachineVariants(self, machine_id):
        variants = []
        for definition in self._machine_defintions:
            if definition.getId() == machine_id:
                variants.append(definition)

        return variants

    machineInstancesChanged = Signal()

    def getMachineInstance(self, index):
        return self._machine_instances[index]

    def getMachineInstances(self):
        return self._machine_instances

    def addMachineInstance(self, instance):
        if instance in self._machine_instances:
            return

        self._machine_instances.append(instance)
        self.machineInstancesChanged.emit()

    def removeMachineInstance(self, instance):
        if instance not in self._machine_instances:
            return

        self._machine_instances.remove(instance)

        try:
            path = Resources.getStoragePath(Resources.MachineInstances, urllib.parse.quote_plus(instance.getName()) + ".cfg")
            os.remove(path)
        except FileNotFoundError:
            pass

        self.machineInstancesChanged.emit()

    def findMachineInstance(self, name):
        for i in range(len(self._machine_instances)):
            if self._machine_instances[i].getName() == name:
                return i

        return -1

    ##  Get the currently active machine instance
    #   \returns active_machine \type{MachineSettings}
    def getActiveMachineInstance(self):
        return self._active_machine

    ##  Set the currently active machine
    #   \param active_machine \type{MachineSettings}
    def setActiveMachineInstance(self, machine):
        if machine == self._active_machine:
            return

        self._active_machine = machine
        self.activeMachineInstanceChanged.emit()

    activeMachineInstanceChanged = Signal()

    profilesChanged = Signal()

    def getProfiles(self):
        return self._profiles

    def addProfile(self, profile):
        if profile in self._profiles:
            return

        self._profiles.append(profile)
        self.profilesChanged.emit()

    def removeProfile(self, profile):
        if profile not in self._profiles:
            return

        self._profiles.remove(profile)
        self.profilesChanged.emit()

    def findProfile(self, name):
        for profile in self._profiles:
            if profile.getName() == name:
                return profile

        return None

    activeProfileChanged = Signal()

    def getActiveProfile(self):
        return self._active_profile

    def setActiveProfile(self, profile):
        if profile not in self._profiles or self._active_profile == profile:
            return

        self._active_profile = profile
        self.activeProfileChanged.emit()

    def loadAll(self):
        self.loadMachineDefinitions()
        self.loadMachineInstances()
        self.loadProfiles()

    def loadMachineDefinitions(self):
        dirs = Resources.getAllPathsForType(Resources.MachineDefinitions)
        for dir in dirs:
            if not os.path.isdir(dir):
                continue

            for file_name in os.listdir(dir):
                data = None
                path = os.path.join(dir, file_name)
{'fraction_non_alphanumeric': 0.0741246585547554, 'fraction_numerical': 0.0029798857710454435, 'mean_word_length': 2.559434379142731, 'pattern_counts': {'":': 0, '<': 4, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '899231', 'n_tokens_mistral': 2151, 'n_tokens_neox': 2023, 'n_words': 518}