diff --git a/.eslintrc.yaml b/.eslintrc.yaml new file mode 100644 index 000000000..c34fe2339 --- /dev/null +++ b/.eslintrc.yaml @@ -0,0 +1,40 @@ +overrides: + - files: + - "src/octoprint/static/js/app/**" + env: + browser: true + jquery: true + parserOptions: + ecmaVersion: 5 + rules: + es5/no-arrow-functions: error + es5/no-binary-and-octal-literals: error + es5/no-block-scoping: error + es5/no-classes: error + es5/no-computed-properties: error + es5/no-default-parameters: error + es5/no-destructuring: error + es5/no-exponentiation-operator: error + es5/no-for-of: error + es5/no-generators: error + es5/no-modules: error + es5/no-object-super: error + es5/no-rest-parameters: error + es5/no-shorthand-properties: error + es5/no-spread: error + es5/no-template-literals: error + es5/no-typeof-symbol: error + es5/no-unicode-code-point-escape: error + es5/no-unicode-regex: error + - files: + - "tests/cypress/**" + env: + node: true + es6: true + cypress/globals: true + extends: + - "plugin:cypress/recommended" + +plugins: + - eslint-plugin-es5 + - cypress diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 6e56ba502..e0816d0f9 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -58,6 +58,17 @@ inputs: - No, it did not persist (it's an issue with one of your installed plugins, don't report here) - I cannot test this issue in safe mode (state why below) required: true + - type: input + attributes: + label: If you could not test in safe mode, please state why + description: >- + Issues caused by a third party plugin are a major cause of bugs reported here, so we really need to + rule out that a plugin is at fault here. [Safe mode](https://docs.octoprint.org/en/master/features/safemode.html) is an easy way to do that. Only skip safe mode + if your particular problem *absolutely requires* third party plugins to be enabled. "It would take + too long" is **not** a reason to skip testing in safe mode, neither is "I do not know how to + enable it" as you can find info on that [here](https://docs.octoprint.org/en/master/features/safemode.html). + + If you really *cannot* test in safe mode, leave a short explanation as to why. - type: description attributes: value: | @@ -92,10 +103,10 @@ inputs: value: >- Please also be sure to upload the following files below: - * `octoprint.log`: See [here](https://community.octoprint.org/t/where-can-i-find-octoprints-and-octopis-log-files/299) if you don't know where to find that. + * `octoprint.log`: See [here](https://community.octoprint.org/t/where-can-i-find-octoprints-and-octopis-log-files/299) if you don't know where to find that. Just attach down below as-is. * `serial.log` or the contents of your terminal tab, if applicable. Always include if unsure. **Please note that you need to enable `serial.log` first**, - see [here](https://community.octoprint.org/t/where-can-i-find-octoprints-and-octopis-log-files/299) if you don't know how to do or where to find it. + see [here](https://community.octoprint.org/t/where-can-i-find-octoprints-and-octopis-log-files/299) if you don't know how to do or where to find it. Just attach down below as-is. * Your browser's JavaScript console, if you are reporting a problem with the user interface. See [here](https://webmasters.stackexchange.com/questions/8525/how-to-open-the-javascript-console-in-different-browsers) on where to find that. * If possible, screenshots or videos showing the problem, especially if you diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1116d1640..e34fb27e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,22 +46,6 @@ jobs: run: | pre-commit run --hook-stage manual black --all-files --show-diff-on-failure - lint-prettier: - name: ๐Ÿงน prettier - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: ๐Ÿ— Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: ๐Ÿ— Set up dev dependencies - run: | - pip install -e .[develop] - - name: ๐Ÿš€ Run prettier - run: | - pre-commit run --hook-stage manual prettier --all-files --show-diff-on-failure - lint-isort: name: ๐Ÿงน isort runs-on: ubuntu-latest @@ -94,6 +78,38 @@ jobs: run: | pre-commit run --hook-stage manual flake8 --all-files + lint-prettier: + name: ๐Ÿงน prettier + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: ๐Ÿ— Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: ๐Ÿ— Set up dev dependencies + run: | + pip install -e .[develop] + - name: ๐Ÿš€ Run prettier + run: | + pre-commit run --hook-stage manual prettier --all-files --show-diff-on-failure + + lint-eslint: + name: ๐Ÿงน eslint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: ๐Ÿ— Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: ๐Ÿ— Set up dev dependencies + run: | + pip install -e .[develop] + - name: ๐Ÿš€ Run eslint + run: | + pre-commit run --hook-stage manual eslint --all-files + test-unit: name: ๐Ÿงช Unit tests strategy: @@ -192,9 +208,10 @@ jobs: if: github.event_name == 'release' needs: - lint-black - - lint-prettier - lint-isort - lint-flake8 + - lint-prettier + - lint-eslint - test-unit - test-install - test-e2e diff --git a/.github/workflows/nightly_merge.yml b/.github/workflows/nightly_merge.yml new file mode 100644 index 000000000..4d54ff64c --- /dev/null +++ b/.github/workflows/nightly_merge.yml @@ -0,0 +1,33 @@ +name: "Nightly merge" + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + nightly-merge: + runs-on: ubuntu-latest + steps: + - name: โฌ‡ Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: ๐Ÿ”€ Merge master into maintenance + uses: robotology/gh-action-nightly-merge@v1.3.2 + with: + stable_branch: "master" + development_branch: "maintenance" + allow_ff: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + #- name: ๐Ÿ”€ Merge maintenance into devel + # uses: robotology/gh-action-nightly-merge@v1.3.2 + # with: + # stable_branch: "maintenance" + # development_branch: "devel" + # allow_ff: false + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 90d2be578..37c9c1c5d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -52,3 +52,13 @@ repos: rev: v2.1.2 hooks: - id: prettier + - repo: https://github.com/pre-commit/mirrors-eslint + rev: v7.19.0 + hooks: + - id: eslint + additional_dependencies: + - eslint@7.19.0 + - eslint-plugin-es5@v1.3.0 + - eslint-plugin-cypress@2.11.2 + files: \.js$ + exclude: ^(src/octoprint/vendor/|tests/static/js/lib|tests/util/_files|docs/|scripts/|translations/) diff --git a/THIRDPARTYLICENSES.md b/THIRDPARTYLICENSES.md index f3c0cb7f9..80556b1cb 100644 --- a/THIRDPARTYLICENSES.md +++ b/THIRDPARTYLICENSES.md @@ -4,6 +4,7 @@ * [AVLTree](https://gist.github.com/viking/2424106) (modified): GPL, LGPL (dual licensed) * [Babel JavaScript Support](https://github.com/mitsuhiko/babel/blob/master/contrib/babel.js): BSD + * [@babel/polyfill](https://babeljs.io/docs/en/babel-polyfill/): MIT * [Bootstrap](http://getbootstrap.com/): Apache License 2.0 * [Bootstrap Modal](http://jschr.github.io/bootstrap-modal/): Apache License 2.0 * [Bootstrap Slider Knockout Binding](https://github.com/cosminstefanxp/bootstrap-slider-knockout-binding): MIT diff --git a/docs/api/push.rst b/docs/api/push.rst index c9c6a4b04..5210ad599 100644 --- a/docs/api/push.rst +++ b/docs/api/push.rst @@ -68,6 +68,23 @@ OctoPrint's SockJS socket also accepts two commands from the client to the serve "auth": "someuser:LGZ0trf8By" } + An example for an auth roundtrip with only an API key using the :ref:`JS Client Library ` + can be found :ref:`here `. + + .. mermaid:: + + sequenceDiagram + participant Client + participant API + participant Websocket + + Client->>API: GET /api/login?passive=true&apikey=... + API->>Client: { name: ..., session: ..., ... } + + note over Client: auth = name ":" session + + Client->>Websocket: { "auth": auth } + * ``throttle``: Usually, OctoPrint will push the general state update in the ``current`` message twice per second. For some clients that might still be too fast, so they can signal a different factor to OctoPrint utilizing the diff --git a/docs/development/environment.rst b/docs/development/environment.rst index e286e8010..2af58027c 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -1,14 +1,15 @@ .. _sec-development-environment: +************************************ Setting up a Development environment -==================================== +************************************ .. _sec-development-environment-source: Obtaining, building and running the source ------------------------------------------- +========================================== -This describes the general steps in obtaining, building and running. OS specific instructions can be found +This describes the **general, platform agnostic** steps in obtaining, building and running. OS specific instructions can be found below. * Prerequisites: @@ -77,10 +78,11 @@ Go to the directory `docs` and you can then build the documentation: * ``sphinx-build -b html . _build`` The documentation will be available in the newly created ``_build`` directory. You can simply browse it locally by opening ``index.html`` + .. _sec-development-environment-source-linux: Linux -..... +----- This assumes you'll host your OctoPrint development checkout at ``~/devel/OctoPrint``. If you want to use a different location, please substitute accordingly. @@ -119,7 +121,7 @@ You can then start OctoPrint via ``octoprint`` after activating one of the two v .. _sec-development-environment-windows: Windows -....... +------- This assumes you'll host your OctoPrint development checkout at ``C:\Devel\OctoPrint``. If you want to use a different location, please substitute accordingly. @@ -131,8 +133,13 @@ First download & install: * make sure to have the installer add Python to the ``PATH`` and have it install ``pip`` too * it's recommended to install Python 2.7 into ``C:\Python27`` and Python 3 into ``C:\Python38`` - if you select different install locations please substitute accordingly + * it's also recommended to have both versions get installed for all users * `Build Tools for Visual Studio 2019 `_ + + * install "C++ build tools" and ensure the latest versions of "MSVCv142 - VS 2019 C++ x64/x86 build tools" and + "Windows 10 SDK" are checked. + * `Git for Windows `_ Open the Git Bash you just installed and in that: @@ -145,15 +152,40 @@ Open the Git Bash you just installed and in that: cd OctoPrint virtualenv --python=C:\Python38\python.exe venv source ./venv/Scripts/activate - pip install --upgrade pip - pip install -e .[develop,plugins,docs] + python -m pip install --upgrade pip + python -m pip install -e .[develop,plugins,docs] pre-commit install git config blame.ignoreRevsFile .git-blame-ignore-revs +.. _sec-development-environment-windows-optional: + +Optional but recommended tools +.............................. + +These are some tools that are recommended but not required to have on hand: + + * `Visual Studio Code `_ + * `Windows Terminal `_ + + Add the following profile to ``profiles.list`` in the settings, that will allow you to + easily start Git Bash from the terminal: + + .. code-block:: js + + { + "guid": "{3df4550c-eebd-496c-a189-e55f2f8b01ce}", + "hidden": false, + "name": "Git Bash", + "commandline": "C:\\Program Files\\Git\\bin\\bash.exe --login -i", + "startingDirectory": "C:\\Devel", + "tabTitle": "Git Bash", + "suppressApplicationTitle": true + }, + .. _sec-development-environment-mac: Mac OS X -........ +-------- .. note:: @@ -204,7 +236,7 @@ You'll need a user account with administrator privileges. .. _sec-development-environment-ides: IDE Setup ---------- +========= .. todo:: @@ -215,7 +247,7 @@ IDE Setup .. _sec-development-environment-ides-pycharm: PyCharm -....... +------- - "File" > "Open ...", select OctoPrint checkout folder (e.g. ``~/devel/OctoPrint`` or ``C:\Devel\OctoPrint``) - Register virtual environments: diff --git a/docs/features/accesscontrol.rst b/docs/features/accesscontrol.rst index 23bf90b75..62a548768 100644 --- a/docs/features/accesscontrol.rst +++ b/docs/features/accesscontrol.rst @@ -177,6 +177,7 @@ further down there's also a dedicated list of steps for OctoPi specifically. salt line): .. code-block:: yaml + accessControl: salt: aabbccddee1234523452345 autologinLocal: true diff --git a/docs/jsclientlib/base.rst b/docs/jsclientlib/base.rst index 63833f0dc..37416fd10 100644 --- a/docs/jsclientlib/base.rst +++ b/docs/jsclientlib/base.rst @@ -14,13 +14,13 @@ The client library instance's options. The following keys are currently supported: - ``apikey`` - The API Key to use for requests against the OctoPrint API. Should usually be - the anonymous UI API Key provided on the socket. - ``baseurl`` The base URL of the OctoPrint API + ``apikey`` + The API Key to use for requests against the OctoPrint API. If left unset, you'll + need to authenticate your session through a login. + ``locale`` The locale to set in ``X-Locale`` headers on API requests. Useful for API endpoints that might return localized content. diff --git a/docs/jsclientlib/browser.rst b/docs/jsclientlib/browser.rst index d44ba08bf..e71c26a60 100644 --- a/docs/jsclientlib/browser.rst +++ b/docs/jsclientlib/browser.rst @@ -29,6 +29,25 @@ Tries to perform a passive login into OctoPrint, using existing session data stored in the browser's cookies. + .. code-block:: javascript + + OctoPrint.browser.passiveLogin() + .done(function(response) { + // do something with the response + }) + + .. code-block:: javascript + + var client = new OctoPrintClient({ + baseurl: "https://example.com/", + apikey: "..." + }); + client.browser.passiveLogin() + .done(function(response) { + // do something with the response, e.g. authenticate with the socket + // via response.name and response.session + }) + :param object opts: Additional request options :returns Promise: A `jQuery Promise `_ for the request's response diff --git a/docs/jsclientlib/index.rst b/docs/jsclientlib/index.rst index 43b734769..280b3c241 100644 --- a/docs/jsclientlib/index.rst +++ b/docs/jsclientlib/index.rst @@ -40,6 +40,12 @@ because the library depends on those to be available (as ``$`` and ``_``). You c +Moreover, if you need to use the socket module, you'll need to include sockJS. You can embed it like this: + +.. code-block:: html+jinja + + + Note that all components depend on the ``base`` component to be present, so if you are only including a select number of components, make sure to at the very least include that one to be able to utilize the client. diff --git a/docs/jsclientlib/socket.rst b/docs/jsclientlib/socket.rst index 925528490..fc4223546 100644 --- a/docs/jsclientlib/socket.rst +++ b/docs/jsclientlib/socket.rst @@ -64,12 +64,24 @@ Sends a message of type ``type`` with the provided ``payload`` to the server. - Note that at the time of writing, OctoPrint only supports the ``throttle`` message. See + Note that at the time of writing, OctoPrint only supports the ``throttle`` and ``auth`` messages. See also the :ref:`Push API documentation `. :param string type: Type of message to send :param object payload: Payload to send +.. js:function:: OctoPrintClient.socket.sendAuth(userId, session) + + Sends an ``auth`` message with the provided ``userId`` and ``session`` to the server. + + ``session`` is expected to be the ``session`` value retrieved + from any valid :ref:`OctoPrint.browser.login(userId,...) ` response. + + See also the :ref:`Push API documentation `. + + :param string userId: An existing OctoPrint username + :param string session: A valid session id for the provided username + .. js:function:: OctoPrintClient.socket.onRateTooLow(measured, minimum) Called by the socket client when the measured message round trip times have been lower than @@ -102,6 +114,35 @@ Instructs the server to decrease the message rate by 500ms. +.. _sec-jsclient-socket-authsample: + +Sample to setup an authed socket +================================ + +If you have a username and a password: + +.. code-block:: javascript + + OctoPrint.socket.connect(); + OctoPrint.browser.login("myusername", "mypassword", true) + .done(function(response) { + OctoPrint.socket.sendAuth("myusername", response.session); + }); + +If you have an API key: + +.. code-block:: javascript + + var client = new OctoPrintClient({ + baseurl: "http://example.com/", + apikey: "abcdef" + }); + client.socket.connect(); + client.browser.passiveLogin() + .done(function(response) { + client.socket.sendAuth(response.name, response.session); + }); + .. _sec-jsclient-socket-throttling: Communication Throttling diff --git a/src/octoprint/access/groups.py b/src/octoprint/access/groups.py index bb8ffef27..d63363ff6 100644 --- a/src/octoprint/access/groups.py +++ b/src/octoprint/access/groups.py @@ -347,7 +347,7 @@ class FilebasedGroupManager(GroupManager): import yaml yaml.safe_dump( - data, f, default_flow_style=False, indent=4, allow_unicode=True + data, f, default_flow_style=False, indent=2, allow_unicode=True ) self._dirty = False self._load() diff --git a/src/octoprint/access/users.py b/src/octoprint/access/users.py index 62b61959f..feacd6722 100644 --- a/src/octoprint/access/users.py +++ b/src/octoprint/access/users.py @@ -605,7 +605,7 @@ class FilebasedUserManager(UserManager): self._userfile, mode="wt", permissions=0o600, max_permissions=0o666 ) as f: yaml.safe_dump( - data, f, default_flow_style=False, indent=4, allow_unicode=True + data, f, default_flow_style=False, indent=2, allow_unicode=True ) self._dirty = False self._load() diff --git a/src/octoprint/cli/analysis.py b/src/octoprint/cli/analysis.py index 8b8f48a9f..1b335aa76 100644 --- a/src/octoprint/cli/analysis.py +++ b/src/octoprint/cli/analysis.py @@ -140,7 +140,7 @@ def gcode_command( yaml.safe_dump( interpreter.get_result(), default_flow_style=False, - indent=4, + indent=2, allow_unicode=True, ) ) diff --git a/src/octoprint/cli/config.py b/src/octoprint/cli/config.py index 90349a365..7af142247 100644 --- a/src/octoprint/cli/config.py +++ b/src/octoprint/cli/config.py @@ -215,7 +215,7 @@ def get_command(ctx, path, as_json=False, as_yaml=False, as_raw=False): output = json.dumps(value) elif as_yaml: output = yaml.safe_dump( - value, default_flow_style=False, indent=4, allow_unicode=True + value, default_flow_style=False, indent=2, allow_unicode=True ) elif as_raw: output = value @@ -241,7 +241,7 @@ def effective_command(ctx, as_json=False, as_yaml=False, as_raw=False): output = json.dumps(value) elif as_yaml: output = yaml.safe_dump( - value, default_flow_style=False, indent=4, allow_unicode=True + value, default_flow_style=False, indent=2, allow_unicode=True ) elif as_raw: output = value diff --git a/src/octoprint/environment.py b/src/octoprint/environment.py index 47356c9e8..59e7cd65f 100644 --- a/src/octoprint/environment.py +++ b/src/octoprint/environment.py @@ -166,7 +166,7 @@ class EnvironmentDetector: environment = copy.deepcopy(self._cache) dumped_environment = yaml.safe_dump( - environment, default_flow_style=False, indent=4, allow_unicode=True + environment, default_flow_style=False, indent=2, allow_unicode=True ).strip() environment_lines = "\n".join( map(lambda l: "| {}".format(l), dumped_environment.split("\n")) diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index 240de8f5b..c75b75a68 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -1864,7 +1864,7 @@ class LocalFileStorage(StorageInterface): try: with atomic_write(metadata_path, mode="wb") as f: f.write( - to_bytes(json.dumps(metadata, indent=4, separators=(",", ": "))) + to_bytes(json.dumps(metadata, indent=2, separators=(",", ": "))) ) except Exception: self._logger.exception( @@ -1938,7 +1938,7 @@ class LocalFileStorage(StorageInterface): return with atomic_write(metadata_path_json, mode="wb") as f: - f.write(to_bytes(json.dumps(metadata, indent=4, separators=(",", ": ")))) + f.write(to_bytes(json.dumps(metadata, indent=2, separators=(",", ": ")))) try: os.remove(metadata_path_yaml) diff --git a/src/octoprint/logging/filters.py b/src/octoprint/logging/filters.py index 6214ceb72..fcd545ae0 100644 --- a/src/octoprint/logging/filters.py +++ b/src/octoprint/logging/filters.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, division, print_function, unicode_literals - import logging try: diff --git a/src/octoprint/plugins/backup/__init__.py b/src/octoprint/plugins/backup/__init__.py index e59bfa2ac..0ad10d229 100644 --- a/src/octoprint/plugins/backup/__init__.py +++ b/src/octoprint/plugins/backup/__init__.py @@ -45,12 +45,15 @@ from flask_babel import gettext from octoprint.plugins.pluginmanager import DEFAULT_PLUGIN_REPOSITORY from octoprint.settings import valid_boolean_trues +from octoprint.util import get_formatted_size from octoprint.util.text import sanitize UNKNOWN_PLUGINS_FILE = "unknown_plugins_from_restore.json" BACKUP_DATE_TIME_FMT = "%Y%m%d-%H%M%S" +MAX_UPLOAD_SIZE = 1024 * 1024 * 1024 # 1GB + class BackupPlugin( octoprint.plugin.SettingsPlugin, @@ -118,6 +121,12 @@ class BackupPlugin( {"type": "wizard", "name": gettext("Restore Backup?")}, ] + def get_template_vars(self): + return { + "max_upload_size": MAX_UPLOAD_SIZE, + "max_upload_size_str": get_formatted_size(MAX_UPLOAD_SIZE), + } + ##~~ BlueprintPlugin @octoprint.plugin.BlueprintPlugin.route("/", methods=["GET"]) @@ -131,6 +140,7 @@ class BackupPlugin( backup_in_progress=len(self._in_progress) > 0, unknown_plugins=unknown_plugins, restore_supported=self._restore_supported(self._settings), + max_upload_size=MAX_UPLOAD_SIZE, ) @octoprint.plugin.BlueprintPlugin.route("/unknown_plugins", methods=["GET"]) @@ -385,8 +395,8 @@ class BackupPlugin( ] def bodysize_hook(self, current_max_body_sizes, *args, **kwargs): - # max upload size of 1GB for the restore endpoint - return [("POST", r"/restore", 1024 * 1024 * 1024)] + # max upload size for the restore endpoint + return [("POST", r"/restore", MAX_UPLOAD_SIZE)] # Exported plugin helpers def create_backup_helper(self, exclude=None, filename=None): @@ -1136,8 +1146,8 @@ class BackupPlugin( metadata_bytes = zip.read(metadata_zipinfo) metadata = json.loads(metadata_bytes) - backup_version = get_comparable_version(metadata["version"], base=True) - if backup_version > get_octoprint_version(base=True): + backup_version = get_comparable_version(metadata["version"], cut=1) + if backup_version > get_octoprint_version(cut=1): if callable(on_invalid_backup): on_invalid_backup( "Backup is from a newer version of OctoPrint and cannot be applied" diff --git a/src/octoprint/plugins/backup/static/js/backup.js b/src/octoprint/plugins/backup/static/js/backup.js index 5f1894efd..436f699d9 100644 --- a/src/octoprint/plugins/backup/static/js/backup.js +++ b/src/octoprint/plugins/backup/static/js/backup.js @@ -27,10 +27,15 @@ $(function () { self.excludeFromBackup = ko.observableArray([]); self.backupInProgress = ko.observable(false); self.restoreSupported = ko.observable(true); + self.maxUploadSize = ko.observable(0); self.backupUploadData = undefined; self.backupUploadName = ko.observable(); + self.isAboveUploadSize = function (data) { + return data.size > self.maxUploadSize(); + }; + var backupFileuploadOptions = { dataType: "json", maxNumberOfFiles: 1, @@ -70,6 +75,7 @@ $(function () { self.backups.updateItems(response.backups); self.unknownPlugins(response.unknown_plugins); self.restoreSupported(response.restore_supported); + self.maxUploadSize(response.max_upload_size); }; self.createBackup = function () { diff --git a/src/octoprint/plugins/backup/templates/backup_settings.jinja2 b/src/octoprint/plugins/backup/templates/backup_settings.jinja2 index d6fdede80..50077d250 100644 --- a/src/octoprint/plugins/backup/templates/backup_settings.jinja2 +++ b/src/octoprint/plugins/backup/templates/backup_settings.jinja2 @@ -45,7 +45,7 @@ - +  |  |  @@ -61,6 +61,17 @@
  • ยป
  • + +

    + {{ _("Note:") }} + {% trans marker="" %} + OctoPrint currently only allows uploading backups of a maximum size of + {{ plugin_backup_max_upload_size_str }} via the UI. Backups larger than this can only be restored by command line, + or by adjusting the size by removing large contents (like timelapses) from the + zip prior to uploading. Backups exceeding this size limit are marked with a + {{ marker }} up there. + {% endtrans %} +

    {{ _('Create backup') }}

    diff --git a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js index 6fb9ba4e3..c462bc1c3 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js @@ -879,8 +879,8 @@ $(function () { self.resetOptions(); var current = loadFromLocalStorage(optionsLocalStorageKey); - if (current["centerViewport"] !== undefined) - self.renderer_centerViewport(current["centerViewport"]); + if (current["centerViewPort"] !== undefined) + self.renderer_centerViewport(current["centerViewPort"]); if (current["zoomOnModel"] !== undefined) self.renderer_zoomOnModel(current["zoomOnModel"]); if (current["showMoves"] !== undefined) diff --git a/src/octoprint/plugins/logging/static/js/logging.js b/src/octoprint/plugins/logging/static/js/logging.js index 05a17bf54..53052f376 100644 --- a/src/octoprint/plugins/logging/static/js/logging.js +++ b/src/octoprint/plugins/logging/static/js/logging.js @@ -97,10 +97,10 @@ $(function () { levels.push(item); configuredLoggers.push(logger); }); - let sortedLevels = _.sortBy(levels, function (o) { + var sortedLevels = _.sortBy(levels, function (o) { return o.component; }); - self.configuredLoggers(levels); + self.configuredLoggers(sortedLevels); // loggers var availableLoggers = _.difference(response.loggers, configuredLoggers); diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index f0c88cb24..b3949b0ff 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -29,7 +29,11 @@ from octoprint.server.util.flask import ( ) from octoprint.util import dict_merge, get_formatted_size, to_unicode from octoprint.util.pip import create_pip_caller -from octoprint.util.version import get_comparable_version, get_python_version_string +from octoprint.util.version import ( + get_comparable_version, + get_python_version_string, + is_python_compatible, +) from . import cli, exceptions, updaters, util, version_checks @@ -367,23 +371,33 @@ class SoftwareUpdatePlugin( or self._overlay_cache_timestamp + self._overlay_cache_ttl < time.time() ) + def _get_check_overlay(self, url): + self._logger.info("Fetching check overlays from {}".format(url)) + try: + r = requests.get(url, timeout=3.1) + r.raise_for_status() + data = r.json() + except Exception as exc: + self._logger.error( + "Could not fetch check overlay from {}: {}".format(url, exc) + ) + return {} + else: + return data + def _get_check_overlays(self, force=False): if self._check_overlays_stale or force: if self._connectivity_checker.online: - # reload from URL - url = self._settings.get(["check_overlay_url"]) - self._logger.info("Fetching check overlays from {}".format(url)) - try: - r = requests.get(url, timeout=3.1) - r.raise_for_status() - data = r.json() - except Exception as exc: - self._logger.error( - "Could not fetch check overlay from {}: {}".format(url, exc) + self._overlay_cache = self._get_check_overlay( + self._settings.get(["check_overlay_url"]) + ) + if is_python_compatible("<3"): + data = self._get_check_overlay( + self._settings.get(["check_overlay_py2_url"]) + ) + self._overlay_cache = octoprint.util.dict_merge( + self._overlay_cache, data ) - self._overlay_cache = {} - else: - self._overlay_cache = data else: self._logger.info("Not fetching check overlays, we are offline") @@ -530,6 +544,7 @@ class SoftwareUpdatePlugin( "ignore_throttled": False, "minimum_free_storage": 150, "check_overlay_url": "https://plugins.octoprint.org/update_check_overlay.json", + "check_overlay_py2_url": "https://plugins.octoprint.org/update_check_overlay_py2.json", "check_overlay_ttl": 6 * 60, "credentials": { "github": None, @@ -1331,6 +1346,7 @@ class SoftwareUpdatePlugin( ) target_disabled = populated_check.get("disabled", False) + target_compatible = populated_check.get("compatible", True) update_available = update_available or ( target_update_available and not target_disabled ) @@ -1380,6 +1396,7 @@ class SoftwareUpdatePlugin( "online": target_online, "error": target_error, "disabled": target_disabled, + "compatible": target_compatible, "releaseChannels": {}, } @@ -1485,6 +1502,9 @@ class SoftwareUpdatePlugin( update_available = False error = None + disabled = check.get("disabled", False) + compatible = check.get("compatible", True) + try: version_checker = self._get_version_checker(target, check) information, is_current = version_checker.get_latest( @@ -1501,7 +1521,7 @@ class SoftwareUpdatePlugin( ) del self._version_cache[target] self._version_cache_dirty = True - elif not is_current: + elif not is_current and compatible: update_available = True except exceptions.CannotCheckOffline: update_possible = False @@ -1539,15 +1559,15 @@ class SoftwareUpdatePlugin( else: try: updater = self._get_updater(target, check) - update_possible = updater.can_perform_update(target, check, online=online) + update_possible = compatible and updater.can_perform_update( + target, check, online=online + ) except Exception: self._logger.exception( "Error while checking if {} can be updated".format(target) ) update_possible = False - disabled = check.get("disabled", False) - self._version_cache[target] = { "timestamp": time.time(), "hash": current_hash, @@ -1557,6 +1577,7 @@ class SoftwareUpdatePlugin( "online": online, "error": error, "disabled": disabled, + "compatible": compatible, } self._version_cache_dirty = True return information, update_available, update_possible, online, error @@ -1638,7 +1659,7 @@ class SoftwareUpdatePlugin( continue check = checks[target] - if "enabled" in check and not check["enabled"]: + if not check.get("enabled", True) or not check.get("compatible", True): continue if target not in check_targets: @@ -1731,8 +1752,17 @@ class SoftwareUpdatePlugin( if not update_possible: self._logger.warning( - "Cannot perform update for %s, update type is not fully configured" - % target + "Cannot perform update for {}, update type is not fully configured".format( + target + ) + ) + return False, None + + if not information.get("compatible", True): + self._logger.warning( + "Cannot perform update for {}, update is reported as incompatible".format( + target + ) ) return False, None diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index ddaef83a5..b090c2651 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -386,7 +386,11 @@ $(function () { text += "