예제 #1
0
def printerState():
	if not printer.is_operational():
		return make_response("Printer is not operational", 409)

	# process excludes
	excludes = []
	if "exclude" in request.values:
		excludeStr = request.values["exclude"]
		if len(excludeStr.strip()) > 0:
			excludes = filter(lambda x: x in ["temperature", "sd", "state"], map(lambda x: x.strip(), excludeStr.split(",")))

	result = {}

	processor = lambda x: x
	if not printerProfileManager.get_current_or_default()["heatedBed"]:
		processor = _delete_bed

	# add temperature information
	if not "temperature" in excludes:
		result.update({"temperature": _get_temperature_data(processor)})

	# add sd information
	if not "sd" in excludes and settings().getBoolean(["feature", "sdSupport"]):
		result.update({"sd": {"ready": printer.is_sd_ready()}})

	# add state information
	if not "state" in excludes:
		state = printer.get_current_data()["state"]
		result.update({"state": state})

	return jsonify(result)
예제 #2
0
def printerState():
    if not printer.is_operational():
        return make_response("Printer is not operational", 409)

    # process excludes
    excludes = []
    if "exclude" in request.values:
        excludeStr = request.values["exclude"]
        if len(excludeStr.strip()) > 0:
            excludes = filter(lambda x: x in ["temperature", "sd", "state"],
                              map(lambda x: x.strip(), excludeStr.split(",")))

    result = {}

    processor = lambda x: x
    if not printerProfileManager.get_current_or_default()["heatedBed"]:
        processor = _delete_bed

    # add temperature information
    if not "temperature" in excludes:
        result.update({"temperature": _get_temperature_data(processor)})

    # add sd information
    if not "sd" in excludes and settings().getBoolean(["feature", "sdSupport"
                                                       ]):
        result.update({"sd": {"ready": printer.is_sd_ready()}})

    # add state information
    if not "state" in excludes:
        state = printer.get_current_data()["state"]
        result.update({"state": state})

    return jsonify(result)
예제 #3
0
def _convert_profile(profile):
	default = printerProfileManager.get_default()["id"]
	current = printerProfileManager.get_current_or_default()["id"]

	converted = copy.deepcopy(profile)
	converted["resource"] = url_for(".printerProfilesGet", identifier=profile["id"], _external=True)
	converted["default"] = (profile["id"] == default)
	converted["current"] = (profile["id"] == current)
	return converted
예제 #4
0
def _convert_profile(profile):
	default = printerProfileManager.get_default()["id"]
	current = printerProfileManager.get_current_or_default()["id"]

	converted = copy.deepcopy(profile)
	converted["resource"] = url_for(".printerProfilesGet", identifier=profile["id"], _external=True)
	converted["default"] = (profile["id"] == default)
	converted["current"] = (profile["id"] == current)
	return converted
예제 #5
0
def printerState():
    if not printer.is_operational():
        abort(409, description="Printer is not operational")

    # process excludes
    excludes = []
    if "exclude" in request.values:
        excludeStr = request.values["exclude"]
        if len(excludeStr.strip()) > 0:
            excludes = list(
                filter(
                    lambda x: x in ["temperature", "sd", "state"],
                    map(lambda x: x.strip(), excludeStr.split(",")),
                )
            )

    result = {}

    # add temperature information
    if "temperature" not in excludes:
        processor = lambda x: x
        heated_bed = printerProfileManager.get_current_or_default()["heatedBed"]
        heated_chamber = printerProfileManager.get_current_or_default()["heatedChamber"]
        if not heated_bed and not heated_chamber:
            processor = _keep_tools
        elif not heated_bed:
            processor = _delete_bed
        elif not heated_chamber:
            processor = _delete_chamber

        result.update({"temperature": _get_temperature_data(processor)})

    # add sd information
    if "sd" not in excludes and settings().getBoolean(["feature", "sdSupport"]):
        result.update({"sd": {"ready": printer.is_sd_ready()}})

    # add state information
    if "state" not in excludes:
        state = printer.get_current_data()["state"]
        result.update({"state": state})

    return jsonify(result)
예제 #6
0
def printerChamberState():
	if not printer.is_operational():
		return make_response("Printer is not operational", 409)

	if not printerProfileManager.get_current_or_default()["heatedChamber"]:
		return make_response("Printer does not have a heated chamber", 409)

	data = _get_temperature_data(_keep_chamber)
	if isinstance(data, Response):
		return data
	else:
		return jsonify(data)
예제 #7
0
def printerBedState():
    if not printer.is_operational():
        return make_response("Printer is not operational", 409)

    if not printerProfileManager.get_current_or_default()["heatedBed"]:
        return make_response("Printer does not have a heated bed", 409)

    data = _get_temperature_data(_delete_tools)
    if isinstance(data, Response):
        return data
    else:
        return jsonify(data)
예제 #8
0
def printerBedState():
	if not printer.is_operational():
		return make_response("Printer is not operational", 409)

	if not printerProfileManager.get_current_or_default()["heatedBed"]:
		return make_response("Printer does not have a heated bed", 409)

	data = _get_temperature_data(_delete_tools)
	if isinstance(data, Response):
		return data
	else:
		return jsonify(data)
예제 #9
0
def printerBedState():
    if not printer.is_operational():
        abort(409, description="Printer is not operational")

    if not printerProfileManager.get_current_or_default()["heatedBed"]:
        abort(409, description="Printer does not have a heated bed")

    data = _get_temperature_data(_keep_bed)
    if isinstance(data, Response):
        return data
    else:
        return jsonify(data)
예제 #10
0
def printerChamberCommand():
	if not printer.is_operational():
		return make_response("Printer is not operational", 409)

	if not printerProfileManager.get_current_or_default()["heatedChamber"]:
		return make_response("Printer does not have a heated chamber", 409)

	valid_commands = {
		"target": ["target"],
		"offset": ["offset"]
	}
	command, data, response = get_json_command_from_request(request, valid_commands)
	if response is not None:
		return response

	tags = {"source:api", "api:printer.chamber"}

	##~~ temperature
	if command == "target":
		target = data["target"]

		# make sure the target is a number
		if not isinstance(target, (int, long, float)):
			return make_response("Not a number: %r" % target, 400)

		# perform the actual temperature command
		printer.set_temperature("chamber", target, tags=tags)

	##~~ temperature offset
	elif command == "offset":
		offset = data["offset"]

		# make sure the offset is valid
		if not isinstance(offset, (int, long, float)):
			return make_response("Not a number: %r" % offset, 400)
		if not -50 <= offset <= 50:
			return make_response("Offset not in range [-50, 50]: %f" % offset, 400)

		# set the offsets
		printer.set_temperature_offset({"chamber": offset})

	return NO_CONTENT
예제 #11
0
def printerBedCommand():
    if not printer.is_operational():
        abort(409, description="Printer is not operational")

    if not printerProfileManager.get_current_or_default()["heatedBed"]:
        abort(409, description="Printer does not have a heated bed")

    valid_commands = {"target": ["target"], "offset": ["offset"]}
    command, data, response = get_json_command_from_request(request, valid_commands)
    if response is not None:
        return response

    tags = {"source:api", "api:printer.bed"}

    ##~~ temperature
    if command == "target":
        target = data["target"]

        # make sure the target is a number
        if not isinstance(target, (int, long, float)):
            abort(400, description="target is invalid")

        # perform the actual temperature command
        printer.set_temperature("bed", target, tags=tags)

    ##~~ temperature offset
    elif command == "offset":
        offset = data["offset"]

        # make sure the offset is valid
        if not isinstance(offset, (int, long, float)) or not -50 <= offset <= 50:
            abort(400, description="offset is invalid")

        # set the offsets
        printer.set_temperature_offset({"bed": offset})

    return NO_CONTENT
예제 #12
0
def printerProfilesDelete(identifier):
	if printerProfileManager.get_current_or_default()["id"] == identifier:
		return make_response("Cannot delete currently selected profile: %s" % identifier, 409)
	printerProfileManager.remove(identifier)
	return NO_CONTENT
예제 #13
0
def printerProfilesDelete(identifier):
	if printerProfileManager.get_current_or_default()["id"] == identifier:
		return make_response("Cannot delete currently selected profile: %s" % identifier, 409)
	printerProfileManager.remove(identifier)
	return NO_CONTENT