From f02fac20ed337c8a991e5529804e0bde294c889f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Feb 2017 15:51:24 +0100 Subject: [PATCH 01/15] Only do lookup by userid if session is None --- src/octoprint/users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/users.py b/src/octoprint/users.py index c5bb27d67..1c6258cd4 100644 --- a/src/octoprint/users.py +++ b/src/octoprint/users.py @@ -377,7 +377,7 @@ class FilebasedUserManager(UserManager): if user is not None: return user - if userid is not None: + if userid is not None and session is None: if userid not in self._users.keys(): return None return self._users[userid] From b7e2b0f7947546033bbb8cf978f93fd945cbf97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 28 Feb 2017 09:54:36 +0100 Subject: [PATCH 02/15] Fixed login dropdown not auto closing on click outside of it When two wrongs make one right... --- src/octoprint/static/js/app/viewmodels/loginstate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/loginstate.js b/src/octoprint/static/js/app/viewmodels/loginstate.js index 691784e21..9b95d62d2 100644 --- a/src/octoprint/static/js/app/viewmodels/loginstate.js +++ b/src/octoprint/static/js/app/viewmodels/loginstate.js @@ -141,8 +141,8 @@ $(function() { var anyLastpassButton = $("#__lpform_login_user, #__lpform_login_pass"); var isLinkOrButton = anyFormLinkOrButton.is(e.target) || anyFormLinkOrButton.has(e.target).length !== 0; - var isDropdown = dropdown.is(e.target) || dropdown.has(e.target).length === 0; - var isLastpass = anyLastpassButton.is(e.target) || anyLastpassButton.has(e.target).length === 0; + var isDropdown = dropdown.is(e.target) || dropdown.has(e.target).length !== 0; + var isLastpass = anyLastpassButton.is(e.target) || anyLastpassButton.has(e.target).length !== 0; if (isLinkOrButton || !(isDropdown || isLastpass)) { toggle.removeClass("open"); From 14120f732b848897f147a3339f6ff8d78143a531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 28 Feb 2017 10:00:51 +0100 Subject: [PATCH 03/15] Only check if we need to close login dropdown if it's open --- src/octoprint/static/js/app/viewmodels/loginstate.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/octoprint/static/js/app/viewmodels/loginstate.js b/src/octoprint/static/js/app/viewmodels/loginstate.js index 9b95d62d2..14cbf8ac4 100644 --- a/src/octoprint/static/js/app/viewmodels/loginstate.js +++ b/src/octoprint/static/js/app/viewmodels/loginstate.js @@ -136,6 +136,10 @@ $(function() { }); $("body").on("click", function(e) { + if (!toggle.hasClass("open")) { + return; + } + var anyFormLinkOrButton = $("#login_dropdown_loggedout a, #login_dropdown_loggedin a, #login_dropdown_loggedout button, #login_dropdown_loggedin button"); var dropdown = $("li.dropdown#navbar_login"); var anyLastpassButton = $("#__lpform_login_user, #__lpform_login_pass"); From 20e1219d9ee3f2b50826151cd5e181439eeb870e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 1 Mar 2017 15:48:36 +0100 Subject: [PATCH 04/15] Virtual printer: configurable ok format --- src/octoprint/plugins/virtual_printer/virtual.py | 13 ++++++------- src/octoprint/settings.py | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index c60f05491..e231fb7a5 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -109,6 +109,8 @@ class VirtualPrinter(object): self._firmwareName = settings().get(["devel", "virtualPrinter", "firmwareName"]) + self._okFormatString = settings().get(["devel", "virtualPrinter", "okFormatString"]) + self.currentLine = 0 self.lastN = 0 @@ -1073,11 +1075,7 @@ class VirtualPrinter(object): def _sendOk(self): if self.outgoing is None: return - - if settings().getBoolean(["devel", "virtualPrinter", "okWithLinenumber"]): - self._send("{} {}".format(self._ok(), self.lastN)) - else: - self._send(self._ok()) + self._send(self._ok()) def _sendWaitAfterTimeout(self, timeout=5): time.sleep(timeout) @@ -1089,10 +1087,11 @@ class VirtualPrinter(object): self.outgoing.put(line) def _ok(self): - ok = "ok" + ok = self._okFormatString if self._prepared_oks: ok = self._prepared_oks.pop(0) - return ok + + return ok.format(ok, lastN=self.lastN, buffer=self.buffered.maxsize - self.buffered.qsize()) class CharCountingQueue(queue.Queue): diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index cedc2fc74..6640bbc18 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -335,7 +335,6 @@ default_settings = { "enabled": False, "okAfterResend": False, "forceChecksum": False, - "okWithLinenumber": False, "numExtruders": 1, "includeCurrentToolInTemps": True, "includeFilenameInOpened": True, @@ -360,7 +359,8 @@ default_settings = { "sharedNozzle": False, "sendBusy": False, "simulateReset": True, - "preparedOks": [] + "preparedOks": [], + "okFormatString": "ok" } } } From c765e6e228022a3785906de68c02a2c6dd15865b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 1 Mar 2017 15:49:19 +0100 Subject: [PATCH 05/15] Revert "Only do lookup by userid if session is None" This reverts commit f02fac20ed337c8a991e5529804e0bde294c889f. The commit turned out to nuke the "remember me" functionality. --- src/octoprint/users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/users.py b/src/octoprint/users.py index 1c6258cd4..c5bb27d67 100644 --- a/src/octoprint/users.py +++ b/src/octoprint/users.py @@ -377,7 +377,7 @@ class FilebasedUserManager(UserManager): if user is not None: return user - if userid is not None and session is None: + if userid is not None: if userid not in self._users.keys(): return None return self._users[userid] From d845257cf4fb11a6f30582aa266dd1e00face13e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 1 Mar 2017 18:28:37 +0100 Subject: [PATCH 06/15] Fixed caching of main page Got broken by 62890ef73a184a116f1177b1f90152c86ff161a9 --- src/octoprint/server/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 9e3afe3bf..2e8a25c06 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -301,7 +301,7 @@ def index(): decorated_view = view decorated_view = util.flask.lastmodified(lambda _: compute_lastmodified())(decorated_view) - decorated_view = util.flask.etagged(lambda _: compute_etag(additional=cache_key()))(decorated_view) + decorated_view = util.flask.etagged(lambda _: compute_etag(additional=[cache_key()] + additional_etag))(decorated_view) decorated_view = util.flask.cached(timeout=-1, refreshif=validate_cache, key=cache_key, From 2dcd6e02b1448fdcf3253e3de4dab6b536e3ba70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 6 Mar 2017 11:37:00 +0100 Subject: [PATCH 07/15] Remove webapp headers to play nice with Safari's session handling Solves #1792 --- src/octoprint/templates/index.jinja2 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/octoprint/templates/index.jinja2 b/src/octoprint/templates/index.jinja2 index 56b687938..fc33805ec 100644 --- a/src/octoprint/templates/index.jinja2 +++ b/src/octoprint/templates/index.jinja2 @@ -8,10 +8,6 @@ - - - - {% include 'stylesheets.jinja2' %} {% include 'initscript.jinja2' %} From 01ebf8fba785c94053fb2d85ac317b4de3659e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 6 Mar 2017 11:54:03 +0100 Subject: [PATCH 08/15] Fix for two timing sensitive unit tests --- tests/settings/test_settings.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/settings/test_settings.py b/tests/settings/test_settings.py index 9455c1799..7ce753cb2 100644 --- a/tests/settings/test_settings.py +++ b/tests/settings/test_settings.py @@ -17,6 +17,7 @@ import tempfile import yaml import hashlib import ddt +import time import octoprint.settings @@ -527,6 +528,9 @@ class TestSettings(unittest.TestCase): # current modification date of config.yaml current_modified = os.stat(config_path).st_mtime + # sleep a bit to make sure we do have a change in the timestamp + time.sleep(1.0) + # set a new value settings.set(["api", "key"], "newkey") @@ -542,6 +546,9 @@ class TestSettings(unittest.TestCase): settings = octoprint.settings.Settings() last_modified = settings.last_modified + # sleep a bit to make sure we do have a change in the timestamp + time.sleep(1.0) + settings.save() self.assertEqual(settings.last_modified, last_modified) From 811c91955cb5409e1c22a7e1126e8b01afde5059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 6 Mar 2017 14:02:39 +0100 Subject: [PATCH 09/15] Fix for new user settings getting lost until restart On reload of the user settings a new user object was created but not updated on the associated session user(s). That let to session user (s) still referring to the old user instances with the only partially updated user settings. Behaviour changed such that on a reload of the users from file (including user settings) all registered session users will now get their reference updated as well. Also made modelling of user id to session id a bit less redundant. --- src/octoprint/users.py | 44 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/octoprint/users.py b/src/octoprint/users.py index c5bb27d67..56ddf7867 100644 --- a/src/octoprint/users.py +++ b/src/octoprint/users.py @@ -26,7 +26,7 @@ class UserManager(object): def __init__(self): self._logger = logging.getLogger(__name__) self._session_users_by_session = dict() - self._session_users_by_userid = dict() + self._sessionids_by_userid = dict() self._enabled = True @property @@ -61,9 +61,10 @@ class UserManager(object): self._session_users_by_session[user.get_session()] = user userid = user.get_id() - if not userid in self._session_users_by_userid: - self._session_users_by_userid[userid] = [] - self._session_users_by_userid[userid].append(user) + if not userid in self._sessionids_by_userid: + self._sessionids_by_userid[userid] = set() + + self._sessionids_by_userid[userid].add(user.get_session()) self._logger.debug("Logged in user: %r" % user) @@ -80,15 +81,16 @@ class UserManager(object): return userid = user.get_id() - if userid in self._session_users_by_userid: - users_by_userid = self._session_users_by_userid[userid] - for u in users_by_userid: - if u.get_session() == user.get_session(): - users_by_userid.remove(u) - break + sessionid = user.get_session() - if user.get_session() in self._session_users_by_session: - del self._session_users_by_session[user.get_session()] + if userid in self._sessionids_by_userid: + try: + self._sessionids_by_userid[userid].remove(sessionid) + except KeyError: + pass + + if sessionid in self._session_users_by_session: + del self._session_users_by_session[sessionid] self._logger.debug("Logged out user: %r" % user) @@ -165,13 +167,12 @@ class UserManager(object): pass def removeUser(self, username): - if username in self._session_users_by_userid: - users = self._session_users_by_userid[username] - sessions = [user.get_session() for user in users if isinstance(user, SessionUser)] + if username in self._sessionids_by_userid: + sessions = self._sessionids_by_userid[username] for session in sessions: if session in self._session_users_by_session: del self._session_users_by_session[session] - del self._session_users_by_userid[username] + del self._sessionids_by_userid[username] def findUser(self, userid=None, session=None): if session is not None and session in self._session_users_by_session: @@ -217,6 +218,9 @@ class FilebasedUserManager(UserManager): if "settings" in attributes: settings = attributes["settings"] self._users[name] = User(name, attributes["password"], attributes["active"], attributes["roles"], apikey=apikey, settings=settings) + for sessionid in self._sessionids_by_userid.get(name, set()): + if sessionid in self._session_users_by_session: + self._session_users_by_session[sessionid].update_user(self._users[name]) else: self._customized = False @@ -421,7 +425,7 @@ class User(UserMixin): self._roles = roles self._apikey = apikey - if not settings: + if settings is None: settings = dict() self._settings = settings @@ -505,7 +509,6 @@ class User(UserMixin): class SessionUser(User): def __init__(self, user): self._user = user - User.__init__(self, user._username, user._passwordHash, user._active, user._roles, user._apikey, user._settings) import string import random @@ -515,7 +518,7 @@ class SessionUser(User): self._created = time.time() def __getattribute__(self, item): - if item in ("get_session", "_user", "_session", "_created"): + if item in ("get_session", "update_user", "_user", "_session", "_created"): return object.__getattribute__(self, item) else: return getattr(object.__getattribute__(self, "_user"), item) @@ -529,6 +532,9 @@ class SessionUser(User): def get_session(self): return self._session + def update_user(self, user): + self._user = user + def __repr__(self): return "SessionUser(id=%s,name=%s,active=%r,user=%r,admin=%r,session=%s,created=%s)" % (self.get_id(), self.get_name(), self.is_active(), self.is_user(), self.is_admin(), self._session, self._created) From d8f2630fd4cba8a1473105d24b0124a1be4b4613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 6 Mar 2017 14:11:41 +0100 Subject: [PATCH 10/15] Don't call onUserLoggedIn/Out on user reload --- .../static/js/app/viewmodels/loginstate.js | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/loginstate.js b/src/octoprint/static/js/app/viewmodels/loginstate.js index 14cbf8ac4..ab3423c1a 100644 --- a/src/octoprint/static/js/app/viewmodels/loginstate.js +++ b/src/octoprint/static/js/app/viewmodels/loginstate.js @@ -41,7 +41,7 @@ $(function() { } OctoPrint.users.get(self.currentUser().name) - .done(self.fromResponse); + .done(self.updateCurrentUserData); }; self.requestData = function() { @@ -52,25 +52,31 @@ $(function() { self.fromResponse = function(response) { if (response && response.name) { self.loggedIn(true); - self.username(response.name); - self.isUser(response.user); - self.isAdmin(response.admin); - - self.currentUser(response); - + self.updateCurrentUserData(response); callViewModels(self.allViewModels, "onUserLoggedIn", [response]); } else { self.loggedIn(false); - self.username(undefined); - self.isUser(false); - self.isAdmin(false); - - self.currentUser(undefined); - + self.resetCurrentUserData(); callViewModels(self.allViewModels, "onUserLoggedOut"); } }; + self.updateCurrentUserData = function(data) { + self.username(data.name); + self.isUser(data.user); + self.isAdmin(data.admin); + + self.currentUser(data); + }; + + self.resetCurrentUserData = function() { + self.username(undefined); + self.isUser(false); + self.isAdmin(false); + + self.currentUser(undefined); + }; + self.login = function(u, p, r) { var username = u || self.loginUser(); var password = p || self.loginPass(); From 01cffafe77fbbe4c6bca9817116367e958b8241c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 6 Mar 2017 14:36:43 +0100 Subject: [PATCH 11/15] Fixed documentation of printer profile API Closes #1732 --- docs/api/printerprofiles.rst | 189 +++++++++++++++++++++-------------- 1 file changed, 113 insertions(+), 76 deletions(-) diff --git a/docs/api/printerprofiles.rst b/docs/api/printerprofiles.rst index 8a18713a5..835399d5c 100644 --- a/docs/api/printerprofiles.rst +++ b/docs/api/printerprofiles.rst @@ -34,90 +34,92 @@ Retrieve all printer profiles HTTP/1.1 200 OK Content-Type: application/json - [ - { - "id": "_default", - "name": "Default", - "color": "default", - "model": "Generic RepRap Printer", - "default": true, - "current": true, - "resource": "http://example.com/api/printerprofiles/_default", - "volume": { - "formFactor": "rectangular", - "origin": "lowerleft", - "width": 200, - "depth": 200, - "height": 200 - }, - "heatedBed": true, - "axes": { - "x": { - "speed": 6000, - "inverted": false + { + "profiles": [ + { + "id": "_default", + "name": "Default", + "color": "default", + "model": "Generic RepRap Printer", + "default": true, + "current": true, + "resource": "http://example.com/api/printerprofiles/_default", + "volume": { + "formFactor": "rectangular", + "origin": "lowerleft", + "width": 200, + "depth": 200, + "height": 200 }, - "y": { - "speed": 6000, - "inverted": false + "heatedBed": true, + "axes": { + "x": { + "speed": 6000, + "inverted": false + }, + "y": { + "speed": 6000, + "inverted": false + }, + "z": { + "speed": 200, + "inverted": false + }, + "e": { + "speed": 300, + "inverted": false + } }, - "z": { - "speed": 200, - "inverted": false - }, - "e": { - "speed": 300, - "inverted": false + "extruder": { + "count": 1, + "offsets": [ + {"x": 0.0, "y": 0.0} + ] } }, - "extruder": { - "count": 1, - "offsets": [ - {"x": 0.0, "y": 0.0} - ] - } - }, - { - "id": "my_profile", - "name": "My Profile", - "color": "default", - "model": "My Custom Printer", - "default": false, - "current": false, - "resource": "http://example.com/api/printerprofiles/my_profile", - "volume": { - "formFactor": "rectangular", - "origin": "lowerleft", - "width": 200, - "depth": 200, - "height": 200 - }, - "heatedBed": true, - "axes": { - "x": { - "speed": 6000, - "inverted": false + { + "id": "my_profile", + "name": "My Profile", + "color": "default", + "model": "My Custom Printer", + "default": false, + "current": false, + "resource": "http://example.com/api/printerprofiles/my_profile", + "volume": { + "formFactor": "rectangular", + "origin": "lowerleft", + "width": 200, + "depth": 200, + "height": 200 }, - "y": { - "speed": 6000, - "inverted": false + "heatedBed": true, + "axes": { + "x": { + "speed": 6000, + "inverted": false + }, + "y": { + "speed": 6000, + "inverted": false + }, + "z": { + "speed": 200, + "inverted": false + }, + "e": { + "speed": 300, + "inverted": false + } }, - "z": { - "speed": 200, - "inverted": false - }, - "e": { - "speed": 300, - "inverted": false + "extruder": { + "count": 1, + "offsets": [ + {"x": 0.0, "y": 0.0} + ] } }, - "extruder": { - "count": 1, - "offsets": [ - {"x": 0.0, "y": 0.0} - ] - } - }, - ] + ] + } .. _sec-api-printerprofiles-add: @@ -537,6 +539,41 @@ Profile - 0..1 - ``float`` - The height of the print volume + * - ``volume.custom_box`` + - 0..1 + - ``boolean`` or ``object`` + - If the printer has a custom bounding box where the print head can be safely moved to, exceeding the defined print + volume, that bounding box will be defined here. Otherwise (safe area == print volume) this value will be ``false``. + * - ``volume.custom_box.min_x`` + - 0..1 + - ``float`` + - Minimum X coordinate defining the safe custom bounding box. Smaller value than the minimum X coordinate of the + print volume. + * - ``volume.custom_box.max_x`` + - 0..1 + - ``float`` + - Maximum X coordinate defining the safe custom bounding box. Larger value than the maximum X coordinate of the + print volume. + * - ``volume.custom_box.min_y`` + - 0..1 + - ``float`` + - Minimum Y coordinate defining the safe custom bounding box. Smaller value than the minimum Y coordinate of the + print volume. + * - ``volume.custom_box.max_y`` + - 0..1 + - ``float`` + - Maximum Y coordinate defining the safe custom bounding box. Larger value than the maximum Y coordinate of the + print volume. + * - ``volume.custom_box.min_z`` + - 0..1 + - ``float`` + - Minimum Z coordinate defining the safe custom bounding box. Smaller value than the minimum Z coordinate of the + print volume. + * - ``volume.custom_box.max_z`` + - 0..1 + - ``float`` + - Maximum Z coordinate defining the safe custom bounding box. Larger value than the maximum Z coordinate of the + print volume. * - ``heatedBed`` - 0..1 - ``boolean`` From ab42cc2a7fcd53861f2b2b0af925bdfa47cd7c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 6 Mar 2017 15:32:30 +0100 Subject: [PATCH 12/15] Better error resilience against garbage history data from plugins See #1805 --- src/octoprint/filemanager/storage.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index 46a3d63fa..9a74e3dc3 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -982,7 +982,15 @@ class LocalFileStorage(StorageInterface): continue printer_profile = history_entry["printerProfile"] + if not printer_profile: + continue + print_time = history_entry["printTime"] + try: + print_time = float(print_time) + except: + self._logger.warn("Invalid print time value found in print history for {} in {}/.metadata.yaml: {!r}".format(name, path, print_time)) + continue if not printer_profile in former_print_times: former_print_times[printer_profile] = [] From ef6159cc962e2855901cb9de4a18ba0050fdf070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 6 Mar 2017 15:51:14 +0100 Subject: [PATCH 13/15] Applied text changes proposed by @seigel in #1735 --- CONTRIBUTING.md | 2 +- README.md | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3807025c1..91e3e84f1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -268,7 +268,7 @@ See [the corresponding chapter in the documentation](http://docs.octoprint.org/e **ideally of only one commit** (use git's rebase and squash functionality). 5. Make sure you **follow the current coding style**. This means: * Tabs instead of spaces in the Python files[2] - * Spaces instead of tabs in the Javascript sources + * Spaces instead of tabs in the JavaScript sources * English language (code, variables, comments, ...) * Comments where necessary: Tell *why* the code does something like it does it, structure your code diff --git a/README.md b/README.md index f6d3be2a7..be7b27487 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ If you think something is bad about OctoPrint or its documentation the way it is in any way to make it better instead of just complaining about it -- this is an Open Source Project after all :) -For information about how to go about contributions of any kind, please see the project's +For information about how to go about making contributions of any kind, please see the project's [Contribution Guidelines](https://github.com/foosel/OctoPrint/blob/master/CONTRIBUTING.md). ## Installation @@ -41,7 +41,7 @@ For information about how to go about contributions of any kind, please see the Installation instructions for installing from source for different operating systems can be found [on the wiki](https://github.com/foosel/OctoPrint/wiki#assorted-guides). -If you want to run OctoPrint on a Raspberry Pi you might want to take a look at [OctoPi](https://github.com/guysoft/OctoPi) +If you want to run OctoPrint on a Raspberry Pi, you might want to take a look at [OctoPi](https://github.com/guysoft/OctoPi) which is a custom SD card image that includes OctoPrint plus dependencies. The generic steps that should basically be done regardless of operating system @@ -59,7 +59,7 @@ for details. After installation, please make sure you follow the first-run wizard and set up access control as necessary. If you want to not only be notified about new -releases but also be able to automatically upgrade to them from within +releases, but also be able to automatically upgrade to them from within OctoPrint, take a look [at the documentation of the Software Update Plugin](https://github.com/foosel/OctoPrint/wiki/Plugin:-Software-Update#making-octoprint-updateable-on-existing-installations) and at its settings. @@ -70,7 +70,7 @@ OctoPrint via `setup.py`: python setup.py install -You should also do this every time after pulling from the repository, since the dependencies might have changed. +You should do this every time after pulling from the repository, since the dependencies may have changed. OctoPrint currently only supports Python 2.7. @@ -81,8 +81,8 @@ Running the `setup.py` script via python setup.py install installs the `octoprint` script in your Python installation's scripts folder -(which depending on whether you installed OctoPrint globally or into a virtual env will be on your `PATH` or not). The -following usage examples assume that said `octoprint` script is on your `PATH`. +(which, depending on whether you installed OctoPrint globally or into a virtual env, will be in your `PATH` or not). The +following usage examples assume that the `octoprint` script is on your `PATH`. You can start the server via @@ -95,7 +95,7 @@ to only listen on the local interface on port 8080, the command line would be octoprint serve --host=127.0.0.1 --port=8080 -Alternatively, the host and port on which to bind can be defined via the configuration. +Alternatively, the host and port on which to bind can be defined via the config file. If you want to run OctoPrint as a daemon (only supported on Linux), use @@ -103,19 +103,19 @@ If you want to run OctoPrint as a daemon (only supported on Linux), use If you do not supply a custom pidfile location via `--pid PIDFILE`, it will be created at `/tmp/octoprint.pid`. -You can also specify the configfile or the base directory (for basing off the `uploads`, `timelapse` and `logs` folders), +You can also specify the config file or the base directory (for basing off the `uploads`, `timelapse` and `logs` folders), e.g.: octoprint serve --config /path/to/another/config.yaml --basedir /path/to/my/basedir See `octoprint --help` for further information. -OctoPrint also ships with a `run` script in its source directory. You can also invoke that to start up the server, it +OctoPrint also ships with a `run` script in its source directory. You can invoke it to start the server. It takes the same command line arguments as the `octoprint` script. ## Configuration -If not specified via the commandline, the configfile `config.yaml` for OctoPrint is expected in the settings folder, +If not specified via the command line, the config file `config.yaml` for OctoPrint is expected in the settings folder, which is located at `~/.octoprint` on Linux, at `%APPDATA%/OctoPrint` on Windows and at `~/Library/Application Support/OctoPrint` on MacOS. From a0e5f79483085075dcf3f673b154e97a56973ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 8 Mar 2017 18:03:16 +0100 Subject: [PATCH 14/15] Only load file into GCODE viewer when that is actually visible Reduces needed bandwidth on page load, might help to mitigate bandwidth related issues described in #1241. --- src/octoprint/static/js/app/viewmodels/gcode.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/octoprint/static/js/app/viewmodels/gcode.js b/src/octoprint/static/js/app/viewmodels/gcode.js index d4ae7c310..ea8b4c6ea 100644 --- a/src/octoprint/static/js/app/viewmodels/gcode.js +++ b/src/octoprint/static/js/app/viewmodels/gcode.js @@ -39,6 +39,8 @@ $(function() { size: ko.observable(undefined) }; + self.needsLoad = false; + self.renderer_centerModel = ko.observable(false); self.renderer_centerViewport = ko.observable(false); self.renderer_zoomOnModel = ko.observable(false); @@ -300,6 +302,7 @@ $(function() { self.loadFile = function(path, date){ self.enableReload(false); + self.needsLoad = false; if (self.status == "idle" && self.errorCount < 3) { self.status = "request"; OctoPrint.files.download("local", path) @@ -401,7 +404,11 @@ $(function() { self.loadedFileDate = undefined; } else { self.waitForApproval(false); - self.loadFile(data.job.file.path, data.job.file.date); + if (self.tabActive) { + self.loadFile(data.job.file.path, data.job.file.date); + } else { + self.needsLoad = true; + } } } } @@ -573,6 +580,9 @@ $(function() { self.onTabChange = function(current, previous) { self.tabActive = current == "#gcode"; + if (self.tabActive && self.needsLoad) { + self.loadFile(self.selectedFile.path(), self.selectedFile.date()); + } }; self.shiftLayer = function(value){ From 8a4934e6f825707c75cad8cf26b00458e580a523 Mon Sep 17 00:00:00 2001 From: Andy Werner Date: Tue, 7 Mar 2017 10:35:33 +0100 Subject: [PATCH 15/15] Fix an issue in user settings * UserSettings: crashed if overwrite an existing key with primitive value by same key with complex value. Also reduced number of calls to user.get_setting() * Updated tests (cherry picked from commit b75b53d) --- AUTHORS.md | 1 + src/octoprint/users.py | 9 ++++----- tests/users/test_user.py | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 917011e78..a91f18e6f 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -77,6 +77,7 @@ date of first contribution): * [Noah Martin](https://github.com/noahsmartin) * [Eyal Soha](https://github.com/eyal0) * [Greg Hulands](https://github.com/ghulands) + * [Andreas Werner](https://github.com/gallore) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/src/octoprint/users.py b/src/octoprint/users.py index 56ddf7867..5f05bc754 100644 --- a/src/octoprint/users.py +++ b/src/octoprint/users.py @@ -314,9 +314,8 @@ class FilebasedUserManager(UserManager): raise UnknownUser(username) user = self._users[username] - current = user.get_setting(key) - if not current or current != value: - old_value = user.get_setting(key) + old_value = user.get_setting(key) + if not old_value or old_value != value: user.set_setting(key, value) self._dirty = self._dirty or old_value != value self._save() @@ -482,7 +481,7 @@ class User(UserMixin): def _get_setting(self, path): s = self._settings for p in path: - if p in s: + if isinstance(s, dict) and p in s: s = s[p] else: return None @@ -495,7 +494,7 @@ class User(UserMixin): s[p] = dict() if not isinstance(s[p], dict): - return False + s[p] = dict() s = s[p] diff --git a/tests/users/test_user.py b/tests/users/test_user.py index 4665a2153..e827d3e89 100644 --- a/tests/users/test_user.py +++ b/tests/users/test_user.py @@ -63,7 +63,9 @@ class UserTestCase(unittest.TestCase): (["sub", "othersubkey"], "othersubvalue", dict(sub=dict(othersubkey="othersubvalue")), True), ("booleankey", True, dict(booleankey=True), True), (["newsub", "newsubkey"], "newsubvalue", dict(newsub=dict(newsubkey="newsubvalue")), True), - (["sub", "subkey", "wontwork"], "wontwork", dict(), False) + # ["sub", "subkey"] is already existing and gets overwritten + (["sub", "subkey", "subsubkey"], "42", dict(sub=dict(subkey=dict(subsubkey="42"))), True), + (["sub"], "overwrite", dict(sub="overwrite"), True) ) @ddt.unpack def test_set_setting_string(self, key, value, update, expected_returnvalue):