Skip to content

Commit f8a2edc

Browse files
authored
[plugin] Initialize the Python plugin (#5414)
* Add plugin skeleton * Add python artifacts to gitignore * Gut plugin to have only settings * WIP on adding versioning script * Get correct data for versioning * Migrate to pyproject.toml OctoPrint has final migrated away from setup.py so this needs to follow suit * Updates to build system * Revert "Updates to build system" This reverts commit 39e95d2. * Revert "Migrate to pyproject.toml" This reverts commit 4db43ae. * Convert to pyproject Will need to figure out the build stuff later * Make build include version properly * Formatting on taskfile * Delete egg info * Gut more plugin stuff * Delete python cache file Should never have been commited anyway
1 parent cefed5e commit f8a2edc

File tree

11 files changed

+773
-0
lines changed

11 files changed

+773
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ src/locale/backups
1515

1616
# compiled output
1717
/dist
18+
/octoprint_octodash/static
1819
/package
1920
/tmp
2021
/out-tsc
@@ -53,6 +54,13 @@ speed-measure-plugin.json
5354
/libpeerconnection.log
5455
/typings
5556

57+
# python
58+
__pycache__/
59+
*.py[cod]
60+
*.egg*
61+
62+
build/
63+
5664

5765
docs/images/compilation.psd
5866
scripts/clean-github.sh

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include README.md
2+
recursive-include octoprint_octodash/templates *
3+
recursive-include octoprint_octodash/translations *
4+
recursive-include octoprint_octodash/static *

Taskfile.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# https://taskfile.dev
2+
3+
version: '3'
4+
5+
env:
6+
LOCALES: [] # list your included locales here, e.g. ["de", "fr"]
7+
TRANSLATIONS: 'octoprint_octodash/translations' # translations folder, do not touch
8+
9+
tasks:
10+
install:
11+
desc: Installs the plugin into the current venv
12+
cmds:
13+
- 'python -m pip install -e .[develop]'
14+
15+
### Build related
16+
17+
build:
18+
desc: Builds sdist & wheel
19+
cmds:
20+
- python -m build --sdist --wheel
21+
22+
build-sdist:
23+
desc: Builds sdist
24+
cmds:
25+
- python -m build --sdist
26+
27+
build-wheel:
28+
desc: Builds wheel
29+
cmds:
30+
- python -m build --wheel
31+
32+
### Translation related
33+
34+
babel-new:
35+
desc: Create a new translation for a locale
36+
cmds:
37+
- task: babel-extract
38+
- |
39+
pybabel init --input-file=translations/messages.pot --output-dir=translations --locale="{{ .CLI_ARGS }}"
40+
41+
babel-extract:
42+
desc: Update pot file from source
43+
cmds:
44+
- pybabel extract --mapping-file=babel.cfg --output-file=translations/messages.pot --msgid-bugs-address=i18n@octoprint.org --copyright-holder="The OctoPrint Project" .
45+
46+
babel-update:
47+
desc: Update translation files from pot file
48+
cmds:
49+
- for:
50+
var: LOCALES
51+
cmd: pybabel update --input-file=translations/messages.pot --output-dir=translations --locale={{ .ITEM }}
52+
53+
babel-refresh:
54+
desc: Update translation files from source
55+
cmds:
56+
- task: babel-extract
57+
- task: babel-update
58+
59+
babel-compile:
60+
desc: Compile translation files
61+
cmds:
62+
- pybabel compile --directory=translations
63+
64+
babel-bundle:
65+
desc: Bundle translations
66+
preconditions:
67+
- test -d {{ .TRANSLATIONS }}
68+
cmds:
69+
- for:
70+
var: LOCALES
71+
cmd: |
72+
locale="{{ .ITEM }}"
73+
source="translations/${locale}"
74+
target="{{ .TRANSLATIONS }}/${locale}"
75+
76+
[ ! -d "${target}" ] || rm -r "${target}"
77+
78+
echo "Copying translations for locale ${locale} from ${source} to ${target}..."
79+
cp -r "${source}" "${target}"

babel.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[python: */**.py]
2+
3+
[jinja2: */**.jinja2]
4+
silent=false
5+
extensions=jinja2.ext.do, octoprint.util.jinja.trycatch
6+
7+
[javascript: */**.js]
8+
extract_messages = gettext, ngettext

octoprint_octodash/__init__.py

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# coding=utf-8
2+
from __future__ import absolute_import
3+
4+
from flask import make_response
5+
6+
import octoprint.plugin
7+
8+
9+
class OctodashPlugin(
10+
octoprint.plugin.SettingsPlugin,
11+
):
12+
13+
##~~ SettingsPlugin mixin
14+
15+
def get_settings_defaults(self):
16+
return {
17+
"octoprint": {
18+
"accessToken": "1t9H6i51hQLMm2eZXGAPbvRLv4iJr2Yao_LoxhE_66E",
19+
"url": "http://localhost:8080/",
20+
},
21+
"printer": {
22+
"name": "",
23+
"xySpeed": 150,
24+
"zSpeed": 5,
25+
"disableExtruderGCode": "M18 E",
26+
"zBabystepGCode": "M290 Z",
27+
"defaultTemperatureFanSpeed": {
28+
"hotend": 220,
29+
"heatbed": 70,
30+
"fan": 100,
31+
},
32+
},
33+
"filament": {
34+
"density": 1.25,
35+
"thickness": 1.75,
36+
"feedLength": 0,
37+
"feedSpeed": 20,
38+
"feedSpeedSlow": 3,
39+
"purgeDistance": 30,
40+
"useM600": False,
41+
},
42+
"plugins": {
43+
"companion": {"enabled": True},
44+
"displayLayerProgress": {"enabled": True},
45+
"enclosure": {
46+
"enabled": True,
47+
"ambientSensorID": None,
48+
"filament1SensorID": None,
49+
"filament2SensorID": None,
50+
},
51+
"filamentManager": {"enabled": False},
52+
"spoolManager": {"enabled": False},
53+
"preheatButton": {"enabled": True},
54+
"printTimeGenius": {"enabled": True},
55+
"psuControl": {"enabled": False},
56+
"ophom": {"enabled": False},
57+
"tpLinkSmartPlug": {"enabled": False, "smartPlugIP": "127.0.0.1"},
58+
"tasmota": {"enabled": False, "ip": "127.0.0.1", "index": None},
59+
"tasmotaMqtt": {
60+
"enabled": False,
61+
"topic": "topic",
62+
"relayNumber": None,
63+
},
64+
"tuya": {"enabled": False, "label": "label"},
65+
"wemo": {"enabled": False, "ip": "127.0.0.1", "port": 49152},
66+
},
67+
"octodash": {
68+
"customActions": [
69+
{
70+
"icon": "house",
71+
"command": "G28",
72+
"color": "#dcdde1",
73+
"confirm": False,
74+
"exit": True,
75+
},
76+
{
77+
"icon": "ruler-vertical",
78+
"command": "G29",
79+
"color": "#4bae50",
80+
"confirm": False,
81+
"exit": True,
82+
},
83+
{
84+
"icon": "fire-flame-curved",
85+
"command": "M140 S50; M104 S185",
86+
"color": "#e1b12c",
87+
"confirm": False,
88+
"exit": True,
89+
},
90+
{
91+
"icon": "snowflake",
92+
"command": "M140 S0; M104 S0",
93+
"color": "#0097e6",
94+
"confirm": False,
95+
"exit": True,
96+
},
97+
{
98+
"icon": "rotate-right",
99+
"command": "[!RELOAD]",
100+
"color": "#7f8fa6",
101+
"confirm": True,
102+
"exit": False,
103+
},
104+
{
105+
"icon": "power-off",
106+
"command": "[!SHUTDOWN]",
107+
"color": "#e84118",
108+
"confirm": True,
109+
"exit": False,
110+
},
111+
],
112+
"fileSorting": {"attribute": "name", "order": "asc"},
113+
"invertAxisControl": {"x": False, "y": False, "z": False},
114+
"pollingInterval": 2000,
115+
"touchscreen": True,
116+
"turnScreenOffWhileSleeping": False,
117+
"turnOnPrinterWhenExitingSleep": False,
118+
"preferPreviewWhilePrinting": False,
119+
"previewProgressCircle": False,
120+
"screenSleepCommand": "xset dpms force standby",
121+
"screenWakeupCommand": "xset s off && xset -dpms && xset s noblank",
122+
"showExtruderControl": True,
123+
"showNotificationCenterIcon": True,
124+
"defaultDirectory": "/",
125+
},
126+
}
127+
128+
##~~ Softwareupdate hook
129+
130+
def get_update_information(self):
131+
# Define the configuration for your plugin to use with the Software Update
132+
# Plugin here. See https://docs.octoprint.org/en/master/bundledplugins/softwareupdate.html
133+
# for details.
134+
return {
135+
"octodash": {
136+
"displayName": "Octodash Plugin",
137+
"displayVersion": self._plugin_version,
138+
# version check: github repository
139+
"type": "github_release",
140+
"user": "UnchartedBull",
141+
"repo": "Octodash",
142+
"current": self._plugin_version,
143+
# update method: pip
144+
"pip": "https://github.com/UnchartedBull/Octodash/archive/{target_version}.zip",
145+
}
146+
}
147+
148+
149+
__plugin_name__ = "Octodash Plugin"
150+
151+
152+
# Set the Python version your plugin is compatible with below. Recommended is Python 3 only for all new plugins.
153+
# OctoPrint 1.4.0 - 1.7.x run under both Python 3 and the end-of-life Python 2.
154+
# OctoPrint 1.8.0 onwards only supports Python 3.
155+
__plugin_pythoncompat__ = ">=3,<4" # Only Python 3
156+
157+
158+
def __plugin_load__():
159+
global __plugin_implementation__
160+
__plugin_implementation__ = OctodashPlugin()
161+
162+
global __plugin_hooks__
163+
__plugin_hooks__ = {
164+
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
165+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version = "__use_git__"
2+
branch = None
3+
revision = None

0 commit comments

Comments
 (0)