diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 229f4b4a6..4970021e3 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,8 +1,10 @@ READ THE FOLLOWING FIRST: If not already done, please read the "guidelines for contributing" -that are linked ^-- just up there in the big yellow box. Also read -the FAQ: https://github.com/foosel/OctoPrint/wiki/FAQ. +aka the Contribution Guidelines that are linked ^-- just up there +in the big yellow box. + +Also read the FAQ: https://github.com/foosel/OctoPrint/wiki/FAQ. This is a bug and feature tracker, please only use it to report bugs or request features within OctoPrint (not OctoPi, not any OctoPrint @@ -14,18 +16,18 @@ for contributing" linked above, read it!), NOT here. Mark requests with a "[Request]" prefix in the title please. Fully fill out the bug reporting template for bug reports (if you don't know where -to find some information - it's all described in the contribution -guidelines linked up there in the big yellow box). +to find some information - it's all described in the Contribution +Guidelines linked up there in the big yellow box). -When reporting a bug do NOT delete any lines from the template but +When reporting a bug do NOT delete ANY lines from the template but those enclosed in [ and ] - and those please DO delete, they are only provided for your information and removing them makes your ticket more readable :) -Make sure any bug you want to repor tis still present with the CURRENT +Make sure any bug you want to report is still present with the CURRENT OctoPrint version and that it does not vanish when you start OctoPrint -in safe mode - how to do that is also explained in the contribution -guidelines linked up there in the big yellow box. +in safe mode - how to do that is also explained in the Contribution +Guidelines linked up there in the big yellow box. Thank you! @@ -37,15 +39,27 @@ by heart ;)) #### What were you doing? -[Please describe the steps to reproduce your issue. Be as specific as -possible here. The maintainers will need to reproduce your issue in -order to fix it and that is not possible if they don't know what you -did to get it to happen in the first place. +[Please be as specific as possible here. The maintainers will need to +reproduce your issue in order to fix it and that is not possible if they +don't know what you did to get it to happen in the first place. + +Ideally provide exact steps to follow in order to reproduce your problem: + +1. ... +2. ... +3. ... If you encountered a problem with specific files of any sorts, make sure to also include a link to a file with which to reproduce the problem.] -#### What did you expect to happen and what happened instead? +#### What did you expect to happen? + +#### What happened instead? + +#### Did the same happen when running OctoPrint in safe mode? + +[Try to reproduce your problem in safe mode. You can find information +on how to enable safe mode in the Contribution Guidelines.] #### Branch & Commit or Version of OctoPrint @@ -53,7 +67,8 @@ to also include a link to a file with which to reproduce the problem.] #### Operating System running OctoPrint -[OctoPi, Linux, Windows, MacOS, something else? With version please.] +[OctoPi, Linux, Windows, MacOS, something else? With version please. +OctoPi's version can be found in /etc/octopi_version] #### Printer model & used firmware incl. version @@ -61,17 +76,17 @@ to also include a link to a file with which to reproduce the problem.] #### Browser and Version of Browser, Operating System running Browser -[If applicable, always include if unsure or reporting UI issues.] +[If applicable, always include if unsure.] #### Link to octoprint.log -[On gist.github.com or pastebin.com. ALWAYS INCLUDE and never truncate.] +[On gist.github.com or pastebin.com. ALWAYS INCLUDE and never truncate. +The Contribution Guidelines tell you where to find that.] #### Link to contents of terminal tab or serial.log [On gist.github.com or pastebin.com. If applicable, always include if unsure or -reporting any kind of communication issues between OctoPrint and your printer. -Never truncate. +reporting communication issues. Never truncate. serial.log is usually not written due to performance reasons and must be enabled explicitly. Provide at the very least the FULL contents of your @@ -81,9 +96,11 @@ a serial.log.] #### Link to contents of Javascript console in the browser [On gist.github.com or pastebin.com or alternatively a screenshot. If applicable - -always include if unsure or reporting UI issues.] +always include if unsure or reporting UI issues. -#### Screenshot(s) or video(s) showing the problem: +The Contribution Guidelines tell you where to find that.] + +#### Screenshot(s)/video(s) showing the problem: [If applicable. Always include if unsure or reporting UI issues.] diff --git a/AUTHORS.md b/AUTHORS.md index bae6a0750..87c28789c 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -80,6 +80,7 @@ date of first contribution): * [Greg Hulands](https://github.com/ghulands) * [Andreas Werner](https://github.com/gallore) * [Shawn Bruce](https://github.com/kantlivelong) + * [Claudiu Ceia] (https://github.com/ClaudiuCeia) 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/CONTRIBUTING.md b/CONTRIBUTING.md index 1f8020221..4e3a47439 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -142,6 +142,12 @@ only provided here as some additional information for you), **even if only addin reproduce your issue in order to fix it and that is not possible if they don't know what you did to get it to happen in the first place. + Ideally provide exact steps to follow in order to reproduce your problem: + + 1. ... + 2. ... + 3. ... + If you encountered a problem with specific files of any sorts, make sure to also include a link to a file with which to reproduce the problem.] @@ -149,10 +155,20 @@ only provided here as some additional information for you), **even if only addin #### What happened instead? + #### Did the same happen when running OctoPrint in safe mode? + + [Try to reproduce your problem in safe mode. You can find information + on how to enable safe mode in the Contribution Guidelines.] + #### Branch & Commit or Version of OctoPrint [Can be found in the lower left corner of the web interface. ALWAYS INCLUDE.] + #### Operating System running OctoPrint + + [OctoPi, Linux, Windows, MacOS, something else? With version please, + OctoPi's version can be found in /etc/octopi_version] + #### Printer model & used firmware incl. version [If applicable, always include if unsure.] @@ -163,7 +179,8 @@ only provided here as some additional information for you), **even if only addin #### Link to octoprint.log - [On gist.github.com or pastebin.com. ALWAYS INCLUDE and never truncate.] + [On gist.github.com or pastebin.com. ALWAYS INCLUDE and never truncate. + The Contribution Guidelines tell you where to find that.] #### Link to contents of terminal tab or serial.log @@ -178,16 +195,19 @@ only provided here as some additional information for you), **even if only addin #### Link to contents of Javascript console in the browser [On gist.github.com or pastebin.com or alternatively a screenshot. If applicable - - always include if unsure or reporting UI issues.] + always include if unsure or reporting UI issues. - #### Screenshot(s) showing the problem: + The Contribution Guidelines tell you where to find that.] + + #### Screenshot(s)/video(s) showing the problem: [If applicable. Always include if unsure or reporting UI issues.] I have read the FAQ. -Copy-paste this template **completely**. Do not skip any lines or the bot -*will* complain! +Copy-paste this template **completely** (or use the version that gets pre-filled +into the "new issue" form). Do not skip any lines or the bot *will* complain! Provide +all requested information or your ticket will be closed. ### Where can I find which version and branch I'm on? @@ -405,6 +425,7 @@ the local version identifier to allow for an exact determination of the active c * 2017-03-09: Allow PRs against `maintenance` branch for bugs in stable. * 2017-03-10: Reproduce bugs in safe mode to make sure they are really caused by OctoPrint itself and not a misbehaving plugin. + * 2017-03-27: Added safe mode section to ticket template. ## Footnotes * [1] - If you are wondering why, the problem is that anything that you add diff --git a/docs/events/index.rst b/docs/events/index.rst index 802ed3856..b471193f5 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -152,7 +152,7 @@ File handling ------------- Upload - A file has been uploaded. + A file has been uploaded through the web interface. Payload: * ``name``: the file's name @@ -165,19 +165,74 @@ Upload Still available for reasons of backwards compatibility. Will be removed with 1.4.0. +FileAdded + A file has been added to a storage. + + Payload: + * ``storage``: the storage's identifier + * ``path``: the file's path within its storage location + * ``name``: the file's name + * ``type``: the file's type, a list of the path within the type hierarchy, e.g. ``["machinecode", "gcode"]`` or + ``["model", "stl"]`` + + .. note:: + + A copied file triggers this for its new path. A moved file first triggers ``FileRemoved`` for its original + path and then ``FileAdded`` for the new one. + +FileRemoved + A file has been removed from a storage. + + Payload: + * ``storage``: the storage's identifier + * ``path``: the file's path within its storage location + * ``name``: the file's name + * ``type``: the file's type, a list of the path within the type hierarchy, e.g. ``["machinecode", "gcode"]`` or + ``["model", "stl"]`` + + .. note:: + + A moved file first triggers ``FileRemoved`` for its original path and then ``FileAdded`` for the new one. + +FolderAdded + A folder has been added to a storage. + + Payload: + * ``storage``: the storage's identifier + * ``path``: the folders's path within its storage location + * ``name``: the folders's name + + .. note:: + + A copied folder triggers this for its new path. A moved folder first triggers ``FolderRemoved`` for its original + path and then ``FolderAdded`` for the new one. + +FolderRemoved + A folder has been removed from a storage. + + Payload: + * ``storage``: the storage's identifier + * ``path``: the folders's path within its storage location + * ``name``: the folders's name + + .. note:: + + A moved folder first triggers ``FolderRemoved`` for its original path and then ``FolderAdded`` for the new one. + UpdatedFiles A file list was modified. Payload: - * ``type``: the type of file list that was modified. Currently only ``printables`` and ``gcode`` (DEPRECATED) are supported here. + * ``type``: the type of file list that was modified. Only ``printables`` is supported here. See the deprecation + note below. - .. note:: + .. deprecated:: 1.2.0 + + The ``gcode`` modification type has been superceeded by ``printables``. It is currently still available for + reasons of backwards compatibility and will also be sent on modification of ``printables``. It will however + be removed with 1.4.0. - The type ``gcode`` has been renamed to ``printables`` with the introduction of a new file management layer that - supports STL files as first class citizens as well. For reasons of backwards compatibility the ``UpdatedFiles`` - event for printable files will be fired twice, once with ``type`` set to ``gcode``, once set to ``printables``. - Support for the ``gcode`` type will be removed in the next release after version 1.2.0. MetadataAnalysisStarted The metadata analysis of a file has started. diff --git a/setup.py b/setup.py index 5cf2ad466..029ac10c4 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,8 @@ INSTALL_REQUIRES = [ "chainmap>=1.0.2,<1.1", "future>=0.15,<0.16", "scandir>=1.3,<1.4", - "websocket-client>=0.40,<0.41" + "websocket-client>=0.40,<0.41", + "python-dateutil>=2.6,<2.7" ] if sys.platform == "darwin": diff --git a/src/octoprint/cli/client.py b/src/octoprint/cli/client.py index cafcd1817..070806ad6 100644 --- a/src/octoprint/cli/client.py +++ b/src/octoprint/cli/client.py @@ -29,6 +29,7 @@ def client_commands(): @client_commands.group("client", context_settings=dict(ignore_unknown_options=True)) +@click.option("--apikey", "-a", type=click.STRING) @click.option("--host", "-h", type=click.STRING) @click.option("--port", "-p", type=click.INT) @click.option("--httpuser", type=click.STRING) @@ -36,11 +37,29 @@ def client_commands(): @click.option("--https", is_flag=True) @click.option("--prefix", type=click.STRING) @click.pass_context -def client(ctx, host, port, httpuser, httppass, https, prefix): +def client(ctx, apikey, host, port, httpuser, httppass, https, prefix): """Basic API client.""" try: - ctx.obj.settings = init_settings(get_ctx_obj_option(ctx, "basedir", None), get_ctx_obj_option(ctx, "configfile", None)) - octoprint_client.init_client(ctx.obj.settings, https=https, httpuser=httpuser, httppass=httppass, host=host, port=port, prefix=prefix) + if not host or not port or not apikey: + settings = init_settings(get_ctx_obj_option(ctx, "basedir", None), get_ctx_obj_option(ctx, "configfile", None)) + + if not host: + host = settings.get(["server", "host"]) + host = host if host != "0.0.0.0" else "127.0.0.1" + if not port: + port = settings.getInt(["server", "port"]) + + if not apikey: + apikey = settings.get(["api", "key"]) + + baseurl = octoprint_client.build_base_url(https=https, + httpuser=httpuser, + httppass=httppass, + host=host, + port=port, + prefix=prefix) + + ctx.obj.client = octoprint_client.Client(baseurl, apikey) except FatalStartupError as e: click.echo(e.message, err=True) click.echo("There was a fatal error initializing the client.", err=True) @@ -60,27 +79,30 @@ def log_response(response, status_code=True, body=True, headers=False): @client.command("get") @click.argument("path") -def get(path): +@click.pass_context +def get(ctx, path): """Performs a GET request against the specified server path.""" - r = octoprint_client.get(path) + r = ctx.obj.client.get(path) log_response(r) @client.command("post_json") @click.argument("path") @click.argument("data", type=JsonStringParamType()) -def post_json(path, data): +@click.pass_context +def post_json(ctx, path, data): """POSTs JSON data to the specified server path.""" - r = octoprint_client.post_json(path, data) + r = ctx.obj.client.post_json(path, data) log_response(r) @client.command("patch_json") @click.argument("path") @click.argument("data", type=JsonStringParamType()) -def patch_json(path, data): +@click.pass_context +def patch_json(ctx, path, data): """PATCHes JSON data to the specified server path.""" - r = octoprint_client.patch(path, data, encoding="json") + r = ctx.obj.client.patch(path, data, encoding="json") log_response(r) @@ -89,7 +111,8 @@ def patch_json(path, data): @click.argument("file_path", type=click.Path(exists=True, dir_okay=False, resolve_path=True)) @click.option("--json", is_flag=True) @click.option("--yaml", is_flag=True) -def post_from_file(path, file_path, json_flag, yaml_flag): +@click.pass_context +def post_from_file(ctx, path, file_path, json_flag, yaml_flag): """POSTs JSON data to the specified server path.""" if json_flag or yaml_flag: if json_flag: @@ -100,12 +123,12 @@ def post_from_file(path, file_path, json_flag, yaml_flag): with open(file_path, "rb") as fp: data = yaml.safe_load(fp) - r = octoprint_client.post_json(path, data) + r = ctx.obj.client.post_json(path, data) else: with open(file_path, "rb") as fp: data = fp.read() - r = octoprint_client.post(path, data) + r = ctx.obj.client.post(path, data) log_response(r) @@ -117,13 +140,14 @@ def post_from_file(path, file_path, json_flag, yaml_flag): @click.option("--int", "-i", "int_params", multiple=True, nargs=2, type=click.Tuple([unicode, int])) @click.option("--float", "-f", "float_params", multiple=True, nargs=2, type=click.Tuple([unicode, float])) @click.option("--bool", "-b", "bool_params", multiple=True, nargs=2, type=click.Tuple([unicode, bool])) -def command(path, command, str_params, int_params, float_params, bool_params): +@click.pass_context +def command(ctx, path, command, str_params, int_params, float_params, bool_params): """Sends a JSON command to the specified server path.""" data = dict() params = str_params + int_params + float_params + bool_params for param in params: data[param[0]] = param[1] - r = octoprint_client.post_command(path, command, additional=data) + r = ctx.obj.client.post_command(path, command, additional=data) log_response(r, body=False) @@ -133,26 +157,29 @@ def command(path, command, str_params, int_params, float_params, bool_params): @click.option("--parameter", "-P", "params", multiple=True, nargs=2, type=click.Tuple([unicode, unicode])) @click.option("--file-name", type=click.STRING) @click.option("--content-type", type=click.STRING) -def upload(path, file_path, params, file_name, content_type): +@click.pass_context +def upload(ctx, path, file_path, params, file_name, content_type): """Uploads the specified file to the specified server path.""" data = dict() for param in params: data[param[0]] = param[1] - r = octoprint_client.upload(path, file_path, additional=data, file_name=file_name, content_type=content_type) + r = ctx.obj.client.upload(path, file_path, additional=data, file_name=file_name, content_type=content_type) log_response(r) @client.command("delete") @click.argument("path") -def delete(path): +@click.pass_context +def delete(ctx, path): """Sends a DELETE request to the specified server path.""" - r = octoprint_client.delete(path) + r = ctx.obj.client.delete(path) log_response(r) @client.command("listen") -def listen(): +@click.pass_context +def listen(ctx): def on_connect(ws): click.echo(">>> Connected!") @@ -168,11 +195,11 @@ def listen(): def on_message(ws, message_type, message_payload): click.echo("Message: {}, Payload: {}".format(message_type, json.dumps(message_payload))) - socket = octoprint_client.connect_socket(on_connect=on_connect, - on_close=on_close, - on_error=on_error, - on_heartbeat=on_heartbeat, - on_message=on_message) + socket = ctx.obj.client.create_socket(on_connect=on_connect, + on_close=on_close, + on_error=on_error, + on_heartbeat=on_heartbeat, + on_message=on_message) click.echo(">>> Waiting for client to exit") try: diff --git a/src/octoprint/events.py b/src/octoprint/events.py index eb500a014..367fd9851 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -53,6 +53,11 @@ class Events(object): METADATA_ANALYSIS_FINISHED = "MetadataAnalysisFinished" METADATA_STATISTICS_UPDATED = "MetadataStatisticsUpdated" + FILE_ADDED = "FileAdded", + FILE_REMOVED = "FileRemoved", + FOLDER_ADDED = "FolderAdded", + FOLDER_REMOVED = "FolderRemoved", + # SD Upload TRANSFER_STARTED = "TransferStarted" TRANSFER_DONE = "TransferDone" @@ -350,7 +355,10 @@ class CommandTrigger(GenericEventListener): else: commandExecutioner(command) except subprocess.CalledProcessError as e: - self._logger.warn("Command failed with return code %i: %s" % (e.returncode, str(e))) + if debug: + self._logger.warn("Command failed with return code {}: {}".format(e.returncode, str(e))) + else: + self._logger.warn("Command failed with return code {}, enable debug logging on target 'octoprint.events' for details".format(e.returncode)) except: self._logger.exception("Command failed") diff --git a/src/octoprint/filemanager/__init__.py b/src/octoprint/filemanager/__init__.py index de06893b7..35c9075e4 100644 --- a/src/octoprint/filemanager/__init__.py +++ b/src/octoprint/filemanager/__init__.py @@ -409,30 +409,47 @@ class FileManager(object): queue_entry = self._analysis_queue_entry(destination, path) self._analysis_queue.dequeue(queue_entry) - file_path = self._storage(destination).add_file(path, file_object, links=links, printer_profile=printer_profile, allow_overwrite=allow_overwrite) + path_in_storage = self._storage(destination).add_file(path, file_object, links=links, printer_profile=printer_profile, allow_overwrite=allow_overwrite) if analysis is None: - queue_entry = self._analysis_queue_entry(destination, file_path, printer_profile=printer_profile) + queue_entry = self._analysis_queue_entry(destination, path_in_storage, printer_profile=printer_profile) if queue_entry: self._analysis_queue.enqueue(queue_entry, high_priority=True) else: self._add_analysis_result(destination, path, analysis) + _, name = self._storage(destination).split_path(path_in_storage) + eventManager().fire(Events.FILE_ADDED, dict(storage=destination, + path=path_in_storage, + name=name, + type=get_file_type(name))) eventManager().fire(Events.UPDATED_FILES, dict(type="printables")) - return file_path + return path_in_storage def remove_file(self, destination, path): queue_entry = self._analysis_queue_entry(destination, path) self._analysis_queue.dequeue(queue_entry) self._storage(destination).remove_file(path) + + _, name = self._storage(destination).split_path(path) + eventManager().fire(Events.FILE_REMOVED, dict(storage=destination, + path=path, + name=name, + type=get_file_type(name))) eventManager().fire(Events.UPDATED_FILES, dict(type="printables")) def copy_file(self, destination, source, dst): - path = self._storage(destination).copy_file(source, dst) - if not self.has_analysis(destination, path): - queue_entry = self._analysis_queue_entry(destination, path) + path_in_storage = self._storage(destination).copy_file(source, dst) + if not self.has_analysis(destination, path_in_storage): + queue_entry = self._analysis_queue_entry(destination, path_in_storage) if queue_entry: self._analysis_queue.enqueue(queue_entry) + + _, name = self._storage(destination).split_path(path_in_storage) + eventManager().fire(Events.FILE_ADDED, dict(storage=destination, + path=path_in_storage, + name=name, + type=get_file_type(name))) eventManager().fire(Events.UPDATED_FILES, dict(type="printables")) def move_file(self, destination, source, dst): @@ -443,23 +460,52 @@ class FileManager(object): queue_entry = self._analysis_queue_entry(destination, path) if queue_entry: self._analysis_queue.enqueue(queue_entry) + + source_path_in_storage = self._storage(destination).path_in_storage(source) + _, source_name = self._storage(destination).split_path(source_path_in_storage) + dst_path_in_storage = self._storage(destination).path_in_storage(dst) + _, dst_name = self._storage(destination).split_path(dst_path_in_storage) + + eventManager().fire(Events.FILE_REMOVED, dict(storage=destination, + path=source_path_in_storage, + name=source_name, + type=get_file_type(source_name))) + eventManager().fire(Events.FILE_ADDED, dict(storage=destination, + path=dst_path_in_storage, + name=dst_name, + type=get_file_type(dst_name))) eventManager().fire(Events.UPDATED_FILES, dict(type="printables")) def add_folder(self, destination, path, ignore_existing=True): - folder_path = self._storage(destination).add_folder(path, ignore_existing=ignore_existing) + path_in_storage = self._storage(destination).add_folder(path, ignore_existing=ignore_existing) + + _, name = self._storage(destination).split_path(path_in_storage) + eventManager().fire(Events.FOLDER_ADDED, dict(storage=destination, + path=path_in_storage, + name=name)) eventManager().fire(Events.UPDATED_FILES, dict(type="printables")) - return folder_path + return path_in_storage def remove_folder(self, destination, path, recursive=True): self._analysis_queue.dequeue_folder(destination, path) self._analysis_queue.pause() self._storage(destination).remove_folder(path, recursive=recursive) self._analysis_queue.resume() + + _, name = self._storage(destination).split_path(path) + eventManager().fire(Events.FOLDER_REMOVED, dict(storage=destination, + path=path, + name=name)) eventManager().fire(Events.UPDATED_FILES, dict(type="printables")) def copy_folder(self, destination, source, dst): - self._storage(destination).copy_folder(source, dst) + path_in_storage = self._storage(destination).copy_folder(source, dst) self._determine_analysis_backlog(destination, self._storage(destination), root=dst) + + _, name = self._storage(destination).split_path(path_in_storage) + eventManager().fire(Events.FOLDER_ADDED, dict(storage=destination, + path=path_in_storage, + name=name)) eventManager().fire(Events.UPDATED_FILES, dict(type="printables")) def move_folder(self, destination, source, dst): @@ -468,6 +514,18 @@ class FileManager(object): self._storage(destination).move_folder(source, dst) self._determine_analysis_backlog(destination, self._storage(destination), root=dst) self._analysis_queue.resume() + + source_path_in_storage = self._storage(destination).path_in_storage(source) + _, source_name = self._storage(destination).split_path(source_path_in_storage) + dst_path_in_storage = self._storage(destination).path_in_storage(destination) + _, dst_name = self._storage(destination).split_path(dst_path_in_storage) + + eventManager().fire(Events.FOLDER_REMOVED, dict(storage=destination, + path=source_path_in_storage, + name=source_name)) + eventManager().fire(Events.FOLDER_ADDED, dict(storage=destination, + path=dst_path_in_storage, + name=dst_name)) eventManager().fire(Events.UPDATED_FILES, dict(type="printables")) def has_analysis(self, destination, path): diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index 9a74e3dc3..bbc90b090 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -29,7 +29,6 @@ class StorageInterface(object): Interface of storage adapters for OctoPrint. """ - @property def analysis_backlog(self): """ @@ -155,7 +154,9 @@ class StorageInterface(object): def add_folder(self, path, ignore_existing=True): """ - Adds a folder as ``path``. The ``path`` will be sanitized. + Adds a folder as ``path`` + + The ``path`` will be sanitized. :param string path: the path of the new folder :param bool ignore_existing: if set to True, no error will be raised if the folder to be added already exists @@ -165,7 +166,7 @@ class StorageInterface(object): def remove_folder(self, path, recursive=True): """ - Removes the folder at ``path``. + Removes the folder at ``path`` :param string path: the path of the folder to remove :param bool recursive: if set to True, contained folders and files will also be removed, otherwise and error will @@ -212,7 +213,9 @@ class StorageInterface(object): def remove_file(self, path): """ - Removes the file at ``path``. Will also take care of deleting the corresponding entries + Removes the file at ``path`` + + Will also take care of deleting the corresponding entries in the metadata and deleting all links pointing to the file. :param string path: path of the file to remove @@ -486,6 +489,9 @@ class LocalFileStorage(StorageInterface): return self.analysis_backlog_for_path() def analysis_backlog_for_path(self, path=None): + if path: + path = self.sanitize_path(path) + for entry in self._analysis_backlog_generator(path): yield entry diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py index 62da7633b..f8a168f5d 100644 --- a/src/octoprint/plugin/core.py +++ b/src/octoprint/plugin/core.py @@ -71,6 +71,9 @@ class PluginInfo(object): attr_description = '__plugin_description__' """ Module attribute from which to retrieve the plugin's description. """ + attr_disabling_discouraged = '__plugin_disabling_discouraged__' + """ Module attribute from which to retrieve the reason why disabling the plugin is discouraged. Only effective if ``self.bundled`` is True. """ + attr_version = '__plugin_version__' """ Module attribute from which to retrieve the plugin's version. """ @@ -294,6 +297,19 @@ class PluginInfo(object): """ return self._get_instance_attribute(self.__class__.attr_description, default=self._description) + @property + def disabling_discouraged(self): + """ + Reason why disabling of this plugin is discouraged. Only evaluated for bundled plugins! Will be taken from + the disabling_discouraged attribute of the plugin module as defined in :attr:`attr_disabling_discouraged` if + available. False if unset or plugin not bundled. + + Returns: + str or None: Reason why disabling this plugin is discouraged (only for bundled plugins) + """ + return self._get_instance_attribute(self.__class__.attr_disabling_discouraged, default=False) if self.bundled \ + else False + @property def version(self): """ diff --git a/src/octoprint/plugins/announcements/__init__.py b/src/octoprint/plugins/announcements/__init__.py index b4ef690ce..00a2664a9 100644 --- a/src/octoprint/plugins/announcements/__init__.py +++ b/src/octoprint/plugins/announcements/__init__.py @@ -18,6 +18,8 @@ import threading import feedparser import flask +from collections import OrderedDict + from octoprint.server import admin_permission from octoprint.server.util.flask import restricted_access, with_revalidation_checking, check_etag from flask_babel import gettext @@ -44,35 +46,64 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, # SettingsPlugin def get_settings_defaults(self): - return dict(channels=dict(_important=dict(name="Important OctoPrint Announcements", - priority=1, - type="rss", - url="http://octoprint.org/feeds/important.xml"), - _news=dict(name="OctoPrint News", - priority=2, - type="rss", - url="http://octoprint.org/feeds/news.xml"), - _releases=dict(name="OctoPrint Release Announcements", + settings = dict(channels=dict(_important=dict(name="Important Announcements", + description="Important announcements about OctoPrint.", + priority=1, + type="rss", + url="http://octoprint.org/feeds/important.xml"), + _releases=dict(name="Release Announcements", + description="Announcements of new releases and release candidates of OctoPrint.", + priority=2, + type="rss", + url="http://octoprint.org/feeds/releases.xml"), + _blog=dict(name="On the OctoBlog", + description="Development news, community spotlights, OctoPrint On Air episodes and more from the official OctoBlog.", priority=2, type="rss", - url="http://octoprint.org/feeds/releases.xml"), - _spotlight=dict(name="OctoPrint Community Spotlights", - priority=2, - type="rss", - url="http://octoprint.org/feeds/spotlight.xml"), - _octopi=dict(name="OctoPi Announcements", - priority=2, - type="rss", - url="http://octoprint.org/feeds/octopi.xml"), - _plugins=dict(name="New Plugins in the Repository", - priority=2, - type="rss", - url="http://plugins.octoprint.org/feed.xml")), - enabled_channels=[], - forced_channels=["_important"], - ttl=6*60, - display_limit=3, - summary_limit=300) + url="http://octoprint.org/feeds/octoblog.xml"), + _plugins=dict(name="New Plugins in the Repository", + description="Announcements of new plugins released on the official Plugin Repository.", + priority=2, + type="rss", + url="http://plugins.octoprint.org/feed.xml"), + _octopi=dict(name="OctoPi News", + description="News around OctoPi, the Raspberry Pi image including OctoPrint.", + priority=2, + type="rss", + url="http://octoprint.org/feeds/octopi.xml")), + enabled_channels=[], + forced_channels=["_important"], + channel_order=["_important", "_releases", "_blog", "_plugins", "_octopi"], + ttl=6*60, + display_limit=3, + summary_limit=300) + settings["enabled_channels"] = settings["channels"].keys() + return settings + + def get_settings_version(self): + return 1 + + def on_settings_migrate(self, target, current): + if current is None: + # first version had different default feeds and only _important enabled by default + channels = self._settings.get(["channels"]) + if "_news" in channels: + del channels["_news"] + if "_spotlight" in channels: + del channels["_spotlight"] + self._settings.set(["channels"], channels) + + enabled = self._settings.get(["enabled_channels"]) + add_blog = False + if "_news" in enabled: + add_blog = True + enabled.remove("_news") + if "_spotlight" in enabled: + add_blog = True + enabled.remove("_spotlight") + if add_blog and not "_blog" in enabled: + enabled.append("_blog") + self._settings.set(["enabled_channels"], enabled) # AssetPlugin @@ -97,7 +128,7 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, def get_channel_data(self): from octoprint.settings import valid_boolean_trues - result = dict() + result = [] force = flask.request.values.get("force", "false") in valid_boolean_trues @@ -118,15 +149,17 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, last = entries[0]["published"] self._mark_read_until(key, last) - result[key] = dict(channel=data["name"], + result.append(dict(key=key, + channel=data["name"], url=data["url"], + description=data.get("description", ""), priority=data.get("priority", 2), enabled=key in enabled or key in forced, forced=key in forced, data=entries, - unread=unread) + unread=unread)) - return flask.jsonify(result) + return flask.jsonify(channels=result) def etag(): import hashlib @@ -141,11 +174,11 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, return hash.hexdigest() - def condition(): - return check_etag(etag()) + def condition(lm, etag): + return check_etag(etag) return with_revalidation_checking(etag_factory=lambda *args, **kwargs: etag(), - condition=lambda *args, **kwargs: condition(), + condition=lambda lm, etag: condition(lm, etag), unless=lambda: force)(view)() @octoprint.plugin.BlueprintPlugin.route("/channels/", methods=["POST"]) @@ -208,9 +241,13 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, with self._cached_channel_configs_mutex: if self._cached_channel_configs is None or force: configs = self._settings.get(["channels"], merged=True) - result = dict() - for key, config in configs.items(): - if "url" not in config or "name" not in config: + order = self._settings.get(["channel_order"]) + all_keys = order + [key for key in sorted(configs.keys()) if not key in order] + + result = OrderedDict() + for key in all_keys: + config = configs.get(key) + if config is None or "url" not in config or "name" not in config: # strip invalid entries continue result[self._slugify(key)] = config @@ -374,4 +411,9 @@ def _strip_tags(text): __plugin_name__ = "Announcement Plugin" +__plugin_author__ = "Gina Häußge" +__plugin_description__ = "Announcements all around OctoPrint" +__plugin_disabling_discouraged__ = gettext("Without this plugin you might miss important announcements " + "regarding security or other critical issues concerning OctoPrint.") +__plugin_license__ = "AGPLv3" __plugin_implementation__ = AnnouncementPlugin() diff --git a/src/octoprint/plugins/announcements/static/css/announcements.css b/src/octoprint/plugins/announcements/static/css/announcements.css index 08e9a9bd0..4df82b396 100644 --- a/src/octoprint/plugins/announcements/static/css/announcements.css +++ b/src/octoprint/plugins/announcements/static/css/announcements.css @@ -1 +1 @@ -table td.settings_plugin_announcements_channels_name,table th.settings_plugin_announcements_channels_name{text-overflow:ellipsis;text-align:left}table td.settings_plugin_announcements_channels_actions,table th.settings_plugin_announcements_channels_actions{text-align:center;width:80px}table td.settings_plugin_announcements_channels_actions a,table th.settings_plugin_announcements_channels_actions a{text-decoration:none;color:#000}table td.settings_plugin_announcements_channels_actions a.disabled,table th.settings_plugin_announcements_channels_actions a.disabled{color:#ccc;cursor:default}#plugin_announcements_dialog .unread{font-weight:700}#plugin_announcements_dialog article{padding-right:20px}#plugin_announcements_dialog article.read{opacity:.5}#plugin_announcements_dialog article.read:hover{opacity:1}#plugin_announcements_dialog article .actions{background-color:#f5f5f5;border-radius:2px;padding:2px 5px;margin-top:5px}#plugin_announcements_dialog article .actions .markread{float:right}#plugin_announcements_dialog article .actions a{color:#000} \ No newline at end of file +table td.settings_plugin_announcements_channels_name,table th.settings_plugin_announcements_channels_name{text-overflow:ellipsis;text-align:left}table td.settings_plugin_announcements_channels_actions,table th.settings_plugin_announcements_channels_actions{text-align:center;width:80px}table td.settings_plugin_announcements_channels_actions a,table th.settings_plugin_announcements_channels_actions a{text-decoration:none;color:#000}table td.settings_plugin_announcements_channels_actions a.disabled,table th.settings_plugin_announcements_channels_actions a.disabled{color:#ccc;cursor:default}#plugin_announcements_dialog .unread{font-weight:700}#plugin_announcements_dialog article{padding-right:20px}#plugin_announcements_dialog article.read{opacity:.5}#plugin_announcements_dialog article.read:hover{opacity:1}#plugin_announcements_dialog article .actions{background-color:#f5f5f5;border-radius:2px;padding:2px 5px;margin-top:5px}#plugin_announcements_dialog article .actions .markread{float:right}#plugin_announcements_dialog article .actions a{color:#000}#plugin_announcements_dialog .modal-footer .configurelink{float:left} \ No newline at end of file diff --git a/src/octoprint/plugins/announcements/static/js/announcements.js b/src/octoprint/plugins/announcements/static/js/announcements.js index 55c208151..dfd6d7d9a 100644 --- a/src/octoprint/plugins/announcements/static/js/announcements.js +++ b/src/octoprint/plugins/announcements/static/js/announcements.js @@ -120,12 +120,13 @@ $(function() { }; self.fromResponse = function(data) { + if (!self.loginState.isAdmin()) return; + var currentTab = $("li.active a", self.announcementDialogTabs).attr("href"); var unread = 0; var channels = []; - _.each(data, function(value, key) { - value.key = key; + _.each(data.channels, function(value) { value.last = value.data.length ? value.data[0].published : undefined; value.count = value.data.length; unread += value.unread; @@ -140,6 +141,8 @@ $(function() { }; self.showAnnouncementDialog = function(channel) { + if (!self.loginState.isAdmin()) return; + self.announcementDialogContent.scrollTop(0); if (!self.announcementDialog.hasClass("in")) { @@ -172,6 +175,8 @@ $(function() { }; self.displayAnnouncements = function(channels) { + if (!self.loginState.isAdmin()) return; + var displayLimit = self.settings.settings.plugins.announcements.display_limit(); var maxLength = self.settings.settings.plugins.announcements.summary_limit(); @@ -222,7 +227,7 @@ $(function() { } var rest = newItems.length - displayedItems.length; - var text = "