Example #1
0
def _getFileList(origin):
	if origin == FileDestinations.SDCARD:
		sdFileList = printer.getSdFiles()

		files = []
		if sdFileList is not None:
			for sdFile, sdSize in sdFileList:
				file = {
					"name": sdFile,
					"origin": FileDestinations.SDCARD,
					"refs": {
						"resource": url_for(".readGcodeFile", target=FileDestinations.SDCARD, filename=sdFile, _external=True)
					}
				}
				if sdSize is not None:
					file.update({"size": sdSize})
				files.append(file)
	else:
		files = gcodeManager.getAllFileData()
		for file in files:
			file.update({
				"refs": {
					"resource": url_for(".readGcodeFile", target=FileDestinations.LOCAL, filename=file["name"], _external=True),
					"download": url_for("index", _external=True) + "downloads/files/" + FileDestinations.LOCAL + "/" + file["name"]
				}
			})
	return files
Example #2
0
def _getFileList(origin):
    if origin == FileDestinations.SDCARD:
        sdFileList = printer.getSdFiles()

        files = []
        if sdFileList is not None:
            for sdFile in sdFileList:
                files.append({
                    "name": sdFile,
                    "origin": FileDestinations.SDCARD,
                    "refs": {
                        "resource":
                        url_for(".readGcodeFile",
                                target=FileDestinations.SDCARD,
                                filename=sdFile,
                                _external=True)
                    }
                })
    else:
        files = gcodeManager.getAllFileData()
        for file in files:
            file.update({
                "refs": {
                    "resource":
                    url_for(".readGcodeFile",
                            target=FileDestinations.LOCAL,
                            filename=file["name"],
                            _external=True),
                    "download":
                    url_for("index", _external=True) + "downloads/files/" +
                    FileDestinations.LOCAL + "/" + file["name"]
                }
            })
    return files
Example #3
0
def designs():
	slicer = astroprintCloud()
	forceSyncCloud = request.args.get('forceSyncCloud')
	cloud_files = json.loads(slicer.print_files(forceSyncCloud))

	local_files = list(gcodeManager.getAllFileData())

	if cloud_files:
		for p in cloud_files:
			p['local_filename'] = None
			for i in range(len(local_files)):
				if "cloud_id" in local_files[i] and p['id'] == local_files[i]['cloud_id']:
					local_file = local_files[i]
					p['local_filename'] = local_file['name']
					p['local_only'] = False
					del local_files[i]
					break

		sorted_cloud_files = sorted(cloud_files, key=lambda e: e['local_filename'] is None)
	else:
		sorted_cloud_files = []

	if local_files:
		for p in local_files:
			p['id'] = uuid.uuid4().hex
			p['local_filename'] = p['name']
			p['local_only'] = True
			p['info'] = p['gcodeAnalysis']
			del p['gcodeAnalysis']

	return json.dumps(local_files + sorted_cloud_files)
Example #4
0
def designs():
	slicer = astroprintCloud()
	forceSyncCloud = request.args.get('forceSyncCloud')
	cloud_files = json.loads(slicer.print_files(forceSyncCloud))
	local_files = list(gcodeManager.getAllFileData())

	if cloud_files:
		for p in cloud_files:
			p['local_filename'] = None
			p['last_print'] = None
			for i in range(len(local_files)):
				if "cloud_id" in local_files[i] and p['id'] == local_files[i]['cloud_id']:
					local_file = local_files[i]
					p['local_filename'] = local_file['name']
					p['local_only'] = False
					
					if 'prints' in local_file \
						and 'last' in local_file['prints'] \
						and local_file['prints']['last'] \
						and 'date' in local_file['prints']['last']:
						p['last_print'] = local_file['prints']['last']['date']

					del local_files[i]

					break

		cloud_files = sorted(cloud_files, key=lambda e: e['local_filename'] is None)

	else:
		cloud_files = []

	if local_files:
		for p in local_files:
			p['id'] = uuid.uuid4().hex
			p['local_filename'] = p['name']
			p['local_only'] = True
			p['last_print'] = None
			if 'gcodeAnalysis' in p:
				p['info'] = p['gcodeAnalysis']
				del p['gcodeAnalysis']
			else:
				p['info'] = None

			if 'prints' in p \
				and 'last' in p['prints'] \
				and p['prints']['last'] \
				and 'date' in p['prints']['last']:
				p['last_print'] = p['prints']['last']['date']
				del p['prints']

	else:
		local_files = []

	files = sorted(local_files + cloud_files, key=lambda e: e['last_print'], reverse=True)

	return json.dumps(files)
Example #5
0
def readGcodeFiles():
    files = gcodeManager.getAllFileData()

    sdFileList = printer.getSdFiles()
    if sdFileList is not None:
        for sdFile in sdFileList:
            files.append({
                "name": sdFile,
                "size": "n/a",
                "bytes": 0,
                "date": "n/a",
                "origin": "sd"
            })
    return jsonify(files=files, free=util.getFormattedSize(util.getFreeBytes(settings.getpath("uploads"))))
Example #6
0
def readGcodeFiles():
    files = gcodeManager.getAllFileData()

    sdFileList = printer.getSdFiles()
    if sdFileList is not None:
        for sdFile in sdFileList:
            files.append({
                "name": sdFile,
                "size": "n/a",
                "bytes": 0,
                "date": "n/a",
                "origin": "sd"
            })
    return jsonify(files=files,
                   free=util.getFormattedSize(
                       util.getFreeBytes(settings().getBaseFolder("uploads"))))
Example #7
0
def _getFileList(target):
	if target == FileDestinations.SDCARD:
		sdFileList = printer.getSdFiles()

		files = []
		if sdFileList is not None:
			for sdFile in sdFileList:
				files.append({
					"name": sdFile,
					"size": "n/a",
					"bytes": 0,
					"date": "n/a",
					"origin": FileDestinations.SDCARD
				})
	else:
		files = gcodeManager.getAllFileData()
	return files
Example #8
0
def uploadGcodeFile(target):
    if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
        return make_response("Invalid target: %s" % target, 400)

    if "gcode_file" in request.files.keys():
        file = request.files["gcode_file"]
        sd = target == FileDestinations.SDCARD
        selectAfterUpload = "select" in request.values.keys(
        ) and request.values["select"] in valid_boolean_trues
        printAfterSelect = "print" in request.values.keys(
        ) and request.values["print"] in valid_boolean_trues

        # determine current job
        currentFilename = None
        currentSd = None
        currentJob = printer.getCurrentJob()
        if currentJob is not None and "filename" in currentJob.keys() and "sd" in currentJob.keys():
            currentFilename = currentJob["filename"]
            currentSd = currentJob["sd"]

        # determine future filename of file to be uploaded, abort if it can't
        # be uploaded
        futureFilename = gcodeManager.getFutureFilename(file)
        if futureFilename is None or (not settings.get("cura", "enabled") and not gcodefiles.isGcodeFileName(futureFilename)):
            return make_response("Can not upload file %s, wrong format?" % file.filename, 400)

        # prohibit overwriting currently selected file while it's being printed
        if futureFilename == currentFilename and sd == currentSd and printer.isPrinting() or printer.isPaused():
            return make_response("Trying to overwrite file that is currently being printed: %s" % currentFilename, 403)

        filename = None

        def fileProcessingFinished(filename, absFilename, destination):
            """
            Callback for when the file processing (upload, optional slicing, addition to analysis queue) has
            finished.

            Depending on the file's destination triggers either streaming to SD card or directly calls selectOrPrint.
            """
            sd = destination == FileDestinations.SDCARD
            if sd:
                printer.addSdFile(filename, absFilename, selectAndOrPrint)
            else:
                selectAndOrPrint(absFilename, destination)

        def selectAndOrPrint(nameToSelect, destination):
            """
            Callback for when the file is ready to be selected and optionally printed. For SD file uploads this only
            the case after they have finished streaming to the printer, which is why this callback is also used
            for the corresponding call to addSdFile.

            Selects the just uploaded file if either selectAfterUpload or printAfterSelect are True, or if the
            exact file is already selected, such reloading it.
            """
            sd = destination == FileDestinations.SDCARD
            if selectAfterUpload or printAfterSelect or (currentFilename == filename and currentSd == sd):
                printer.selectFile(nameToSelect, sd, printAfterSelect)

        destination = FileDestinations.SDCARD if sd else FileDestinations.LOCAL
        filename, done = gcodeManager.addFile(
            file, destination, fileProcessingFinished)
        if filename is None:
            return make_response("Could not upload the file %s" % file.filename, 500)

        eventManager.fire("Upload", filename)
        return jsonify(files=gcodeManager.getAllFileData(), filename=filename, done=done)
    else:
        return make_response("No gcode_file included", 400)
Example #9
0
def uploadGcodeFile(target):
    if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
        return make_response("Invalid target: %s" % target, 400)

    if "gcode_file" in request.files.keys():
        file = request.files["gcode_file"]
        sd = target == FileDestinations.SDCARD
        selectAfterUpload = "select" in request.values.keys(
        ) and request.values["select"] in valid_boolean_trues
        printAfterSelect = "print" in request.values.keys(
        ) and request.values["print"] in valid_boolean_trues

        # determine current job
        currentFilename = None
        currentSd = None
        currentJob = printer.getCurrentJob()
        if currentJob is not None and "filename" in currentJob.keys(
        ) and "sd" in currentJob.keys():
            currentFilename = currentJob["filename"]
            currentSd = currentJob["sd"]

        # determine future filename of file to be uploaded, abort if it can't be uploaded
        futureFilename = gcodeManager.getFutureFilename(file)
        if futureFilename is None or (
                not settings().getBoolean(["cura", "enabled"])
                and not gcodefiles.isGcodeFileName(futureFilename)):
            return make_response(
                "Can not upload file %s, wrong format?" % file.filename, 400)

        # prohibit overwriting currently selected file while it's being printed
        if futureFilename == currentFilename and sd == currentSd and printer.isPrinting(
        ) or printer.isPaused():
            return make_response(
                "Trying to overwrite file that is currently being printed: %s"
                % currentFilename, 403)

        filename = None

        def fileProcessingFinished(filename, absFilename, destination):
            """
			Callback for when the file processing (upload, optional slicing, addition to analysis queue) has
			finished.

			Depending on the file's destination triggers either streaming to SD card or directly calls selectOrPrint.
			"""
            sd = destination == FileDestinations.SDCARD
            if sd:
                printer.addSdFile(filename, absFilename, selectAndOrPrint)
            else:
                selectAndOrPrint(absFilename, destination)

        def selectAndOrPrint(nameToSelect, destination):
            """
			Callback for when the file is ready to be selected and optionally printed. For SD file uploads this only
			the case after they have finished streaming to the printer, which is why this callback is also used
			for the corresponding call to addSdFile.

			Selects the just uploaded file if either selectAfterUpload or printAfterSelect are True, or if the
			exact file is already selected, such reloading it.
			"""
            sd = destination == FileDestinations.SDCARD
            if selectAfterUpload or printAfterSelect or (
                    currentFilename == filename and currentSd == sd):
                printer.selectFile(nameToSelect, sd, printAfterSelect)

        destination = FileDestinations.SDCARD if sd else FileDestinations.LOCAL
        filename, done = gcodeManager.addFile(file, destination,
                                              fileProcessingFinished)
        if filename is None:
            return make_response(
                "Could not upload the file %s" % file.filename, 500)

        eventManager.fire("Upload", filename)
        return jsonify(files=gcodeManager.getAllFileData(),
                       filename=filename,
                       done=done)
    else:
        return make_response("No gcode_file included", 400)