Ejemplo n.º 1
0
    def test_loadAndSave(self, machine_manager, definition_file_name, instance_file_name, profile_file_name, target_profile_file_name):
        profile = Profile(machine_manager)
        definition = MachineDefinition(machine_manager, self._getDefinitionsFilePath(definition_file_name))
        definition.loadMetaData()

        machine_manager.addMachineDefinition(definition)

        machine_instance = MachineInstance(machine_manager, definition = definition)
        machine_instance.loadFromFile(self._getInstancesFilePath(instance_file_name))
        profile._active_instance = machine_instance
        profile.loadFromFile(self._getProfileFilePath(profile_file_name))
        try:
            os.remove(self._getProfileFilePath(target_profile_file_name)) # Clear any previous tests
        except:
            pass
        profile.saveToFile(self._getProfileFilePath(target_profile_file_name))

        config_loaded = configparser.ConfigParser()
        config_loaded.read(self._getProfileFilePath(instance_file_name))
        config_saved = configparser.ConfigParser()
        config_saved.read(self._getProfileFilePath(target_profile_file_name))

        for section in config_loaded.sections():
            assert section in config_saved.sections()
            for key in config_loaded[section]:
                assert key in config_saved[section]
                assert config_loaded[section][key] == config_saved[section][key]
Ejemplo n.º 2
0
    def loadProfiles(self):
        storage_path = Resources.getStoragePathForType(Resources.Profiles)

        dirs = Resources.getAllPathsForType(Resources.Profiles)
        for dir in dirs:
            if not os.path.isdir(dir):
                continue

            read_only = dir != storage_path

            for file_name in os.listdir(dir):
                path = os.path.join(dir, file_name)

                if os.path.isdir(path):
                    continue

                profile = Profile(self, read_only)
                try:
                    profile.loadFromFile(path)
                except Exception as e:
                    Logger.log("e", "An exception occurred loading Profile %s: %s", path, str(e))
                    continue

                if not self.findProfile(profile.getName()):
                    self._profiles.append(profile)
                    profile.nameChanged.connect(self._onProfileNameChanged)

        profile = self.findProfile(Preferences.getInstance().getValue("machines/active_profile"))
        if profile:
            self.setActiveProfile(profile)

        self.profilesChanged.emit()
Ejemplo n.º 3
0
    def loadProfiles(self):
        storage_path = Resources.getStoragePathForType(Resources.Profiles)

        dirs = Resources.getAllPathsForType(Resources.Profiles)
        for dir in dirs:
            if not os.path.isdir(dir):
                continue

            read_only = dir != storage_path

            for root, dirs, files in os.walk(dir):
                for file_name in files:
                    path = os.path.join(root, file_name)

                    if os.path.isdir(path):
                        continue

                    profile = Profile(self, read_only)
                    try:
                        profile.loadFromFile(path)
                    except Exception as e:
                        Logger.log("e", "An exception occurred loading Profile %s: %s", path, str(e))
                        continue

                    if not self.findProfile(profile.getName(), variant_name = profile.getMachineVariantName(), material_name = profile.getMaterialName(), instance = self._active_machine):
                        self._profiles.append(profile)
                        profile.nameChanged.connect(self._onProfileNameChanged)

        for instance in self._machine_instances:
            try:
                file_name = urllib.parse.quote_plus(instance.getName()) + ".curaprofile"
                instance.getWorkingProfile().loadFromFile(Resources.getStoragePath(Resources.MachineInstanceProfiles, file_name))
            except Exception as e:
                Logger.log("w", "Could not load working profile: %s: %s", file_name, str(e))
                self._setDefaultVariantMaterialProfile(instance)

        self._protect_working_profile = True

        if self._active_machine:
            profile_name = self._active_machine.getActiveProfileName()
            if profile_name == "":
                profile_name = "Normal Quality"

            profile = self.findProfile(self._active_machine.getActiveProfileName(), instance = self._active_machine)
            if profile:
                self.setActiveProfile(profile)
            else:
                profiles = self.getProfiles(instance = self._active_machine)
                if len(profiles) > 0:
                    self.setActiveProfile(profiles[0])

        self.profilesChanged.emit()
        self._protect_working_profile = False
Ejemplo n.º 4
0
    def test_profiles(self, machine_manager):
        profile_1 = Profile(machine_manager)
        profile_2 = Profile(machine_manager)
        definition = MachineDefinition(
            machine_manager,
            self._getDefinitionsFilePath("simple_machine.json"))
        definition.loadMetaData()
        machine_manager.addMachineDefinition(definition)

        machine_instance = MachineInstance(machine_manager,
                                           definition=definition,
                                           name="Basic Test")
        machine_instance.loadFromFile(
            self._getInstancesFilePath("simple_machine.cfg"))
        machine_manager.addMachineInstance(machine_instance)
        profile_1._active_instance = machine_instance
        profile_2._active_instance = machine_instance

        profile_1.loadFromFile(
            self._getProfileFilePath("simple_machine_with_overrides.cfg"))
        profile_2.loadFromFile(
            self._getProfileFilePath("simple_machine_with_overrides.cfg"))
        machine_manager.addProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_1]

        # Check if adding again has no effect
        machine_manager.addProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_1]

        # Check that adding another profile with same name does not work
        with pytest.raises(DuplicateProfileError):
            machine_manager.addProfile(profile_2)

        # Changing the name and then adding it should work
        profile_2.setName("test")
        machine_manager.addProfile(profile_2)
        assert profile_1 in machine_manager.getProfiles(
        ) and profile_2 in machine_manager.getProfiles()

        assert machine_manager.findProfile("test") == profile_2

        # Check if removing one of the profiles works
        machine_manager.removeProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_2]

        machine_manager.setActiveProfile(profile_2)
        assert machine_manager.getActiveProfile() == profile_2

        machine_manager.removeProfile(profile_2)

        assert machine_manager.getProfiles() == []
Ejemplo n.º 5
0
    def test_profileOverride(self, machine_manager, definition_file_name, instance_file_name, profile_file_name, expected_values):
        profile = Profile(machine_manager)
        definition = MachineDefinition(machine_manager, self._getDefinitionsFilePath(definition_file_name))
        definition.loadMetaData()

        machine_manager.addMachineDefinition(definition)

        machine_instance = MachineInstance(machine_manager, definition = definition)
        machine_instance.loadFromFile(self._getInstancesFilePath(instance_file_name))
        profile._active_instance = machine_instance
        profile.loadFromFile(self._getProfileFilePath(profile_file_name))

        for key in expected_values:
            assert profile.getSettingValue(key) == expected_values[key]
Ejemplo n.º 6
0
    def importProfile(self, url):
        path = url.toLocalFile()
        if not path:
            return

        profile = Profile(self._manager, read_only = False)
        try:
            profile.loadFromFile(path)
        except Exception as e:
            m = Message(catalog.i18nc("@info:status", "Failed to import profile from file <filename>{0}</filename>: <message>{1}</message>", path, str(e)))
            m.show()
        else:
            m = Message(catalog.i18nc("@info:status", "Successfully imported profile {0}", profile.getName()))
            m.show()
            self._manager.addProfile(profile)
Ejemplo n.º 7
0
    def test_profiles(self, machine_manager):
        profile_1 = Profile(machine_manager)
        profile_2 = Profile(machine_manager)
        definition = MachineDefinition(machine_manager, self._getDefinitionsFilePath("simple_machine.json"))
        definition.loadMetaData()
        machine_manager.addMachineDefinition(definition)

        machine_instance = MachineInstance(machine_manager, definition = definition, name = "Basic Test")
        machine_instance.loadFromFile(self._getInstancesFilePath("simple_machine.cfg"))
        machine_manager.addMachineInstance(machine_instance)
        profile_1._active_instance = machine_instance
        profile_2._active_instance = machine_instance

        profile_1.loadFromFile(self._getProfileFilePath("simple_machine_with_overrides.cfg"))
        profile_2.loadFromFile(self._getProfileFilePath("simple_machine_with_overrides.cfg"))
        machine_manager.addProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_1]

        # Check if adding again has no effect
        machine_manager.addProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_1]

        # Check that adding another profile with same name does not work
        with pytest.raises(DuplicateProfileError):
            machine_manager.addProfile(profile_2)

        # Changing the name and then adding it should work
        profile_2.setName("test")
        machine_manager.addProfile(profile_2)
        assert profile_1 in machine_manager.getProfiles() and profile_2 in machine_manager.getProfiles()

        assert machine_manager.findProfile("test") == profile_2

        # Check if removing one of the profiles works
        machine_manager.removeProfile(profile_1)
        assert machine_manager.getProfiles() == [profile_2]

        machine_manager.setActiveProfile(profile_2)
        assert machine_manager.getActiveProfile() == profile_2

        machine_manager.removeProfile(profile_2)
        
        assert machine_manager.getProfiles() == []
Ejemplo n.º 8
0
    def importProfile(self, url):
        path = url.toLocalFile()
        if not path:
            return

        profile = Profile(self._manager, read_only=False)
        try:
            profile.loadFromFile(path)
            self._manager.addProfile(profile)
        except SettingsError.DuplicateProfileError as e:
            count = 2
            name = "{0} {1}".format(profile.getName(), count)
            while (self._manager.findProfile(name) != None):
                count += 1
                name = "{0} {1}".format(profile.getName(), count)
            profile.setName(name)
            self._manager.addProfile(profile)
            return {
                "status":
                "duplicate",
                "message":
                catalog.i18nc("@info:status", "Profile was imported as {0}",
                              name)
            }
        except Exception as e:
            return {
                "status":
                "error",
                "message":
                catalog.i18nc(
                    "@info:status",
                    "Failed to import profile from file <filename>{0}</filename>: <message>{1}</message>",
                    path, str(e))
            }
        else:
            return {
                "status":
                "ok",
                "message":
                catalog.i18nc("@info:status",
                              "Successfully imported profile {0}",
                              profile.getName())
            }
Ejemplo n.º 9
0
    def loadProfiles(self):
        storage_path = Resources.getStoragePathForType(Resources.Profiles)

        dirs = Resources.getAllPathsForType(Resources.Profiles)
        for dir in dirs:
            if not os.path.isdir(dir):
                continue

            read_only = dir != storage_path

            for file_name in os.listdir(dir):
                path = os.path.join(dir, file_name)

                if os.path.isdir(path):
                    continue

                profile = Profile(self, read_only)
                try:
                    profile.loadFromFile(path)
                except Exception as e:
                    Logger.log("e",
                               "An exception occurred loading Profile %s: %s",
                               path, str(e))
                    continue

                if not self.findProfile(profile.getName()):
                    self._profiles.append(profile)
                    profile.nameChanged.connect(self._onProfileNameChanged)

        profile = self.findProfile(
            Preferences.getInstance().getValue("machines/active_profile"))
        if profile:
            self.setActiveProfile(profile)
        else:
            if Preferences.getInstance().getValue(
                    "machines/active_profile") == "":
                for profile in self._profiles:
                    self.setActiveProfile(
                        profile)  #default to first profile you can find
                    break
        self.profilesChanged.emit()
Ejemplo n.º 10
0
    def importProfile(self, url):
        path = url.toLocalFile()
        if not path:
            return

        profile = Profile(self._manager, read_only = False)
        try:
            profile.loadFromFile(path)
            self._manager.addProfile(profile)
        except SettingsError.DuplicateProfileError as e:
            count = 2
            name = "{0} {1}".format(profile.getName(), count)
            while(self._manager.findProfile(name) != None):
                count += 1
                name = "{0} {1}".format(profile.getName(), count)
            profile.setName(name)
            self._manager.addProfile(profile)
            return { "status": "duplicate", "message": catalog.i18nc("@info:status", "Profile was imported as {0}", name) }
        except Exception as e:
            return { "status": "error", "message": catalog.i18nc("@info:status", "Failed to import profile from file <filename>{0}</filename>: <message>{1}</message>", path, str(e)) }
        else:
            return { "status": "ok", "message": catalog.i18nc("@info:status", "Successfully imported profile {0}", profile.getName()) }
Ejemplo n.º 11
0
    def loadProfiles(self):
        storage_path = Resources.getStoragePathForType(Resources.Profiles)

        dirs = Resources.getAllPathsForType(Resources.Profiles)
        for dir in dirs:
            if not os.path.isdir(dir):
                continue

            read_only = dir != storage_path

            for root, dirs, files in os.walk(dir):
                for file_name in files:
                    path = os.path.join(root, file_name)

                    if os.path.isdir(path):
                        continue

                    profile = Profile(self, read_only)
                    try:
                        profile.loadFromFile(path)
                    except Exception as e:
                        Logger.log(
                            "e",
                            "An exception occurred loading Profile %s: %s",
                            path, str(e))
                        continue

                    if not self.findProfile(
                            profile.getName(),
                            variant_name=profile.getMachineVariantName(),
                            material_name=profile.getMaterialName(),
                            instance=self._active_machine):
                        self._profiles.append(profile)
                        profile.nameChanged.connect(self._onProfileNameChanged)

        for instance in self._machine_instances:
            try:
                file_name = urllib.parse.quote_plus(
                    instance.getName()) + ".curaprofile"
                instance.getWorkingProfile().loadFromFile(
                    Resources.getStoragePath(Resources.MachineInstanceProfiles,
                                             file_name))
            except Exception as e:
                Logger.log("w", "Could not load working profile: %s: %s",
                           file_name, str(e))
                self._setDefaultVariantMaterialProfile(instance)

        self._protect_working_profile = True

        if self._active_machine:
            profile_name = self._active_machine.getActiveProfileName()
            if profile_name == "":
                profile_name = "Normal Quality"

            profile = self.findProfile(
                self._active_machine.getActiveProfileName(),
                instance=self._active_machine)
            if profile:
                self.setActiveProfile(profile)
            else:
                profiles = self.getProfiles(instance=self._active_machine)
                if len(profiles) > 0:
                    self.setActiveProfile(profiles[0])

        self.profilesChanged.emit()
        self._protect_working_profile = False
Ejemplo n.º 12
0
    def loadProfiles(self):
        storage_path = Resources.getStoragePathForType(Resources.Profiles)

        dirs = Resources.getAllPathsForType(Resources.Profiles)
        for dir in dirs:
            if not os.path.isdir(dir):
                continue

            read_only = dir != storage_path

            for root, dirs, files in os.walk(dir):
                for file_name in files:
                    path = os.path.join(root, file_name)

                    if os.path.isdir(path):
                        continue

                    # Bit of a hack, but we should only use cfg or curaprofile files in the profile folder.
                    try:
                        extension = path.split(".")[-1]
                        if extension != "cfg" and extension != "curaprofile":
                            continue
                    except:
                        continue  # profile has no extension

                    profile = Profile(self, read_only)
                    try:
                        profile.loadFromFile(path)
                    except Exception as e:
                        Logger.log(
                            "e",
                            "An exception occurred loading Profile %s: %s",
                            path, str(e))
                        continue

                    self._profiles.append(profile)
                    profile.nameChanged.connect(self._onProfileNameChanged)

        for instance in self._machine_instances:
            try:
                file_name = urllib.parse.quote_plus(
                    instance.getName()) + ".curaprofile"
                instance.getWorkingProfile().loadFromFile(
                    Resources.getStoragePath(Resources.MachineInstanceProfiles,
                                             file_name))
            except Exception as e:
                Logger.log("w", "Could not load working profile: %s: %s",
                           file_name, str(e))
                self._setDefaultVariantMaterialProfile(instance)

        self._protect_working_profile = True

        if self._active_machine:
            profile_name = self._active_machine.getActiveProfileName()
            if profile_name == "":
                profile_name = self._active_machine.getMachineDefinition(
                ).getPreference("prefered_profile")

            profile = self.findProfile(
                self._active_machine.getActiveProfileName(),
                instance=self._active_machine)
            if profile:
                self.setActiveProfile(profile)
            else:
                profiles = self.getProfiles(instance=self._active_machine)
                if len(profiles) > 0:
                    self.setActiveProfile(profiles[0])

        self.profilesChanged.emit()
        self._protect_working_profile = False