Compare commits

..
11 Commits
27 changed files with 1322 additions and 266 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
1.1.0-dev
+177
View File
@@ -0,0 +1,177 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
endif
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/OctoPrint.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/OctoPrint.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/OctoPrint"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/OctoPrint"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
xml:
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
pseudoxml:
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
+248
View File
@@ -0,0 +1,248 @@
# -*- coding: utf-8 -*-
#
# OctoPrint documentation build configuration file, created by
# sphinx-quickstart on Mon Dec 02 17:08:50 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.todo']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'OctoPrint'
copyright = u'2013, Gina Häußge'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = open("../VERSION").read().strip()
# The full version, including alpha/beta/rc tags.
release = version
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'OctoPrintdoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'OctoPrint.tex', u'OctoPrint Documentation',
u'Gina Häußge', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'octoprint', u'OctoPrint Documentation',
[u'Gina Häußge'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'OctoPrint', u'OctoPrint Documentation',
u'Gina Häußge', 'OctoPrint', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False
+22
View File
@@ -0,0 +1,22 @@
.. OctoPrint documentation master file, created by
sphinx-quickstart on Mon Dec 02 17:08:50 2013.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to OctoPrint's documentation!
=====================================
Contents:
.. toctree::
:maxdepth: 2
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
+242
View File
@@ -0,0 +1,242 @@
@ECHO OFF
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set BUILDDIR=_build
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
set I18NSPHINXOPTS=%SPHINXOPTS% .
if NOT "%PAPER%" == "" (
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
)
if "%1" == "" goto help
if "%1" == "help" (
:help
echo.Please use `make ^<target^>` where ^<target^> is one of
echo. html to make standalone HTML files
echo. dirhtml to make HTML files named index.html in directories
echo. singlehtml to make a single large HTML file
echo. pickle to make pickle files
echo. json to make JSON files
echo. htmlhelp to make HTML files and a HTML help project
echo. qthelp to make HTML files and a qthelp project
echo. devhelp to make HTML files and a Devhelp project
echo. epub to make an epub
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
echo. text to make text files
echo. man to make manual pages
echo. texinfo to make Texinfo files
echo. gettext to make PO message catalogs
echo. changes to make an overview over all changed/added/deprecated items
echo. xml to make Docutils-native XML files
echo. pseudoxml to make pseudoxml-XML files for display purposes
echo. linkcheck to check all external links for integrity
echo. doctest to run all doctests embedded in the documentation if enabled
goto end
)
if "%1" == "clean" (
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
del /q /s %BUILDDIR%\*
goto end
)
%SPHINXBUILD% 2> nul
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
if "%1" == "html" (
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
goto end
)
if "%1" == "dirhtml" (
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
goto end
)
if "%1" == "singlehtml" (
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
goto end
)
if "%1" == "pickle" (
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the pickle files.
goto end
)
if "%1" == "json" (
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the JSON files.
goto end
)
if "%1" == "htmlhelp" (
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run HTML Help Workshop with the ^
.hhp project file in %BUILDDIR%/htmlhelp.
goto end
)
if "%1" == "qthelp" (
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run "qcollectiongenerator" with the ^
.qhcp project file in %BUILDDIR%/qthelp, like this:
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\OctoPrint.qhcp
echo.To view the help file:
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\OctoPrint.ghc
goto end
)
if "%1" == "devhelp" (
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished.
goto end
)
if "%1" == "epub" (
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The epub file is in %BUILDDIR%/epub.
goto end
)
if "%1" == "latex" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
if errorlevel 1 exit /b 1
echo.
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "latexpdf" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
cd %BUILDDIR%/latex
make all-pdf
cd %BUILDDIR%/..
echo.
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "latexpdfja" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
cd %BUILDDIR%/latex
make all-pdf-ja
cd %BUILDDIR%/..
echo.
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "text" (
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The text files are in %BUILDDIR%/text.
goto end
)
if "%1" == "man" (
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The manual pages are in %BUILDDIR%/man.
goto end
)
if "%1" == "texinfo" (
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
goto end
)
if "%1" == "gettext" (
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
goto end
)
if "%1" == "changes" (
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
if errorlevel 1 exit /b 1
echo.
echo.The overview file is in %BUILDDIR%/changes.
goto end
)
if "%1" == "linkcheck" (
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
if errorlevel 1 exit /b 1
echo.
echo.Link check complete; look for any errors in the above output ^
or in %BUILDDIR%/linkcheck/output.txt.
goto end
)
if "%1" == "doctest" (
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
if errorlevel 1 exit /b 1
echo.
echo.Testing of doctests in the sources finished, look at the ^
results in %BUILDDIR%/doctest/output.txt.
goto end
)
if "%1" == "xml" (
%SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The XML files are in %BUILDDIR%/xml.
goto end
)
if "%1" == "pseudoxml" (
%SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
goto end
)
:end
+1 -1
View File
@@ -3,7 +3,7 @@
from setuptools import setup, find_packages
VERSION = "1.0.0-rc2"
VERSION = open("VERSION").read().strip()
def params():
name = "OctoPrint"
+1 -5
View File
@@ -14,7 +14,6 @@ import octoprint.util.gcodeInterpreter as gcodeInterpreter
from octoprint.settings import settings
from octoprint.events import eventManager
from octoprint.filemanager.destinations import FileDestinations
from werkzeug.utils import secure_filename
@@ -196,7 +195,6 @@ class GcodeManager:
self.processStl(absolutePath, destination, uploadCallback)
return filename, False
def getFutureFileName(self, file):
if not file:
return None
@@ -207,7 +205,6 @@ class GcodeManager:
return self._getBasicFilename(absolutePath)
def processStl(self, absolutePath, destination, uploadCallback=None):
from octoprint.slicers.cura import CuraFactory
@@ -230,7 +227,6 @@ class GcodeManager:
eventManager().fire("SlicingStarted", {"stl": self._getBasicFilename(absolutePath), "gcode": self._getBasicFilename(gcodePath)})
cura.process_file(config, gcodePath, absolutePath, stlProcessed, [absolutePath, gcodePath])
def processGcode(self, absolutePath, destination, uploadCallback=None):
if absolutePath is None:
return None
@@ -247,7 +243,7 @@ class GcodeManager:
if uploadCallback is not None:
uploadCallback(filename, absolutePath, destination)
return filename
return filename
def getFutureFilename(self, file):
if not file:
+8 -3
View File
@@ -9,8 +9,6 @@ import copy
import os
import logging
#import logging, logging.config
import octoprint.util.comm as comm
import octoprint.util as util
@@ -459,7 +457,7 @@ class Printer():
self._setProgressData(0.0, 0, 0, None)
self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()})
def mcFileTransferDone(self):
def mcFileTransferDone(self, filename):
self._sdStreaming = False
if self._streamingFinishedCallback is not None:
@@ -560,6 +558,13 @@ class Printer():
}
}
def getCurrentConnection(self):
if self._comm is None:
return "Closed", None, None
port, baudrate = self._comm.getConnection()
return self._comm.getStateString(), port, baudrate
def isClosedOrError(self):
return self._comm is None or self._comm.isClosedOrError()
+183 -101
View File
@@ -2,148 +2,196 @@
__author__ = "Gina Häußge <osd@foosel.net>"
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
from flask import request, jsonify
from flask import request, jsonify, make_response
from octoprint.settings import settings
from octoprint.settings import settings, valid_boolean_trues
from octoprint.printer import getConnectionOptions
from octoprint.server import printer, restricted_access, SUCCESS
from octoprint.server.ajax import ajax
import octoprint.util as util
#~~ Printer control
@ajax.route("/control/connection/options", methods=["GET"])
@ajax.route("/control/connection", methods=["GET"])
def connectionOptions():
return jsonify(getConnectionOptions())
state, port, baudrate = printer.getCurrentConnection()
current = {
"state": state,
"port": port,
"baudrate": baudrate
}
return jsonify({"current": current, "options": getConnectionOptions()})
@ajax.route("/control/connection", methods=["POST"])
@restricted_access
def connect():
if "command" in request.values.keys() and request.values["command"] == "connect":
def connectionCommand():
valid_commands = {
"connect": ["autoconnect"],
"disconnect": []
}
command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
if response is not None:
return response
if command == "connect":
options = getConnectionOptions()
port = None
baudrate = None
if "port" in request.values.keys():
port = request.values["port"]
if "baudrate" in request.values.keys():
baudrate = request.values["baudrate"]
if "save" in request.values.keys():
if "port" in data.keys():
port = data["port"]
if port not in options["ports"]:
return make_response("Invalid port: %s" % port, 400)
if "baudrate" in data.keys():
baudrate = data["baudrate"]
if baudrate not in options["baudrates"]:
return make_response("Invalid baudrate: %d" % baudrate, 400)
if "save" in data.keys() and data["save"]:
settings().set(["serial", "port"], port)
settings().setInt(["serial", "baudrate"], baudrate)
settings().save()
if "autoconnect" in request.values.keys():
settings().setBoolean(["serial", "autoconnect"], True)
settings().save()
settings().setBoolean(["serial", "autoconnect"], data["autoconnect"])
settings().save()
printer.connect(port=port, baudrate=baudrate)
elif "command" in request.values.keys() and request.values["command"] == "disconnect":
elif command == "disconnect":
printer.disconnect()
return jsonify(SUCCESS)
@ajax.route("/control/command", methods=["POST"])
@ajax.route("/control/printer/command", methods=["POST"])
@restricted_access
def printerCommand():
if "application/json" in request.headers["Content-Type"]:
data = request.json
if not printer.isOperational():
return make_response("Printer is not operational", 403)
parameters = {}
if "parameters" in data.keys(): parameters = data["parameters"]
if not "application/json" in request.headers["Content-Type"]:
return make_response("Expected content type JSON", 400)
commands = []
if "command" in data.keys(): commands = [data["command"]]
elif "commands" in data.keys(): commands = data["commands"]
data = request.json
commandsToSend = []
for command in commands:
commandToSend = command
if len(parameters) > 0:
commandToSend = command % parameters
commandsToSend.append(commandToSend)
parameters = {}
if "parameters" in data.keys(): parameters = data["parameters"]
printer.commands(commandsToSend)
commands = []
if "command" in data.keys(): commands = [data["command"]]
elif "commands" in data.keys(): commands = data["commands"]
commandsToSend = []
for command in commands:
commandToSend = command
if len(parameters) > 0:
commandToSend = command % parameters
commandsToSend.append(commandToSend)
printer.commands(commandsToSend)
return jsonify(SUCCESS)
@ajax.route("/control/job", methods=["POST"])
@restricted_access
def printJobControl():
if "command" in request.values.keys():
if request.values["command"] == "start":
printer.startPrint()
elif request.values["command"] == "pause":
printer.togglePausePrint()
elif request.values["command"] == "cancel":
printer.cancelPrint()
def controlJob():
if not printer.isOperational():
return make_response("Printer is not operational", 403)
valid_commands = {
"start": [],
"pause": [],
"cancel": []
}
command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
if response is not None:
return response
if command == "start":
printer.startPrint()
elif command == "pause":
printer.togglePausePrint()
elif command == "cancel":
printer.cancelPrint()
return jsonify(SUCCESS)
@ajax.route("/control/temperature", methods=["POST"])
@ajax.route("/control/printer/hotend", methods=["POST"])
@restricted_access
def setTargetTemperature():
if "temp" in request.values.keys():
# set target temperature
temp = request.values["temp"]
printer.command("M104 S" + temp)
def controlPrinterHotend():
if not printer.isOperational():
return make_response("Printer is not operational", 403)
if "bedTemp" in request.values.keys():
# set target bed temperature
bedTemp = request.values["bedTemp"]
printer.command("M140 S" + bedTemp)
valid_commands = {
"temp": ["temps"],
"offset": ["offsets"]
}
command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
if response is not None:
return response
if "tempOffset" in request.values.keys():
# set target temperature offset
try:
tempOffset = float(request.values["tempOffset"])
if tempOffset >= -50 and tempOffset <= 50:
printer.setTemperatureOffset(tempOffset, None)
except:
pass
valid_targets = ["hotend", "bed"]
if "bedTempOffset" in request.values.keys():
# set target bed temperature offset
try:
bedTempOffset = float(request.values["bedTempOffset"])
if bedTempOffset >= -50 and bedTempOffset <= 50:
printer.setTemperatureOffset(None, bedTempOffset)
except:
pass
##~~ temperature
if command == "temp":
temps = data["temps"]
# make sure the targets are valid and the values are numbers
validated_values = {}
for type, value in temps.iteritems():
if not type in valid_targets:
return make_response("Invalid target for setting temperature: %s" % type, 400)
if not isinstance(value, (int, long, float)):
return make_response("Not a number for %s: %r" % (type, value), 400)
validated_values[type] = value
# perform the actual temperature commands
# TODO make this a generic method call (printer.setTemperature(type, value)) to get rid of gcode here
if "hotend" in validated_values:
printer.command("M104 S%f" % validated_values["hotend"])
if "bed" in validated_values:
printer.command("M140 S%f" % validated_values["bed"])
##~~ temperature offset
elif command == "offset":
offsets = data["offsets"]
# make sure the targets are valid, the values are numbers and in the range [-50, 50]
validated_values = {}
for type, value in offsets.iteritems():
if not type in valid_targets:
return make_response("Invalid target for setting temperature: %s" % type, 400)
if not isinstance(value, (int, long, float)):
return make_response("Not a number for %s: %r" % (type, value), 400)
if not -50 <= value <= 50:
return make_response("Offset %s not in range [-50, 50]: %f" % (type, value), 400)
validated_values[type] = value
# set the offsets
if "hotend" in validated_values and "bed" in validated_values:
printer.setTemperatureOffset(validated_values["hotend"], validated_values["bed"])
elif "hotend" in validated_values:
printer.setTemperatureOffset(validated_values["hotend"], None)
elif "bed" in validated_values:
printer.setTemperatureOffset(None, validated_values["bed"])
return jsonify(SUCCESS)
@ajax.route("/control/jog", methods=["POST"])
@ajax.route("/control/printer/printhead", methods=["POST"])
@restricted_access
def jog():
def controlPrinterPrinthead():
if not printer.isOperational() or printer.isPrinting():
# do not jog when a print job is running or we don't have a connection
return jsonify(SUCCESS)
return make_response("Printer is not operational or currently printing", 403)
(movementSpeedX, movementSpeedY, movementSpeedZ, movementSpeedE) = settings().get(["printerParameters", "movementSpeed", ["x", "y", "z", "e"]])
if "x" in request.values.keys():
# jog x
x = request.values["x"]
printer.commands(["G91", "G1 X%s F%d" % (x, movementSpeedX), "G90"])
if "y" in request.values.keys():
# jog y
y = request.values["y"]
printer.commands(["G91", "G1 Y%s F%d" % (y, movementSpeedY), "G90"])
if "z" in request.values.keys():
# jog z
z = request.values["z"]
printer.commands(["G91", "G1 Z%s F%d" % (z, movementSpeedZ), "G90"])
if "homeXY" in request.values.keys():
# home x/y
printer.command("G28 X0 Y0")
if "homeZ" in request.values.keys():
# home z
printer.command("G28 Z0")
if "extrude" in request.values.keys():
# extrude/retract
length = request.values["extrude"]
printer.commands(["G91", "G1 E%s F%d" % (length, movementSpeedE), "G90"])
valid_commands = {
"jog": [],
"home": ["axes"]
}
command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
if response is not None:
return response
movementSpeed = settings().get(["printerParameters", "movementSpeed", ["x", "y", "z"]], asdict=True)
@@ -180,6 +228,33 @@ def jog():
return jsonify(SUCCESS)
@ajax.route("/control/printer/feeder", methods=["POST"])
@restricted_access
def controlPrinterFeeder():
if not printer.isOperational() or printer.isPrinting():
# do not jog when a print job is running or we don't have a connection
return make_response("Printer is not operational or currently printing", 403)
valid_commands = {
"extrude": ["amount"]
}
command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
if response is not None:
return response
extrusionSpeed = settings().get(["printerParameters", "movementSpeed", "e"])
if command == "extrude":
amount = data["amount"]
if not isinstance(amount, (int, long, float)):
return make_response("Not a number for extrusion amount: %r" % amount, 400)
# TODO make this a generic method call (printer.extruder([hotend,] amount)) to get rid of gcode here
printer.commands(["G91", "G1 E%s F%d" % (data["amount"], extrusionSpeed), "G90"])
return jsonify(SUCCESS)
@ajax.route("/control/custom", methods=["GET"])
def getCustomControls():
customControls = settings().get(["controls"])
@@ -190,16 +265,23 @@ def getCustomControls():
@restricted_access
def sdCommand():
if not settings().getBoolean(["feature", "sdSupport"]) or not printer.isOperational() or printer.isPrinting():
return jsonify(SUCCESS)
return make_response("SD support is disabled", 403)
if "command" in request.values.keys():
command = request.values["command"]
if command == "init":
printer.initSdCard()
elif command == "refresh":
printer.refreshSdFiles()
elif command == "release":
printer.releaseSdCard()
valid_commands = {
"init": [],
"refresh": [],
"release": []
}
command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
if response is not None:
return response
if command == "init":
printer.initSdCard()
elif command == "refresh":
printer.refreshSdFiles()
elif command == "release":
printer.releaseSdCard()
return jsonify(SUCCESS)
+85 -42
View File
@@ -18,21 +18,38 @@ from octoprint.server.ajax import ajax
@ajax.route("/gcodefiles", methods=["GET"])
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"
})
files = _getFileList(FileDestinations.LOCAL)
files.extend(_getFileList(FileDestinations.SDCARD))
return jsonify(files=files, free=util.getFormattedSize(util.getFreeBytes(settings().getBaseFolder("uploads"))))
@ajax.route("/gcodefiles/<string:target>", methods=["GET"])
def readGcodeFilesForTarget(target):
if target not in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
return make_response("Invalid target: %s" % target, 400)
return jsonify(files=_getFileList(target), free=util.getFormattedSize(util.getFreeBytes(settings().getBaseFolder("uploads"))))
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
@ajax.route("/gcodefiles/<string:target>", methods=["POST"])
@restricted_access
def uploadGcodeFile(target):
@@ -101,52 +118,78 @@ def uploadGcodeFile(target):
return make_response("No gcode_file included", 400)
@ajax.route("/gcodefiles/load", methods=["POST"])
@ajax.route("/gcodefiles/local/<path:filename>", methods=["GET"])
def readGcodeFile(filename):
return redirectToTornado(request, url_for("index") + "downloads/gcode/" + filename)
@ajax.route("/gcodefiles/<string:target>/<path:filename>", methods=["POST"])
@restricted_access
def loadGcodeFile():
if "filename" in request.values.keys():
def gcodeFileCommand(filename, target):
if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
return make_response("Invalid target: %s" % target, 400)
# valid file commands, dict mapping command name to mandatory parameters
valid_commands = {
"load": []
}
command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
if response is not None:
return response
if command == "load":
# selects/loads a file
printAfterLoading = False
if "print" in request.values.keys() and request.values["print"] in valid_boolean_trues:
if "print" in data.keys() and data["print"]:
printAfterLoading = True
sd = False
if "target" in request.values.keys() and request.values["target"] == "sd":
filename = request.values["filename"]
if target == FileDestinations.SDCARD:
filenameToSelect = filename
sd = True
else:
filename = gcodeManager.getAbsolutePath(request.values["filename"])
printer.selectFile(filename, sd, printAfterLoading)
return jsonify(SUCCESS)
filenameToSelect = gcodeManager.getAbsolutePath(filename)
printer.selectFile(filenameToSelect, sd, printAfterLoading)
return jsonify(SUCCESS)
return make_response("Command %s is currently not implemented" % command, 400)
@ajax.route("/gcodefiles/delete", methods=["POST"])
@ajax.route("/gcodefiles/<string:target>/<path:filename>", methods=["DELETE"])
@restricted_access
def deleteGcodeFile():
if "filename" in request.values.keys():
filename = request.values["filename"]
sd = "target" in request.values.keys() and request.values["target"] == "sd"
def deleteGcodeFile(filename, target):
if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
return make_response("Invalid target: %s" % target, 400)
currentJob = printer.getCurrentJob()
currentFilename = None
currentSd = None
if currentJob is not None and "filename" in currentJob.keys() and "sd" in currentJob.keys():
currentFilename = currentJob["filename"]
currentSd = currentJob["sd"]
sd = target == FileDestinations.SDCARD
if currentFilename is not None and filename == currentFilename and not (printer.isPrinting() or printer.isPaused()):
printer.unselectFile()
currentJob = printer.getCurrentJob()
currentFilename = None
currentSd = None
if currentJob is not None and "filename" in currentJob.keys() and "sd" in currentJob.keys():
currentFilename = currentJob["filename"]
currentSd = currentJob["sd"]
if not (currentFilename == filename and currentSd == sd and (printer.isPrinting() or printer.isPaused())):
if sd:
printer.deleteSdFile(filename)
else:
gcodeManager.removeFile(filename)
if currentFilename is not None and filename == currentFilename and not (printer.isPrinting() or printer.isPaused()):
printer.unselectFile()
if not (currentFilename == filename and currentSd == sd and (printer.isPrinting() or printer.isPaused())):
if sd:
printer.deleteSdFile(filename)
else:
gcodeManager.removeFile(filename)
return readGcodeFiles()
@ajax.route("/gcodefiles/refresh", methods=["POST"])
@ajax.route("/gcodefiles/<string:target>/refresh", methods=["POST"])
@restricted_access
def refreshFiles():
printer.updateSdFiles()
def refreshFiles(target):
if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
return make_response("Invalid target: %s" % target, 400)
if target == FileDestinations.SDCARD:
printer.updateSdFiles()
return jsonify(SUCCESS)
+31
View File
@@ -123,3 +123,34 @@ def changePasswordForUser(username):
else:
return make_response(("Forbidden", 403, []))
@ajax.route("/users/<username>/apikey", methods=["DELETE"])
@restricted_access
def deleteApikeyForUser(username):
if userManager is None:
return jsonify(SUCCESS)
if current_user is not None and not current_user.is_anonymous() and (current_user.get_name() == username or current_user.is_admin()):
try:
userManager.deleteApikey(username)
except users.UnknownUser:
return make_response(("Unknown user: %s" % username, 404, []))
return jsonify(SUCCESS)
else:
return make_response(("Forbidden", 403, []))
@ajax.route("/users/<username>/apikey", methods=["POST"])
@restricted_access
def generateApikeyForUser(username):
if userManager is None:
return jsonify(SUCCESS)
if current_user is not None and not current_user.is_anonymous() and (current_user.get_name() == username or current_user.is_admin()):
try:
apikey = userManager.generateApiKey(username)
except users.UnknownUser:
return make_response(("Unknown user: %s" % username, 404, []))
return jsonify({"apikey": apikey})
else:
return make_response(("Forbidden", 403, []))
+10 -24
View File
@@ -7,36 +7,30 @@ import logging
from flask import Blueprint, request, jsonify, abort
from octoprint.server import printer, gcodeManager, SUCCESS
from octoprint.settings import settings, valid_boolean_trues
from octoprint.server.util import api_access
from octoprint.settings import valid_boolean_trues
from octoprint.filemanager.destinations import FileDestinations
import octoprint.gcodefiles as gcodefiles
api = Blueprint("api", __name__)
#-- very simple api routines
@api.route("/load", methods=["POST"])
@api_access
def apiLoad():
logger = logging.getLogger(__name__)
if not settings().get(["api", "enabled"]):
abort(401)
if not "apikey" in request.values.keys():
abort(401)
if request.values["apikey"] != settings().get(["api", "key"]):
abort(403)
if not "file" in request.files.keys():
abort(400)
# Perform an upload
file = request.files["file"]
if not gcodefiles.isGcodeFileName(file.filename):
f = request.files["file"]
if not gcodefiles.isGcodeFileName(f.filename):
abort(400)
destination = FileDestinations.LOCAL
filename, done = gcodeManager.addFile(file, destination)
filename, done = gcodeManager.addFile(f, destination)
if filename is None:
logger.warn("Upload via API failed")
abort(500)
@@ -51,19 +45,11 @@ def apiLoad():
return jsonify(SUCCESS)
@api.route("/state", methods=["GET"])
@api_access
def apiPrinterState():
if not settings().get(["api", "enabled"]):
abort(401)
if not "apikey" in request.values.keys():
abort(401)
if request.values["apikey"] != settings().get(["api", "key"]):
abort(403)
currentData = printer.getCurrentData()
currentData.update({
"temperatures": printer.getCurrentTemperatures()
"temperatures": printer.getCurrentTemperatures()
})
return jsonify(currentData)
+47 -9
View File
@@ -1,7 +1,7 @@
from flask.ext.principal import identity_changed, Identity
from tornado.web import StaticFileHandler, HTTPError
from flask import url_for, make_response
from flask.ext.login import login_required
from flask import url_for, make_response, request, current_app
from flask.ext.login import login_required, login_user
from werkzeug.utils import redirect
from sockjs.tornado import SockJSConnection
@@ -15,32 +15,70 @@ import threading
import logging
from functools import wraps
from octoprint.server import userManager
from octoprint.settings import settings
import octoprint.timelapse
import octoprint.server
from octoprint.users import ApiUser
def restricted_access(func):
def restricted_access(func, apiEnabled=True):
"""
If you decorate a view with this, it will ensure that first setup has been
done for OctoPrint's Access Control plus that any conditions of the
login_required decorator are met.
login_required decorator are met. It also allows to login using the masterkey or any
of the user's apikeys if API access is enabled globally and for the decorated view.
If OctoPrint's Access Control has not been setup yet (indicated by the "firstRun"
flag from the settings being set to True and the userManager not indicating
that it's user database has been customized from default), the decorator
will cause a HTTP 403 status code to be returned by the decorated resource.
If an API key is provided and it matches a known key, the user will be logged in and
the view will be called directly. If the provided key doesn't match any known key,
a HTTP 403 status code will be returned by the decorated resource.
Otherwise the result of calling login_required will be returned.
"""
@wraps(func)
def decorated_view(*args, **kwargs):
if settings().getBoolean(["server", "firstRun"]) and (userManager is None or not userManager.hasBeenCustomized()):
# if OctoPrint hasn't been set up yet, abort
if settings().getBoolean(["server", "firstRun"]) and (octoprint.server.userManager is None or not octoprint.server.userManager.hasBeenCustomized()):
return make_response("OctoPrint isn't setup yet", 403)
# if API is globally enabled, enabled for this request and an api key is provided, try to use that
if settings().get(["api", "enabled"]) and apiEnabled and "apikey" in request.values.keys():
apikey = request.values["apikey"]
user = None
if apikey == settings().get(["api", "key"]):
# master key was used
user = ApiUser()
else:
# user key might have been used
user = octoprint.server.userManager.findUser(apikey=apikey)
if user is None:
make_response("Invalid API key", 403)
if login_user(user, remember=False):
identity_changed.send(current_app._get_current_object(), identity=Identity(user.get_id()))
return func(*args, **kwargs)
# call regular login_required decorator
return login_required(func)(*args, **kwargs)
return decorated_view
def api_access(func):
@wraps(func)
def decorated_view(*args, **kwargs):
if not settings().get(["api", "enabled"]):
make_response("API disabled", 401)
if not "apikey" in request.values.keys():
make_response("No API key provided", 401)
if request.values["apikey"] != settings().get(["api", "key"]):
make_response("Invalid API key", 403)
return func(args, kwargs)
return decorated_view
#~~ Printer state
@@ -286,7 +324,7 @@ class ReverseProxied(object):
def redirectToTornado(request, target):
requestUrl = request.url
appBaseUrl = requestUrl[:requestUrl.find(url_for("ajax.base"))]
appBaseUrl = requestUrl[:requestUrl.find(url_for("index") + "/ajax")]
redirectUrl = appBaseUrl + target
if "?" in requestUrl:
+17 -6
View File
@@ -187,7 +187,7 @@ class Settings(object):
#~~ getter
def get(self, path):
def get(self, path, asdict=False):
if len(path) == 0:
return None
@@ -211,17 +211,28 @@ class Settings(object):
else:
keys = k
results = []
if asdict:
results = {}
else:
results = []
for key in keys:
if key in config.keys():
results.append(config[key])
value = config[key]
elif key in defaults:
results.append(defaults[key])
value = defaults[key]
else:
results.append(None)
value = None
if asdict:
results[key] = value
else:
results.append(value)
if not isinstance(k, (list, tuple)):
return results.pop()
if asdict:
return results.values().pop()
else:
return results.pop()
else:
return results
+4
View File
@@ -19,6 +19,10 @@ function ItemListHelper(listType, supportedSorting, supportedFilters, defaultSor
//~~ item handling
self.refresh = function() {
self._updateItems();
}
self.updateItems = function(items) {
self.allItems = items;
self._updateItems();
@@ -9,6 +9,7 @@ function ConnectionViewModel(loginStateViewModel, settingsViewModel) {
self.selectedPort = ko.observable(undefined);
self.selectedBaudrate = ko.observable(undefined);
self.saveSettings = ko.observable(undefined);
self.autoconnect = ko.observable(undefined);
self.isErrorOrClosed = ko.observable(undefined);
self.isOperational = ko.observable(undefined);
@@ -29,7 +30,7 @@ function ConnectionViewModel(loginStateViewModel, settingsViewModel) {
self.requestData = function() {
$.ajax({
url: AJAX_BASEURL + "control/connection/options",
url: AJAX_BASEURL + "control/connection",
method: "GET",
dataType: "json",
success: function(response) {
@@ -39,13 +40,18 @@ function ConnectionViewModel(loginStateViewModel, settingsViewModel) {
}
self.fromResponse = function(response) {
self.portOptions(response.ports);
self.baudrateOptions(response.baudrates);
var ports = response.options.ports;
var baudrates = response.options.baudrates;
var portPreference = response.options.portPreference;
var baudratePreference = response.options.baudratePreference;
if (!self.selectedPort() && response.ports && response.ports.indexOf(response.portPreference) >= 0)
self.selectedPort(response.portPreference);
if (!self.selectedBaudrate() && response.baudrates && response.baudrates.indexOf(response.baudratePreference) >= 0)
self.selectedBaudrate(response.baudratePreference);
self.portOptions(ports);
self.baudrateOptions(baudrates);
if (!self.selectedPort() && ports && ports.indexOf(portPreference) >= 0)
self.selectedPort(portPreference);
if (!self.selectedBaudrate() && baudrates && baudrates.indexOf(baudratePreference) >= 0)
self.selectedBaudrate(baudratePreference);
self.saveSettings(false);
}
@@ -86,7 +92,8 @@ function ConnectionViewModel(loginStateViewModel, settingsViewModel) {
var data = {
"command": "connect",
"port": self.selectedPort(),
"baudrate": self.selectedBaudrate()
"baudrate": self.selectedBaudrate(),
"autoconnect": self.settings.serial_autoconnect()
};
if (self.saveSettings())
@@ -96,19 +103,20 @@ function ConnectionViewModel(loginStateViewModel, settingsViewModel) {
url: AJAX_BASEURL + "control/connection",
type: "POST",
dataType: "json",
data: data
})
self.settings.serial_port(self.selectedPort())
self.settings.serial_baudrate(self.selectedBaudrate())
self.settings.saveData();
contentType: "application/json; charset=UTF-8",
data: JSON.stringify(data),
success: function(response) {
self.settings.requestData()
}
});
} else {
self.requestData();
$.ajax({
url: AJAX_BASEURL + "control/connection",
type: "POST",
dataType: "json",
data: {"command": "disconnect"}
contentType: "application/json; charset=UTF-8",
data: JSON.stringify({"command": "disconnect"})
})
}
}
@@ -80,26 +80,37 @@ function ControlViewModel(loginStateViewModel, settingsViewModel) {
self.sendJogCommand = function(axis, multiplier, distance) {
if (typeof distance === "undefined")
distance = $('#jog_distance button.active').data('distance');
if (self.settings.getPrinterInvertAxis(axis)) {
multiplier *= -1;
}
var data = {
"command": "jog"
}
data[axis] = distance * multiplier;
$.ajax({
url: AJAX_BASEURL + "control/jog",
url: AJAX_BASEURL + "control/printer/printhead",
type: "POST",
dataType: "json",
data: axis + "=" + ( distance * multiplier )
})
contentType: "application/json; charset=UTF-8",
data: JSON.stringify(data)
});
}
self.sendHomeCommand = function(axis) {
var data = {
"command": "home",
"axes": axis
}
$.ajax({
url: AJAX_BASEURL + "control/jog",
url: AJAX_BASEURL + "control/printer/printhead",
type: "POST",
dataType: "json",
data: "home" + axis
})
contentType: "application/json; charset=UTF-8",
data: JSON.stringify(data)
});
}
self.sendExtrudeCommand = function() {
@@ -114,12 +125,14 @@ function ControlViewModel(loginStateViewModel, settingsViewModel) {
var length = self.extrusionAmount();
if (!length)
length = 5;
$.ajax({
url: AJAX_BASEURL + "control/jog",
url: AJAX_BASEURL + "control/printer/feeder",
type: "POST",
dataType: "json",
data: "extrude=" + (dir * length)
})
contentType: "application/json; charset=UTF-8",
data: JSON.stringify({command: "extrude", amount: (dir * length)})
});
}
self.sendCustomCommand = function(command) {
@@ -143,11 +156,11 @@ function ControlViewModel(loginStateViewModel, settingsViewModel) {
}
}
if (!data)
if (data === undefined)
return;
$.ajax({
url: AJAX_BASEURL + "control/command",
url: AJAX_BASEURL + "control/printer/command",
type: "POST",
dataType: "json",
contentType: "application/json; charset=UTF-8",
@@ -127,11 +127,19 @@ function GcodeFilesViewModel(printerStateViewModel, loginStateViewModel) {
var file = self.listHelper.getItem(function(item) {return item.name == filename});
if (!file) return;
var origin;
if (file.origin === undefined) {
origin = "local";
} else {
origin = file.origin;
}
$.ajax({
url: AJAX_BASEURL + "gcodefiles/load",
url: AJAX_BASEURL + "gcodefiles/" + origin + "/" + filename,
type: "POST",
dataType: "json",
data: {filename: filename, print: printAfterLoad, target: file.origin}
contentType: "application/json; charset=UTF-8",
data: JSON.stringify({command: "load", print: printAfterLoad})
})
}
@@ -139,11 +147,16 @@ function GcodeFilesViewModel(printerStateViewModel, loginStateViewModel) {
var file = self.listHelper.getItem(function(item) {return item.name == filename});
if (!file) return;
var origin;
if (file.origin === undefined) {
origin = "local";
} else {
origin = file.origin;
}
$.ajax({
url: AJAX_BASEURL + "gcodefiles/delete",
type: "POST",
dataType: "json",
data: {filename: filename, target: file.origin},
url: AJAX_BASEURL + "gcodefiles/" + origin + "/" + filename,
type: "DELETE",
success: self.fromResponse
})
}
@@ -147,7 +147,8 @@ function PrinterStateViewModel(loginStateViewModel) {
url: AJAX_BASEURL + "control/job",
type: "POST",
dataType: "json",
data: {command: command}
contentType: "application/json; charset=UTF-8",
data: JSON.stringify({command: command})
});
}
}
@@ -167,47 +167,64 @@ function TemperatureViewModel(loginStateViewModel, settingsViewModel) {
self.setTempFromProfile = function(profile) {
if (!profile)
return;
self._updateTemperature(profile.extruder, "temp");
self._sendHotendCommand("temp", "hotend", profile.extruder);
}
self.setTemp = function() {
self._updateTemperature(self.newTemp(), "temp", function(){self.targetTemp(self.newTemp()); self.newTemp("");});
self._sendHotendCommand("temp", "hotend", self.newTemp(), function() {self.targetTemp(self.newTemp()); self.newTemp("");});
};
self.setTempToZero = function() {
self._updateTemperature(0, "temp", function(){self.targetTemp(0); self.newTemp("");});
self._sendHotendCommand("temp", "hotend", 0, function() {self.targetTemp(0); self.newTemp("");});
}
self.setTempOffset = function() {
self._updateTemperature(self.newTempOffset(), "tempOffset", function() {self.tempOffset(self.newTempOffset()); self.newTempOffset("");});
self._sendHotendCommand("offset", "hotend", self.newTempOffset(), function() {self.tempOffset(self.newTempOffset()); self.newTempOffset("");});
}
self.setBedTempFromProfile = function(profile) {
self._updateTemperature(profile.bed, "bedTemp");
if (!profile)
return;
self._sendHotendCommand("temp", "bed", profile.bed);
}
self.setBedTemp = function() {
self._updateTemperature(self.newBedTemp(), "bedTemp", function() {self.bedTargetTemp(self.newBedTemp()); self.newBedTemp("");});
self._sendHotendCommand("temp", "bed", self.newBedTemp(), function() {self.bedTargetTemp(self.newBedTemp()); self.newBedTemp("");});
};
self.setBedTempToZero = function() {
self._updateTemperature(0, "bedTemp", function() {self.bedTargetTemp(0); self.newBedTemp("");});
self._sendHotendCommand("temp", "bed", 0, function() {self.bedTargetTemp(0); self.newBedTemp("");});
}
self.setBedTempOffset = function() {
self._updateTemperature(self.newBedTempOffset(), "bedTempOffset", function() {self.bedTempOffset(self.newBedTempOffset()); self.newBedTempOffset("");});
self._sendHotendCommand("offset", "bed", self.newBedTempOffset(), function() {self.bedTempOffset(self.newBedTempOffset()); self.newBedTempOffset("");});
}
self._updateTemperature = function(temp, type, callback) {
var data = {};
data[type] = temp;
self._sendHotendCommand = function(command, type, temp, callback) {
var group;
if ("temp" == command) {
group = "temps";
} else if ("offset" == command) {
group = "offsets";
} else {
return;
}
var data = {
"command": command
};
data[group] = {};
data[group][type] = parseInt(temp);
$.ajax({
url: AJAX_BASEURL + "control/temperature",
url: AJAX_BASEURL + "control/printer/hotend",
type: "POST",
data: data,
dataType: "json",
contentType: "application/json; charset=UTF-8",
data: JSON.stringify(data),
success: function() { if (callback !== undefined) callback(); }
});
}
self.handleEnter = function(event, type) {
@@ -89,18 +89,17 @@ function TerminalViewModel(loginStateViewModel, settingsViewModel) {
}
self.sendCommand = function() {
/*
var re = /^([gm][0-9]+)(\s.*)?/;
var commandMatch = command.match(re);
if (commandMatch != null) {
command = commandMatch[1].toUpperCase() + ((commandMatch[2] !== undefined) ? commandMatch[2] : "");
}
*/
var command = self.command();
var re = /^([gm][0-9]+)(\s.*)?/;
var commandMatch = command.match(re);
if (commandMatch != null) {
command = commandMatch[1].toUpperCase() + ((commandMatch[2] !== undefined) ? commandMatch[2] : "");
}
if (command) {
$.ajax({
url: AJAX_BASEURL + "control/command",
url: AJAX_BASEURL + "control/printer/command",
type: "POST",
dataType: "json",
contentType: "application/json; charset=UTF-8",
@@ -28,6 +28,7 @@ function UsersViewModel(loginStateViewModel) {
self.editorUsername = ko.observable(undefined);
self.editorPassword = ko.observable(undefined);
self.editorRepeatedPassword = ko.observable(undefined);
self.editorApikey = ko.observable(undefined);
self.editorAdmin = ko.observable(undefined);
self.editorActive = ko.observable(undefined);
@@ -36,10 +37,12 @@ function UsersViewModel(loginStateViewModel) {
self.editorUsername(undefined);
self.editorAdmin(undefined);
self.editorActive(undefined);
self.editorApikey(undefined);
} else {
self.editorUsername(newValue.name);
self.editorAdmin(newValue.admin);
self.editorActive(newValue.active);
self.editorApikey(newValue.apikey);
}
self.editorPassword(undefined);
self.editorRepeatedPassword(undefined);
@@ -122,6 +125,27 @@ function UsersViewModel(loginStateViewModel) {
});
}
self.confirmGenerateApikey = function() {
if (!CONFIG_ACCESS_CONTROL) return;
self.generateApikey(self.currentUser().name, function(response) {
self._updateApikey(response.apikey);
})
}
self.confirmDeleteApikey = function() {
if (!CONFIG_ACCESS_CONTROL) return;
self.deleteApikey(self.currentUser().name, function() {
self._updateApikey(undefined);
})
}
self._updateApikey = function(apikey) {
self.editorApikey(apikey);
self.requestData();
}
//~~ AJAX calls
self.addUser = function(user, callback) {
@@ -187,4 +211,24 @@ function UsersViewModel(loginStateViewModel) {
success: callback
});
}
self.generateApikey = function(username, callback) {
if (!CONFIG_ACCESS_CONTROL) return;
$.ajax({
url: AJAX_BASEURL + "users/" + username + "/apikey",
type: "POST",
success: callback
});
}
self.deleteApikey = function(username, callback) {
if (!CONFIG_ACCESS_CONTROL) return;
$.ajax({
url: AJAX_BASEURL + "users/" + username + "/apikey",
type: "DELETE",
success: callback
});
}
}
+5 -5
View File
@@ -210,18 +210,18 @@
<span class="btn btn-primary fileinput-button span6" data-bind="css: {disabled: !$root.loginState.isUser()}" style="margin-bottom: 10px">
<i class="icon-upload-alt icon-white"></i>
<span>Upload</span>
<input id="gcode_upload" type="file" name="gcode_file" class="fileinput-button" data-url="/ajax/gcodefiles/upload" data-bind="enable: loginState.isUser()">
<input id="gcode_upload" type="file" name="gcode_file" class="fileinput-button" data-bind="enable: loginState.isUser()">
</span>
<span class="btn btn-primary fileinput-button span6" data-bind="css: {disabled: !$root.loginState.isUser() || !$root.isSdReady()}" style="margin-bottom: 10px">
<i class="icon-upload-alt icon-white"></i>
<span>Upload to SD</span>
<input id="gcode_upload_sd" type="file" name="gcode_file" class="fileinput-button" data-url="/ajax/gcodefiles/upload" data-bind="enable: loginState.isUser() && isSdReady()">
<input id="gcode_upload_sd" type="file" name="gcode_file" class="fileinput-button" data-bind="enable: loginState.isUser() && isSdReady()">
</span>
{% else %}
<span class="btn btn-primary fileinput-button span12" data-bind="css: {disabled: !$root.loginState.isUser()}" style="margin-bottom: 10px">
<i class="icon-upload-alt icon-white"></i>
<span>Upload</span>
<input id="gcode_upload" type="file" name="gcode_file" class="fileinput-button" data-url="/ajax/gcodefiles/upload" data-bind="enable: loginState.isUser()">
<input id="gcode_upload" type="file" name="gcode_file" class="fileinput-button" data-bind="enable: loginState.isUser()">
</span>
{% endif %}
</div>
@@ -352,7 +352,7 @@
</div>
<div>
<button class="btn box pull-left" data-bind="enable: isOperational() && !isPrinting() && loginState.isUser(), click: function() { $root.sendJogCommand('x',-1) }"><i class="icon-arrow-left"></i></button>
<button class="btn box pull-left" data-bind="enable: isOperational() && !isPrinting() && loginState.isUser(), click: function() { $root.sendHomeCommand('XY') }"><i class="icon-home"></i></button>
<button class="btn box pull-left" data-bind="enable: isOperational() && !isPrinting() && loginState.isUser(), click: function() { $root.sendHomeCommand(['x', 'y']) }"><i class="icon-home"></i></button>
<button class="btn box pull-left" data-bind="enable: isOperational() && !isPrinting() && loginState.isUser(), click: function() { $root.sendJogCommand('x',1) }"><i class="icon-arrow-right"></i></button>
</div>
<div>
@@ -366,7 +366,7 @@
<button class="btn box" data-bind="enable: isOperational() && !isPrinting() && loginState.isUser(), click: function() { $root.sendJogCommand('z',1) }"><i class="icon-arrow-up"></i></button>
</div>
<div>
<button class="btn box" data-bind="enable: isOperational() && !isPrinting() && loginState.isUser(), click: function() { $root.sendHomeCommand('Z') }"><i class="icon-home"></i></button>
<button class="btn box" data-bind="enable: isOperational() && !isPrinting() && loginState.isUser(), click: function() { $root.sendHomeCommand(['z']) }"><i class="icon-home"></i></button>
</div>
<div>
<button class="btn box" data-bind="enable: isOperational() && !isPrinting() && loginState.isUser(), click: function() { $root.sendJogCommand('z',-1) }"><i class="icon-arrow-down"></i></button>
+16 -1
View File
@@ -382,7 +382,7 @@
</thead>
<tbody data-bind="foreach: users.listHelper.paginatedItems">
<tr>
<td class="settings_users_name" data-bind="text: name"></td>
<td class="settings_users_name"><span data-bind="text: name"></span><span class="muted" data-bind="visible: $root.api_enabled() && apikey"><br /><small>Apikey: <span data-bind="text: apikey"></span></small></span></td>
<td class="settings_users_active"><i data-bind="css: { 'icon-check': active, 'icon-check-empty': !active }"></i></td>
<td class="settings_users_admin"><i data-bind="css: { 'icon-check': admin, 'icon-check-empty': !admin }"></i></td>
<td class="settings_users_actions" class="system_users_action">
@@ -504,6 +504,20 @@
<span class="help-inline" data-bind="visible: $root.users.editorPasswordMismatch()">Passwords do not match</span>
</div>
</div>
<fieldset data-bind="visible: api_enabled">
<legend>Apikey</legend>
<div class="control-group">
<label class="control-label">Current Apikey</label>
<div class="controls">
<div class="input-append">
<input type="text" class="input-block-level uneditable-input" data-bind="value: $root.users.editorApikey, attr: {placeholder: 'N/A'}">
<a class="btn" title="Generate new Apikey" data-bind="click: function() { $root.users.confirmGenerateApikey(); }"><i class="icon-refresh"></i></a>
<a class="btn btn-danger" title="Delete Apikey" data-bind="click: function() { $root.users.confirmDeleteApikey(); }"><i class="icon-trash"></i></a>
</div>
</div>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
@@ -511,6 +525,7 @@
<button class="btn btn-primary" data-bind="click: function() { $root.users.confirmChangePassword(); }, enable: !$root.users.editorPasswordMismatch()">Confirm</button>
</div>
</div>
</div>
{% endif %}
+51 -12
View File
@@ -7,6 +7,7 @@ from flask.ext.principal import Identity
import hashlib
import os
import yaml
import uuid
from octoprint.settings import settings
@@ -70,7 +71,10 @@ class FilebasedUserManager(UserManager):
data = yaml.safe_load(f)
for name in data.keys():
attributes = data[name]
self._users[name] = User(name, attributes["password"], attributes["active"], attributes["roles"])
apikey = None
if "apikey" in attributes:
apikey = attributes["apikey"]
self._users[name] = User(name, attributes["password"], attributes["active"], attributes["roles"], apikey)
else:
self._customized = False
@@ -84,7 +88,8 @@ class FilebasedUserManager(UserManager):
data[name] = {
"password": user._passwordHash,
"active": user._active,
"roles": user._roles
"roles": user._roles,
"apikey": user._apikey
}
with open(self._userfile, "wb") as f:
@@ -92,11 +97,11 @@ class FilebasedUserManager(UserManager):
self._dirty = False
self._load()
def addUser(self, username, password, active=False, roles=["user"]):
def addUser(self, username, password, active=False, roles=["user"], apikey=None):
if username in self._users.keys():
raise UserAlreadyExists(username)
self._users[username] = User(username, UserManager.createPasswordHash(password), active, roles)
self._users[username] = User(username, UserManager.createPasswordHash(password), active, roles, apikey)
self._dirty = True
self._save()
@@ -154,6 +159,25 @@ class FilebasedUserManager(UserManager):
self._dirty = True
self._save()
def generateApiKey(self, username):
if not username in self._users.keys():
raise UnknownUser(username)
user = self._users[username]
user._apikey = ''.join('%02X' % ord(z) for z in uuid.uuid4().bytes)
self._dirty = True
self._save()
return user._apikey
def deleteApikey(self, username):
if not username in self._users.keys():
raise UnknownUser(username)
user = self._users[username]
user._apikey = None
self._dirty = True
self._save()
def removeUser(self, username):
if not username in self._users.keys():
raise UnknownUser(username)
@@ -162,14 +186,19 @@ class FilebasedUserManager(UserManager):
self._dirty = True
self._save()
def findUser(self, username=None):
if username is None:
return None
def findUser(self, username=None, apikey=None):
if username is not None:
if username not in self._users.keys():
return None
if username not in self._users.keys():
return self._users[username]
elif apikey is not None:
for user in self._users.values():
if apikey == user._apikey:
return user
return None
else:
return None
return self._users[username]
def getAllUsers(self):
return map(lambda x: x.asDict(), self._users.values())
@@ -194,18 +223,20 @@ class UnknownRole(Exception):
##~~ User object
class User(UserMixin):
def __init__(self, username, passwordHash, active, roles):
def __init__(self, username, passwordHash, active, roles, apikey=None):
self._username = username
self._passwordHash = passwordHash
self._active = active
self._roles = roles
self._apikey = apikey
def asDict(self):
return {
"name": self._username,
"active": self.is_active(),
"admin": self.is_admin(),
"user": self.is_user()
"user": self.is_user(),
"apikey": self._apikey
}
def check_password(self, passwordHash):
@@ -241,3 +272,11 @@ class DummyIdentity(Identity):
def dummy_identity_loader():
return DummyIdentity()
##~~ Apiuser object to use when api key is used to access the API
class ApiUser(User):
def __init__(self):
User.__init__(self, "api", "", True, UserManager.valid_roles)
+18
View File
@@ -8,6 +8,7 @@ import sys
import time
import re
import tempfile
from flask import make_response
from octoprint.settings import settings
@@ -188,3 +189,20 @@ def silentRemove(file):
os.remove(file)
except OSError:
pass
def getJsonCommandFromRequest(request, valid_commands):
if not "application/json" in request.headers["Content-Type"]:
return None, None, make_response("Expected content-type JSON", 400)
data = request.json
if not "command" in data.keys() or not data["command"] in valid_commands.keys():
return None, None, make_response("Expected valid command", 400)
command = data["command"]
for parameter in valid_commands[command]:
if not parameter in data:
return None, None, make_response("Mandatory parameter %s missing for command %s" % (parameter, command), 400)
return command, data, None
+4 -1
View File
@@ -291,6 +291,9 @@ class MachineCom(object):
def getOffsets(self):
return (self._tempOffset, self._bedTempOffset)
def getConnection(self):
return self._port, self._baudrate
##~~ external interface
def close(self, isError = False):
@@ -826,8 +829,8 @@ class MachineCom(object):
self._sendCommand("M29")
filename = self._currentFile.getFilename()
self._currentFile = None
self._callback.mcFileTransferDone()
self._changeState(self.STATE_OPERATIONAL)
self._callback.mcFileTransferDone(filename)
eventManager().fire("TransferDone", filename)
self.refreshSdFiles()
else: