2013-10-28 21:08:36 +00:00
|
|
|
# coding=utf-8
|
2014-08-05 09:26:13 +00:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
2013-10-28 21:08:36 +00:00
|
|
|
__author__ = "Gina Häußge <osd@foosel.net>"
|
|
|
|
|
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
2014-08-05 09:26:13 +00:00
|
|
|
__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
2013-10-28 21:08:36 +00:00
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
from flask import request, jsonify, url_for
|
|
|
|
|
from werkzeug.utils import secure_filename
|
|
|
|
|
|
|
|
|
|
import octoprint.timelapse
|
|
|
|
|
import octoprint.util as util
|
|
|
|
|
from octoprint.settings import settings, valid_boolean_trues
|
|
|
|
|
|
2014-08-05 09:26:13 +00:00
|
|
|
from octoprint.server import admin_permission
|
|
|
|
|
from octoprint.server.util.flask import redirect_to_tornado, restricted_access
|
2013-12-21 13:46:20 +00:00
|
|
|
from octoprint.server.api import api
|
2013-10-28 21:08:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#~~ timelapse handling
|
|
|
|
|
|
|
|
|
|
|
2013-12-21 13:46:20 +00:00
|
|
|
@api.route("/timelapse", methods=["GET"])
|
2013-10-28 21:08:36 +00:00
|
|
|
def getTimelapseData():
|
|
|
|
|
timelapse = octoprint.timelapse.current
|
|
|
|
|
|
2013-12-21 13:46:20 +00:00
|
|
|
config = {"type": "off"}
|
2013-10-28 21:08:36 +00:00
|
|
|
if timelapse is not None and isinstance(timelapse, octoprint.timelapse.ZTimelapse):
|
2013-12-21 13:46:20 +00:00
|
|
|
config["type"] = "zchange"
|
2014-03-05 19:52:25 +00:00
|
|
|
config["postRoll"] = timelapse.postRoll()
|
2013-10-28 21:08:36 +00:00
|
|
|
elif timelapse is not None and isinstance(timelapse, octoprint.timelapse.TimedTimelapse):
|
2013-12-21 13:46:20 +00:00
|
|
|
config["type"] = "timed"
|
2014-03-05 19:52:25 +00:00
|
|
|
config["postRoll"] = timelapse.postRoll()
|
2013-12-21 13:46:20 +00:00
|
|
|
config.update({
|
2013-10-28 21:08:36 +00:00
|
|
|
"interval": timelapse.interval()
|
2013-12-21 13:46:20 +00:00
|
|
|
})
|
2013-10-28 21:08:36 +00:00
|
|
|
|
|
|
|
|
files = octoprint.timelapse.getFinishedTimelapses()
|
|
|
|
|
for file in files:
|
|
|
|
|
file["url"] = url_for("index") + "downloads/timelapse/" + file["name"]
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
2013-12-21 13:46:20 +00:00
|
|
|
"config": config,
|
2013-10-28 21:08:36 +00:00
|
|
|
"files": files
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2013-12-21 13:46:20 +00:00
|
|
|
@api.route("/timelapse/<filename>", methods=["GET"])
|
2013-10-28 21:08:36 +00:00
|
|
|
def downloadTimelapse(filename):
|
2014-08-05 09:26:13 +00:00
|
|
|
return redirect_to_tornado(request, url_for("index") + "downloads/timelapse/" + filename)
|
2013-10-28 21:08:36 +00:00
|
|
|
|
|
|
|
|
|
2013-12-21 13:46:20 +00:00
|
|
|
@api.route("/timelapse/<filename>", methods=["DELETE"])
|
2013-10-28 21:08:36 +00:00
|
|
|
@restricted_access
|
|
|
|
|
def deleteTimelapse(filename):
|
|
|
|
|
if util.isAllowedFile(filename, {"mpg"}):
|
2015-01-19 11:34:25 +00:00
|
|
|
timelapse_folder = settings().getBaseFolder("timelapse")
|
|
|
|
|
full_path = os.path.realpath(os.path.join(timelapse_folder, filename))
|
|
|
|
|
if full_path.startswith(timelapse_folder) and os.path.exists(full_path):
|
|
|
|
|
os.remove(full_path)
|
2013-10-28 21:08:36 +00:00
|
|
|
return getTimelapseData()
|
|
|
|
|
|
|
|
|
|
|
2013-12-21 13:46:20 +00:00
|
|
|
@api.route("/timelapse", methods=["POST"])
|
2013-10-28 21:08:36 +00:00
|
|
|
@restricted_access
|
|
|
|
|
def setTimelapseConfig():
|
|
|
|
|
if "type" in request.values:
|
|
|
|
|
config = {
|
|
|
|
|
"type": request.values["type"],
|
2014-03-05 19:52:25 +00:00
|
|
|
"postRoll": 0,
|
2013-10-28 21:08:36 +00:00
|
|
|
"options": {}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-05 19:52:25 +00:00
|
|
|
|
|
|
|
|
if "postRoll" in request.values:
|
|
|
|
|
try:
|
|
|
|
|
config["postRoll"] = int(request.values["postRoll"])
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
|
|
|
|
|
2013-10-28 21:08:36 +00:00
|
|
|
if "interval" in request.values:
|
|
|
|
|
interval = 10
|
|
|
|
|
try:
|
|
|
|
|
interval = int(request.values["interval"])
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
config["options"] = {
|
|
|
|
|
"interval": interval
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if admin_permission.can() and "save" in request.values and request.values["save"] in valid_boolean_trues:
|
|
|
|
|
octoprint.timelapse.configureTimelapse(config, True)
|
|
|
|
|
else:
|
|
|
|
|
octoprint.timelapse.configureTimelapse(config)
|
|
|
|
|
|
|
|
|
|
return getTimelapseData()
|
|
|
|
|
|