예제 #1
0
파일: __init__.py 프로젝트: xmodpt/mariner
 def run(self) -> None:
     os.nice(5)
     for file in chain(FILES_DIRECTORY.rglob("*.ctb"),
                       FILES_DIRECTORY.rglob("*.cbddlp")):
         read_cached_ctb_file(file.absolute())
     for file in chain(FILES_DIRECTORY.rglob("*.ctb"),
                       FILES_DIRECTORY.rglob("*.cbddlp")):
         read_cached_preview(file.absolute())
예제 #2
0
def file_details() -> str:
    filename = str(request.args.get("filename"))
    path = (FILES_DIRECTORY / filename).resolve()
    if FILES_DIRECTORY not in path.parents:
        abort(400)
    ctb_file = read_cached_ctb_file(path)
    return jsonify({
        "filename": ctb_file.filename,
        "path": filename,
        "bed_size_mm": list(ctb_file.bed_size_mm),
        "height_mm": round(ctb_file.height_mm, 4),
        "layer_count": ctb_file.layer_count,
        "layer_height_mm": round(ctb_file.layer_height_mm, 4),
        "resolution": list(ctb_file.resolution),
        "print_time_secs": ctb_file.print_time_secs,
    })
예제 #3
0
def list_files() -> str:
    path_parameter = str(request.args.get("path", "."))
    path = (FILES_DIRECTORY / path_parameter).resolve()
    if FILES_DIRECTORY not in path.parents and path != FILES_DIRECTORY:
        abort(400)
    with os.scandir(path) as dir_entries:
        files = []
        directories = []
        for dir_entry in dir_entries:
            if dir_entry.is_file():
                ctb_file: Optional[CTBFile] = None
                if dir_entry.name.endswith((".ctb", ".cbddlp")):
                    ctb_file = read_cached_ctb_file(path / dir_entry.name)

                file_data: Dict[str, Any] = {
                    "filename":
                    dir_entry.name,
                    "path":
                    str((path / dir_entry.name).relative_to(FILES_DIRECTORY)),
                }

                if ctb_file:
                    file_data = {
                        "print_time_secs": ctb_file.print_time_secs,
                        "can_be_printed": True,
                        **file_data,
                    }
                else:
                    file_data = {
                        "can_be_printed": False,
                        **file_data,
                    }

                files.append(file_data)
            else:
                directories.append({"dirname": dir_entry.name})
        return jsonify({
            "directories": directories,
            "files": files,
        })
예제 #4
0
def print_status() -> str:
    with ElegooMars() as elegoo_mars:
        selected_file = elegoo_mars.get_selected_file()
        print_status = elegoo_mars.get_print_status()

        if print_status.state == PrinterState.IDLE:
            progress = 0.0
            print_details = {}
        else:
            ctb_file = read_cached_ctb_file(FILES_DIRECTORY / selected_file)

            if print_status.current_byte == 0:
                current_layer = 1
            else:
                current_layer = (ctb_file.end_byte_offset_by_layer.index(
                    print_status.current_byte) + 1)

            progress = (100.0 * none_throws(current_layer - 1) /
                        none_throws(ctb_file.layer_count))

            print_details = {
                "current_layer":
                current_layer,
                "layer_count":
                ctb_file.layer_count,
                "print_time_secs":
                ctb_file.print_time_secs,
                "time_left_secs":
                round(ctb_file.print_time_secs * (100.0 - progress) / 100.0),
            }

        return jsonify({
            "state": print_status.state.value,
            "selected_file": selected_file,
            "progress": progress,
            **print_details,
        })