Skip to content

Commit ce63321

Browse files
committed
✨ Add ability to disable selected checks
1 parent 9140aff commit ce63321

File tree

5 files changed

+123
-36
lines changed

5 files changed

+123
-36
lines changed

octoprint_file_check/__init__.py

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ def on_event(self, event, payload):
8686
self._validate_file, payload["origin"], payload["path"], file_type
8787
)
8888

89+
##~~ SettingsPlugin API
90+
91+
def get_settings_defaults(self):
92+
return {
93+
"ignored_checks": [],
94+
}
95+
8996
##~~ SimpleApiPlugin API
9097

9198
def on_api_get(self, request):
@@ -128,22 +135,24 @@ def on_api_command(self, command, data):
128135
##~~ TemplatePlugin API
129136

130137
def get_template_configs(self):
131-
if not self._native_grep_available:
132-
return []
133-
134-
return [
135-
dict(
136-
type="wizard",
137-
template="file_check_wizard_grep.jinja2",
138-
custom_bindings=True,
139-
),
140-
dict(
141-
type="settings",
142-
template="file_check_settings_grep.jinja2",
143-
custom_bindings=True,
144-
),
138+
templates = [
139+
{
140+
"type": "settings",
141+
"custom_bindings": True,
142+
}
145143
]
146144

145+
if self._native_grep_available:
146+
templates.append(
147+
{
148+
"type": "wizard",
149+
"template": "file_check_wizard_fullcheck.jinja2",
150+
"custom_bindings": True,
151+
}
152+
)
153+
154+
return templates
155+
147156
##~~ WizardPlugin API
148157

149158
def is_wizard_required(self):
@@ -222,9 +231,12 @@ def _check_all_files(self):
222231
with self._full_check_lock:
223232
path = self._settings.global_get_basefolder("uploads")
224233
self._logger.info(f"Running check on all files in {path} (local storage)")
234+
ignored_checks = self._settings.get(["ignored_checks"])
225235

226236
full_check_result = defaultdict(list)
227237
for check, params in CHECKS.items():
238+
if check in ignored_checks:
239+
continue
228240
self._logger.info(f"Running check {check}")
229241
pattern = params["pattern"]
230242
sanitized = self._sanitize_pattern(
@@ -305,8 +317,13 @@ def _validate_file(self, storage, path, file_type):
305317
if file_type[-1] != "gcode":
306318
return
307319

320+
ignored_checks = self._settings.get(["ignored_checks"])
321+
308322
types = []
309323
for check, params in CHECKS.items():
324+
if check in ignored_checks:
325+
continue
326+
310327
pattern = params["pattern"]
311328
if self._search_through_file(
312329
path_on_disk,
@@ -392,32 +409,42 @@ def _save_to_metadata(self, storage, path, positive_checks):
392409
def _gather_from_local_metadata(self):
393410
uploads = self._settings.global_get_basefolder("uploads")
394411

412+
ignored_checks = self._settings.get(["ignored_checks"])
413+
395414
result = {}
396415
for path in glob.glob(
397416
os.path.join(uploads, "**", ".metadata.json"), recursive=True
398417
):
399418
internal_path = path[len(uploads) + 1 : -len(".metadata.json")]
400-
from_metadata = self._gather_metadata_from_file(path)
419+
from_metadata = self._gather_metadata_from_file(
420+
path, ignored_checks=ignored_checks
421+
)
401422
result.update(
402423
{f"local:{internal_path}{k}": v for k, v in from_metadata.items()}
403424
)
404425
return result
405426

406-
def _gather_metadata_from_file(self, path):
427+
def _gather_metadata_from_file(self, path, ignored_checks=None):
407428
with open(path, encoding="utf-8") as f:
408429
metadata = json.load(f)
409430

410431
if not isinstance(metadata, dict):
411432
return {}
412433

434+
if ignored_checks is None:
435+
ignored_checks = self._settings.get(["ignored_checks"])
436+
413437
result = {}
414438
for key, value in metadata.items():
415-
if (
416-
"file_check" in value
417-
and isinstance(value["file_check"], dict)
418-
and len(value["file_check"].get("checks", []))
419-
):
420-
result[key] = value["file_check"]["checks"]
439+
if "file_check" in value and isinstance(value["file_check"], dict):
440+
filtered = list(
441+
filter(
442+
lambda x: x not in ignored_checks,
443+
value["file_check"].get("checks", []),
444+
)
445+
)
446+
if len(filtered) > 0:
447+
result[key] = filtered
421448
return result
422449

423450

octoprint_file_check/static/js/file_check.js

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ $(function () {
44

55
self.loginState = parameters[0];
66
self.access = parameters[1];
7-
self.printerState = parameters[2];
8-
self.filesViewModel = parameters[3];
7+
self.settingsViewModel = parameters[2];
8+
self.printerState = parameters[3];
9+
self.filesViewModel = parameters[4];
910

1011
self.fullCheckAvailable = ko.observable(false);
1112
self.checkResult = ko.observable();
@@ -18,6 +19,7 @@ $(function () {
1819

1920
const ISSUES = {
2021
travel_speed: {
22+
title: gettext("Travel Speed Placeholder"),
2123
message: gettext(
2224
"Your file still contains a place holder <code>{travel_speed}</code>. " +
2325
"This is a common issue when using old start/stop GCODE code snippets in current versions of " +
@@ -27,6 +29,7 @@ $(function () {
2729
)
2830
},
2931
leaked_api_key: {
32+
title: gettext("Leaked API Key"),
3033
message: gettext(
3134
"Your file contains an API key that is not supposed to be there. " +
3235
"This is caused by a bug in your slicer, and known to happen with PrusaSlicer (<= 2.1.1), " +
@@ -39,6 +42,34 @@ $(function () {
3942
}
4043
};
4144

45+
self.checksArray = ko.pureComputed(() => {
46+
return Object.keys(ISSUES).map((key) => {
47+
return {
48+
key: key,
49+
title: ISSUES[key].title,
50+
message: ISSUES[key].message,
51+
enabled: ko.pureComputed({
52+
read: () => {
53+
return !self.settingsViewModel.settings.plugins.file_check
54+
.ignored_checks()
55+
.includes(key);
56+
},
57+
write: (value) => {
58+
if (value) {
59+
self.settingsViewModel.settings.plugins.file_check.ignored_checks.remove(
60+
key
61+
);
62+
} else {
63+
self.settingsViewModel.settings.plugins.file_check.ignored_checks.push(
64+
key
65+
);
66+
}
67+
}
68+
})
69+
};
70+
});
71+
});
72+
4273
self.lastCheckTimestampText = ko.pureComputed(() => {
4374
return formatDate(self.lastCheckTimestamp(), {
4475
placeholder: gettext("unknown")
@@ -47,9 +78,9 @@ $(function () {
4778

4879
self.lastCheckStateText = ko.pureComputed(() => {
4980
if (self.lastCheckCurrent()) {
50-
return gettext("Current set of checks");
81+
return gettext("Up to date");
5182
} else {
52-
return gettext("Outdated set of checks");
83+
return gettext("Outdated");
5384
}
5485
});
5586

@@ -308,6 +339,14 @@ $(function () {
308339
);
309340
};
310341

342+
self.onAfterBinding = function () {
343+
self.settingsViewModel.settings.plugins.file_check.ignored_checks.subscribe(
344+
() => {
345+
self.requestData();
346+
}
347+
);
348+
};
349+
311350
self.onUserLoggedIn = self.onUserLoggedOut = function () {
312351
self.requestData();
313352
};
@@ -318,6 +357,7 @@ $(function () {
318357
dependencies: [
319358
"loginStateViewModel",
320359
"accessViewModel",
360+
"settingsViewModel",
321361
"printerStateViewModel",
322362
"filesViewModel"
323363
],
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<fieldset>
2+
<legend>{{ _("Configured checks") }}</legend>
3+
4+
<p>{% trans %}
5+
The following checks are currently configured for your instance. You can enable or disable them as needed.
6+
{% endtrans %}</p>
7+
8+
<form class="form-horizontal" onsubmit="return false;" data-bind="foreach: checksArray">
9+
<div class="control-group">
10+
<div class="controls">
11+
<label class="checkbox">
12+
<input type="checkbox" data-bind="checked: $data.enabled"> <span data-bind="text: $data.title"></span>
13+
</label>
14+
</div>
15+
</div>
16+
</form>
17+
</fieldset>
18+
19+
<fieldset data-bind="visible: fullCheckAvailable">
20+
<legend>{{ _("Full file check") }}</legend>
21+
22+
<p>{% trans %}
23+
The bundled File Check plugin allows checking your uploaded files for known slicer misconfigurations and related issues.
24+
The plugin automatically checks all freshly uploaded files and files selected for printing, but for already uploaded
25+
files you can also trigger a full file check manually. It is recommended to do this whenever new checks are added
26+
to the plugin, in which case your last check will be marked as outdated below.
27+
{% endtrans %}</p>
28+
29+
{% include "snippets/fileCheckButton.jinja2" %}
30+
</fieldset>

octoprint_file_check/templates/file_check_settings_grep.jinja2

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)