Beispiel #1
0
def _sfn_really_universal(name):
    from octoprint.util.text import sanitize

    ### taken from pathvalidate library

    _WINDOWS_RESERVED_FILE_NAMES = (
        "CON", "PRN", "AUX", "CLOCK$", "NUL") + tuple(
            f"{name:s}{num:d}"
            for name, num in itertools.product(("COM", "LPT"), range(1, 10)))
    _MACOS_RESERVED_FILE_NAMES = (":", )

    result = sanitize(name, safe_chars="-_.()[] ").replace(" ", "_")
    root, ext = os.path.splitext(result)
    if root.upper() in (_WINDOWS_RESERVED_FILE_NAMES +
                        _MACOS_RESERVED_FILE_NAMES):
        root += "_"
    return root + ext
Beispiel #2
0
    def _get_channel_configs(self, force=False):
        """Retrieve all channel configs with sanitized keys."""

        with self._cached_channel_configs_mutex:
            if self._cached_channel_configs is None or force:
                configs = self._settings.get(["channels"], merged=True)
                order = self._settings.get(["channel_order"])
                all_keys = order + [
                    key for key in sorted(configs.keys()) if key not in order
                ]

                result = OrderedDict()
                for key in all_keys:
                    config = configs.get(key)
                    if config is None or "url" not in config or "name" not in config:
                        # strip invalid entries
                        continue
                    result[sanitize(key)] = config
                self._cached_channel_configs = result
        return self._cached_channel_configs
Beispiel #3
0
    def _get_channel_cache_path(self, key):
        """Retrieve cache path for channel key."""

        safe_key = sanitize(key)
        return os.path.join(self.get_plugin_data_folder(), f"{safe_key}.cache")
Beispiel #4
0
    def _get_channel_config(self, key, force=False):
        """Retrieve specific channel config for channel."""

        safe_key = sanitize(key)
        return self._get_channel_configs(force=force).get(safe_key)