コード例 #1
0
ファイル: MultiSlice.py プロジェクト: Badgie/CuraMultiSlice
    def _write_gcode(self, state) -> None:
        """
        Write sliced model to file in output dir and emit signal once done
        """
        # state = 3 = process is done
        if state == 3:
            # ensure proper file suffix
            file_name = self._current_model_name.replace(
                self._current_model_suffix, '.gcode')

            # construct path relative to output directory using input path structure if we are
            # following directories
            # otherwise just dump it into the output directory
            if self._preserve_dirs:
                rel_path = self._current_model.relative_to(self._input_path)
                path = (self._output_path / rel_path).parent / file_name
                Path_(path.parent).mkdir(parents=True, exist_ok=True)
            else:
                path = self._output_path / file_name

            self._log_msg('Writing gcode to file {0}'.format(file_name))
            self._log_msg('Saving to directory: {0}'.format(str(path)))

            with Path_(path).open(mode='w') as stream:
                res = PluginRegistry.getInstance().getPluginObject(
                    "GCodeWriter").write(stream, [])

            # GCodeWriter notifies success state with bool
            if res:
                self._write_done.emit()
コード例 #2
0
 def __init__(self,
              initial: Union[str, os.PathLike] = '.',
              *pathsegments: str):
     self.__path = Path_(_norm_path(initial), *pathsegments)
     self.__parent = self.__path.parent.as_posix()
     self._parent_name = self.__path.cwd().name
     self._verify()
コード例 #3
0
ファイル: MultiSlice.py プロジェクト: Badgie/CuraMultiSlice
    def validate_input(self) -> bool:
        """
        Try and validate applicable(bool options obviously don't need to be validated) options.
        Emit error and return false if any fail.
        """
        # file pattern should be valid regex
        try:
            re.compile(self._file_pattern)
        except re.error:
            self._send_error('Regex string \"{0}\" is not a valid regex. '
                             'Please try again.'.format(self._file_pattern))
            return False

        # input path should be a valid path
        if type(self._input_path) is str or not Path_(
                self._input_path).is_dir():
            self._send_error('Input path \"{0}\" is not a valid path. '
                             'Please try again.'.format(self._input_path))
            return False

        # output path should be a valid path
        if type(self._output_path) is str or not Path_(
                self._output_path).is_dir():
            self._send_error('Output path \"{0}\" is not a valid path. '
                             'Please try again.'.format(self._output_path))
            return False

        # follow depth should be an int
        try:
            self._follow_depth = int(self._follow_depth)
        except ValueError:
            self._send_error('Depth value \"{0}\" is not a valid integer. '
                             'Please try again.'.format(self._follow_depth))
            return False

        return True
コード例 #4
0
ファイル: MultiSlice.py プロジェクト: Badgie/CuraMultiSlice
        def _files(pattern: str, path: Path, depth: int):
            # skip if we exceeded recursion depth
            if depth > self._follow_depth:
                return

            try:
                for d in Path_(path).iterdir():

                    # if we reached a directory, do recursive call
                    if d.is_dir():
                        _files(pattern, d, depth + 1)
                    # if we reached a file, check if it matches file pattern and add to list if so
                    elif d.is_file() and re.match(pattern, d.name):
                        nonlocal files
                        files.append(d if abs_paths else d.name)

            except PermissionError:
                # if we can't read the current step, notify and skip
                self._log_msg(
                    'Could not access directory {0}, reason: permission denied. '
                    'Skipping.'.format(str(path)))
                return