Skip to content

Commit

Permalink
🎉 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
foosel committed Jun 22, 2020
0 parents commit 76619fd
Show file tree
Hide file tree
Showing 18 changed files with 1,767 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

[**.py]
indent_style = tab

[**.js]
indent_style = space
indent_size = 4
63 changes: 63 additions & 0 deletions .github/workflows/ci-cd-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI/CD pipeline
on:
push:
branches:
- master
release:
types: [published, prereleased]

jobs:
build:
name: 🔨 Build distribution
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: 🏗 Install build dependencies
run: >-
python -m pip install wheel --user
- name: 🔨 Build a binary wheel and a source tarball
run: >-
python setup.py sdist bdist_wheel
- name: ⬆ Upload build result
uses: actions/upload-artifact@v1
with:
name: dist
path: dist

publish-on-testpypi:
name: 📦 Publish on TestPyPI
if: github.event_name == 'push'
needs: build
runs-on: ubuntu-latest
steps:
- name: ⬇ Download build result
uses: actions/download-artifact@v1
with:
name: dist
path: dist
- name: 📦 Publish to index
uses: pypa/gh-action-pypi-publish@master
continue-on-error: true
with:
password: ${{ secrets.testpypi_password }}
repository_url: https://test.pypi.org/legacy/

publish-on-pypi:
name: 📦 Publish tagged releases to PyPI
if: github.event_name == 'release'
needs: build
runs-on: ubuntu-latest
steps:
- name: ⬇ Download build result
uses: actions/download-artifact@v1
with:
name: dist
path: dist
- name: 📦 Publish to index
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.pyc
*.swp
.idea
*.iml
build
dist
*.egg*
.DS_Store
*.zip
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include README.md
recursive-include octoprint_file_check/templates *
recursive-include octoprint_file_check/translations *
recursive-include octoprint_file_check/static *
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# File Check

The File Check plugin tries to detect common issues in uploaded files that are known to cause
issues while printing and which in the past have caused support requests on OctoPrint's Community
Forums.

![Screenshot](https://raw.githubusercontent.com/OctoPrint/OctoPrint-FileCheck/master/extras/screenshot.png)

It currently detects and warns about the following issues:

* Outdated placeholder `{travel_speed}` left in the GCODE generated by the slicer. See
[here](https://faq.octoprint.org/file-check-travel-speed) for details on this.

## Setup

The plugin is part of the core dependencies of OctoPrint 1.4.1+ and will be installed automatically alongside it.

In case you want to manually install it into an older version for whatever reason, install via the bundled
[Plugin Manager](https://docs.octoprint.org/en/master/bundledplugins/pluginmanager.html)
or manually using this URL:

https://github.com/OctoPrint/OctoPrint-GcodeValidator/archive/master.zip
6 changes: 6 additions & 0 deletions babel.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[python: */**.py]
[jinja2: */**.jinja2]
extensions=jinja2.ext.autoescape, jinja2.ext.with_

[javascript: */**.js]
extract_messages = gettext, ngettext
Binary file added extras/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 110 additions & 0 deletions octoprint_file_check/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals

__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
__copyright__ = "Copyright (C) 2020 The OctoPrint Project - Released under terms of the AGPLv3 License"

import octoprint.plugin
import octoprint.events

import sarge
import io
import re

from flask_babel import gettext

# noinspection PyCompatibility
from concurrent.futures import ThreadPoolExecutor

class FileCheckPlugin(octoprint.plugin.AssetPlugin,
octoprint.plugin.EventHandlerPlugin):
def __init__(self):
self._executor = ThreadPoolExecutor()

##~~ AssetPlugin API

def get_assets(self):
return dict(js=("js/file_check.js",))

##~~ EventHandlerPlugin API

def on_event(self, event, payload):
if event == octoprint.events.Events.FILE_ADDED:
self._executor.submit(self._validate_file, payload["storage"], payload["path"], payload["type"])

##~~ SoftwareUpdate hook

def get_update_information(self):
return dict(
file_check=dict(
displayName="File Check Plugin",
displayVersion=self._plugin_version,

# version check: github repository
type="github_release",
user="OctoPrint",
repo="OctoPrint-FileCheck",
current=self._plugin_version,

# update method: pip
pip="https://github.com/OctoPrint/OctoPrint-FileCheck/archive/{target_version}.zip"
)
)

##~~ Internal logic & helpers

def _validate_file(self, storage, path, file_type):
try:
path_on_disk = self._file_manager.path_on_disk(storage, path)
except NotImplementedError:
# storage doesn't support path_on_disk, ignore
return

if file_type[-1] == "gcode":
if self._search_through_file(path_on_disk, "{travel_speed}"):
self._notify("travel_speed", storage, path)

def _search_through_file(self, path, term):
try:
# try native grep
result = sarge.run(["grep", "-q", re.escape(term), path])
return result.returncode == 0
except ValueError as exc:
if 'Command not found' in str(exc):
try:
# try python only approach
with io.open(path, mode="r", encoding="utf8", errors="replace") as f:
for line in f:
if term in line:
return True
return False
except:
self._logger.exception("Something unexpectedly went wrong while trying to "
"search for {} in {} via native python".format(term, path))
else:
self._logger.exception("Something unexpectedly went wrong while trying to "
"search for {} in {} via grep".format(term, path))

return False

def _notify(self, notification_type, storage, path):
self._logger.warning("File check identified an issue: {} for {}:{}, see "
"https://faq.octoprint.org/file-check-{} for details".format(notification_type,
storage,
path,
notification_type.replace("_", "-")))
self._plugin_manager.send_plugin_message(self._identifier, dict(type=notification_type,
storage=storage,
path=path))


__plugin_name__ = "File Check"
__plugin_pycompat__ = ">2.7,<4"
__plugin_disabling_discouraged__ = gettext("Without this plugin OctoPrint will no longer be able to "
"check if uploaded files contain common problems and inform you "
"about that fact.")

__plugin_implementation__ = FileCheckPlugin()
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
44 changes: 44 additions & 0 deletions octoprint_file_check/static/js/file_check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* View model for OctoPrint-FileCheck
*
* Author: Gina Häußge
* License: AGPLv3
*/
$(function() {
function FileCheckViewModel(parameters) {
var self = this;

var issues = {
travel_speed: gettext("Your sliced file still contains a place holder <code>{travel_speed}</code>. "
+ "This is a common issue when using old start/stop GCODE code snippets in current versions of "
+ "Cura, as the placeholder name switched to <code>{speed_travel}</code> at some point and "
+ "no longer gets replaced in current versions. You need to fix this in your slicer and reslice "
+ "your file, do not print it like it is as it will cause issues!")
}

self.onDataUpdaterPluginMessage = function(plugin, data) {
if (plugin !== "file_check") {
return;
}

var message = issues[data["type"]];
if (!message) {
return;
}

var faq = "<a href='https://faq.octoprint.org/file-check-"
+ data["type"].replace("_", "-") + "' target='_blank' rel='noreferrer noopener'>"
+ gettext("Read more...") + "</a>";

new PNotify({
title: _.sprintf(gettext('File Check detected issues with %(storage)s:%(path)s!'), data),
text: "<p>" + message + "</p><p>" + faq + "</p>",
hide: false
});
}
}

OCTOPRINT_VIEWMODELS.push({
construct: FileCheckViewModel
});
});
Binary file not shown.
58 changes: 58 additions & 0 deletions octoprint_file_check/translations/de/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# German translations for OctoPrint-FileCheck.
# Copyright (C) 2020 The OctoPrint Project
# This file is distributed under the same license as the OctoPrint-FileCheck
# project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2020.
#
msgid ""
msgstr ""
"Project-Id-Version: OctoPrint-FileCheck 2020.6.22\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2020-06-22 16:22+0200\n"
"PO-Revision-Date: 2020-06-22 17:13+0200\n"
"Language: de\n"
"Language-Team: de <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.8.0\n"
"Last-Translator: \n"
"X-Generator: Poedit 2.0.4\n"

#: octoprint_file_check/__init__.py:103
msgid ""
"Without this plugin OctoPrint will no longer be able to check if "
"uploaded files contain common the printer it is connected to has a "
"known safety issue or otherwise broken firmware and inform you about "
"that fact."
msgstr ""
"Ohne dieses Plugin wird OctoPrint nicht länger in der Lage sein, zu "
"prüfen, ob eine hochgeladene Datei typische Probleme enthält und ggf. "
"davor zu warnen."

#: octoprint_file_check/static/js/file_check.js:12
msgid ""
"Your sliced file still contains a place holder <code>{travel_speed}</"
"code>. This is a common issue when using old start/stop GCODE code "
"snippets in current versions of Cura, as the placeholder name switched "
"to <code>{speed_travel}</code> at some point and no longer gets replaced "
"in current versions. You need to fix this in your slicer and reslice "
"your file, do not print it like it is as it will cause issues!"
msgstr ""
"Deine geslicete Datei beinhaltet den Platzhalter <code>{travel_speed}</"
"code>. Das ist ein häufiges Problem wenn alter start/stop GCODE in "
"aktuellen Versionen von Cura verwendet wird, da der Platzhaltername vor "
"einiger Zeit zu <code>{speed_travel}</code> geändert wurde und die alte "
"Variante in aktuellen Versionen nicht mehr ersetzt wird. Du musst das in "
"deinem Slicer fixen und deine Datei erneut slicen. Versuche sie nicht so "
"zu drucken, das wird Probleme verursachen!"

#: octoprint_file_check/static/js/file_check.js:31
msgid "Read more..."
msgstr "Mehr..."

#: octoprint_file_check/static/js/file_check.js:34
#, python-format
msgid "File Check detected issues with %(storage)s:%(path)s!"
msgstr "File Check hat Probleme mit %(storage)s:%(path)s festgestellt!"
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
###
# This file is only here to make sure that something like
#
# pip install -e .
#
# works as expected. Requirements can be found in setup.py.
###

.
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[metadata]
license_file = LICENSE

[bdist_wheel]
universal = 1
Loading

0 comments on commit 76619fd

Please sign in to comment.