Allow slicers to manage their profiles themselves

This commit is contained in:
Gina Häußge committed 2018-02-24 22:30:12 +01:00
1 parent c6bb825f7e
commit 763888e83a
2 files changed
+46 -15

No files matched your search

+41
View File
@@ -1861,6 +1861,47 @@ class SlicerPlugin(OctoPrintPlugin):
destination_extensions=["gco", "gcode", "g"]
)
def get_slicer_profiles(self, profile_path):
"""
Fetch all :class:`~octoprint.slicing.SlicingProfile`s stored for this slicer.
For compatibility reasons with existing slicing plugins this method defaults to returning profiles parsed from
.profile files in the plugin's ``profile_path``, utilizing the :func:`SlicingPlugin.get_slicer_profile` method
of the plugin implementation.
Arguments:
profile_path (str): The base folder where OctoPrint stores this slicer plugin's profiles
"""
try:
from os import scandir
except ImportError:
from scandir import scandir
import octoprint.util
profiles = dict()
for entry in scandir(profile_path):
if not entry.name.endswith(".profile") or octoprint.util.is_hidden_path(entry.name):
# we are only interested in profiles and no hidden files
continue
profile_name = entry.name[:-len(".profile")]
profiles[profile_name] = self.get_slicer_profile(entry.path)
return profiles
# noinspection PyMethodMayBeStatic
def get_slicer_profiles_lastmodified(self, profile_path):
import os
try:
from os import scandir
except ImportError:
from scandir import scandir
lms = [os.stat(profile_path).st_mtime]
lms += [os.stat(entry.path).st_mtime for entry in scandir(profile_path) if entry.name.endswith(".profile")]
return max(lms)
# noinspection PyMethodMayBeStatic
def get_slicer_default_profile(self):
"""
+5 -15
View File
@@ -377,9 +377,9 @@ class SlicingManager(object):
If it's a :class:`dict`, a new :class:`SlicingProfile` instance will be created with the supplied meta data and
the profile data as the :attr:`~SlicingProfile.data` attribute.
.. note::
If the profile is the first profile to be saved for the slicer, it will automatically be marked as default.
Arguments:
@@ -432,7 +432,7 @@ class SlicingManager(object):
profile=name)
event = octoprint.events.Events.SLICING_PROFILE_MODIFIED if is_overwrite else octoprint.events.Events.SLICING_PROFILE_ADDED
octoprint.events.eventManager().fire(event, payload)
if first_profile:
# enforce the first profile we add for this slicer is set as default
self.set_default_profile(slicer, name)
@@ -557,16 +557,8 @@ class SlicingManager(object):
if require_configured and not slicer in self.configured_slicers:
raise SlicerNotConfigured(slicer)
profiles = dict()
slicer_profile_path = self.get_slicer_profile_path(slicer)
for entry in scandir(slicer_profile_path):
if not entry.name.endswith(".profile") or octoprint.util.is_hidden_path(entry.name):
# we are only interested in profiles and no hidden files
continue
profile_name = entry.name[:-len(".profile")]
profiles[profile_name] = self._load_profile_from_path(slicer, entry.path, require_configured=require_configured)
return profiles
return self.get_slicer(slicer).get_slicer_profiles(slicer_profile_path)
def profiles_last_modified(self, slicer):
"""
@@ -583,9 +575,7 @@ class SlicingManager(object):
raise UnknownSlicer(slicer)
slicer_profile_path = self.get_slicer_profile_path(slicer)
lms = [os.stat(slicer_profile_path).st_mtime]
lms += [os.stat(entry.path).st_mtime for entry in scandir(slicer_profile_path) if entry.name.endswith(".profile")]
return max(lms)
return self.get_slicer(slicer).get_slicer_profiles_lastmodified(slicer_profile_path)
def get_slicer_profile_path(self, slicer):
"""