simplyprint-duet3d 1.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,87 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+ *.pyw
7
+ *.pyz
8
+ *.pyzw
9
+ *.pyc
10
+
11
+ # Virtual Environment
12
+ venv/
13
+ env/
14
+ env.bak/
15
+ env1/
16
+ env2/
17
+ .env
18
+ venv3.7/
19
+
20
+ # IDE
21
+ .vscode/
22
+ .idea/
23
+ *.sublime-project
24
+ *.sublime-workspace
25
+
26
+ # Logs and databases
27
+ *.log
28
+ *.sqlite3
29
+ *.db
30
+
31
+ # Compiled files
32
+ *.exe
33
+ *.dll
34
+ *.so
35
+ *.dylib
36
+
37
+ # Miscellaneous
38
+ .DS_Store
39
+ Thumbs.db
40
+
41
+ # Distribution / packaging
42
+ .Python
43
+ env/
44
+ build/
45
+ develop-eggs/
46
+ dist/
47
+ downloads/
48
+ eggs/
49
+ .eggs/
50
+ lib/
51
+ lib64/
52
+ parts/
53
+ sdist/
54
+ var/
55
+ *.egg-info/
56
+ .installed.cfg
57
+ *.egg
58
+
59
+ # PyInstaller
60
+ # Usually these files are written by a python script from a template
61
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
62
+ *.manifest
63
+ *.spec
64
+
65
+ # Unit test / coverage reports
66
+ htmlcov/
67
+ .tox/
68
+ .coverage
69
+ .coverage.*
70
+ .cache
71
+ nosetests.xml
72
+ coverage.xml
73
+ *,cover
74
+ .hypothesis/
75
+
76
+ # Translations
77
+ *.mo
78
+ *.pot
79
+
80
+ # Sphinx documentation
81
+ docs/_build/
82
+
83
+ # pyenv
84
+ .python-version
85
+
86
+ # vscode
87
+ .vscode
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.4
2
+ Name: simplyprint-duet3d
3
+ Version: 1.3.4
4
+ Summary: SimplyPrint integration with any Duet3D powered RepRapFirmware printers
5
+ Author-email: Tim Schneider <tim@meltingplot.net>, SimplyPrint <dev@simplyprint.io>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.9
8
+ Requires-Dist: aiohttp>=3.11.13
9
+ Requires-Dist: attrs>=25.1.0
10
+ Requires-Dist: imageio[ffmpeg]>=2.37.0
11
+ Requires-Dist: psutil>=6.1.1
12
+ Requires-Dist: pyee>=12.1.1
13
+ Requires-Dist: simplyprint-ws-client==1.0.1rc3
14
+ Requires-Dist: strenum>=0.4.15
15
+ Description-Content-Type: text/x-rst
16
+
17
+ SimplyPrint Duet3d integration
18
+ ================================================
19
+
20
+ Many thanks to `Tim Schneider <https://github.com/timschneider>`_ at https://github.com/Meltingplot/duet-simplyprint-connector/ for originally creating this integration and allowing us to use it.
21
+
22
+ This package acts as a bridge between Duet-based 3D printers and the SimplyPrint.io cloud service.
23
+
24
+ It communicates with the printer using the Duet HTTP API.
25
+ For more information, visit https://github.com/Duet3D/RepRapFirmware/wiki/HTTP-requests.
26
+
27
+ Communication with SimplyPrint.io is handled via the `simplyprint-ws-client`.
28
+
29
+ ------------
30
+ Status
31
+ ------------
32
+
33
+ Supported features:
34
+
35
+ - Printer registration
36
+ - Printer status update
37
+ - Webcam snapshot livestream
38
+ - GCode receiving
39
+ - File downloading
40
+ - Printer control (start, pause, resume, cancel)
41
+ - Self Upgrading VIA G-Code M997
42
+ - Device healts update
43
+ - Bed leveling
44
+ - Filament Sensor
45
+ - Duet auto discovery with tracking based on BoardID
46
+ - Leave a cookie on the printer to identify the printer in the future (`0:/sys/simplyprint-connector.json`)
47
+ - Grab the webcam url from DWC Settings file from the Printer
48
+ - Allow Webcam URL to be an Snapshot Endpoint or MJPEG Stream
49
+
50
+ Missing features:
51
+
52
+ - PSU Control
53
+ - GCode Macros / Scripts [not yet implemented by SimplyPrint.io for Duet]
54
+ - GCode terminal [not yet implemented by SimplyPrint.io for Duet]
55
+ - Receive messages from Printer in SimplyPrint.io [not yet implemented by SimplyPrint.io for Duet]
56
+
57
+
58
+ ------------
59
+ Installation
60
+ ------------
61
+ Open an SSH session to your SimplyPrint-connected device, such as a Raspberry Pi 4B.
62
+
63
+ .. code-block:: sh
64
+
65
+ source <(curl -sSL https://raw.githubusercontent.com/simplyprint/integration-duet3d/refs/heads/main/install.sh)
66
+
67
+
68
+ -----------------------------
69
+ Content of DuetConnector.json
70
+ -----------------------------
71
+
72
+ The default password for the Duet is `reprap`, even if the web interface does not require a login.
73
+
74
+ .. code-block:: json
75
+
76
+ [
77
+ {
78
+ "id": null,
79
+ "token": null,
80
+ "name": null,
81
+ "in_setup": true,
82
+ "short_id": null,
83
+ "public_ip": null,
84
+ "unique_id": "...",
85
+ "duet_uri": "http://192.168.1.0",
86
+ "duet_password": "reprap",
87
+ "duet_unique_id": "YOUR_DUET_BOARD_ID",
88
+ "duet_name": "YOUR_DUET_NAME",
89
+ "webcam_uri": "http://URI_OF_WEBCAM_SNAPSHOT_ENDPOINT/webcam"
90
+ }
91
+ ]
92
+
93
+
94
+ -----------------------------------------------
95
+ Usage of Meltingplot Duet SimplyPrint Connector
96
+ -----------------------------------------------
97
+
98
+ - Create a configuration with `simplyprint autodiscover`
99
+ - *Optional* Edit the configuration file `~/.config/SimplyPrint/DuetConnector.json`
100
+ - Start the duet simplyprint connector with `simplyprint start` or `systemctl start simplyprint-connector.service`
101
+ - Add the printer via the SimplyPrint.io web interface.
@@ -0,0 +1,85 @@
1
+ SimplyPrint Duet3d integration
2
+ ================================================
3
+
4
+ Many thanks to `Tim Schneider <https://github.com/timschneider>`_ at https://github.com/Meltingplot/duet-simplyprint-connector/ for originally creating this integration and allowing us to use it.
5
+
6
+ This package acts as a bridge between Duet-based 3D printers and the SimplyPrint.io cloud service.
7
+
8
+ It communicates with the printer using the Duet HTTP API.
9
+ For more information, visit https://github.com/Duet3D/RepRapFirmware/wiki/HTTP-requests.
10
+
11
+ Communication with SimplyPrint.io is handled via the `simplyprint-ws-client`.
12
+
13
+ ------------
14
+ Status
15
+ ------------
16
+
17
+ Supported features:
18
+
19
+ - Printer registration
20
+ - Printer status update
21
+ - Webcam snapshot livestream
22
+ - GCode receiving
23
+ - File downloading
24
+ - Printer control (start, pause, resume, cancel)
25
+ - Self Upgrading VIA G-Code M997
26
+ - Device healts update
27
+ - Bed leveling
28
+ - Filament Sensor
29
+ - Duet auto discovery with tracking based on BoardID
30
+ - Leave a cookie on the printer to identify the printer in the future (`0:/sys/simplyprint-connector.json`)
31
+ - Grab the webcam url from DWC Settings file from the Printer
32
+ - Allow Webcam URL to be an Snapshot Endpoint or MJPEG Stream
33
+
34
+ Missing features:
35
+
36
+ - PSU Control
37
+ - GCode Macros / Scripts [not yet implemented by SimplyPrint.io for Duet]
38
+ - GCode terminal [not yet implemented by SimplyPrint.io for Duet]
39
+ - Receive messages from Printer in SimplyPrint.io [not yet implemented by SimplyPrint.io for Duet]
40
+
41
+
42
+ ------------
43
+ Installation
44
+ ------------
45
+ Open an SSH session to your SimplyPrint-connected device, such as a Raspberry Pi 4B.
46
+
47
+ .. code-block:: sh
48
+
49
+ source <(curl -sSL https://raw.githubusercontent.com/simplyprint/integration-duet3d/refs/heads/main/install.sh)
50
+
51
+
52
+ -----------------------------
53
+ Content of DuetConnector.json
54
+ -----------------------------
55
+
56
+ The default password for the Duet is `reprap`, even if the web interface does not require a login.
57
+
58
+ .. code-block:: json
59
+
60
+ [
61
+ {
62
+ "id": null,
63
+ "token": null,
64
+ "name": null,
65
+ "in_setup": true,
66
+ "short_id": null,
67
+ "public_ip": null,
68
+ "unique_id": "...",
69
+ "duet_uri": "http://192.168.1.0",
70
+ "duet_password": "reprap",
71
+ "duet_unique_id": "YOUR_DUET_BOARD_ID",
72
+ "duet_name": "YOUR_DUET_NAME",
73
+ "webcam_uri": "http://URI_OF_WEBCAM_SNAPSHOT_ENDPOINT/webcam"
74
+ }
75
+ ]
76
+
77
+
78
+ -----------------------------------------------
79
+ Usage of Meltingplot Duet SimplyPrint Connector
80
+ -----------------------------------------------
81
+
82
+ - Create a configuration with `simplyprint autodiscover`
83
+ - *Optional* Edit the configuration file `~/.config/SimplyPrint/DuetConnector.json`
84
+ - Start the duet simplyprint connector with `simplyprint start` or `systemctl start simplyprint-connector.service`
85
+ - Add the printer via the SimplyPrint.io web interface.
@@ -0,0 +1,55 @@
1
+ [project]
2
+ name = "simplyprint-duet3d"
3
+ version = "1.3.4"
4
+ description = "SimplyPrint integration with any Duet3D powered RepRapFirmware printers "
5
+ readme = "README.rst"
6
+ license-files = ["LICENSE"]
7
+ requires-python = ">=3.9"
8
+ authors = [
9
+ { name = "Tim Schneider", email = "tim@meltingplot.net" },
10
+ { name = "SimplyPrint", email = "dev@simplyprint.io" },
11
+ ]
12
+ dependencies = [
13
+ "aiohttp>=3.11.13",
14
+ "attrs>=25.1.0",
15
+ "imageio[ffmpeg]>=2.37.0",
16
+ "psutil>=6.1.1",
17
+ "pyee>=12.1.1",
18
+ "simplyprint-ws-client==1.0.1rc3",
19
+ "strenum>=0.4.15",
20
+ ]
21
+
22
+ [dependency-groups]
23
+ dev = [
24
+ "bandit>=1.8.3",
25
+ "flake8>=7.1.2",
26
+ "flake8-blind-except>=0.2.1",
27
+ "flake8-bugbear>=24.12.12",
28
+ "flake8-builtins>=2.5.0",
29
+ "flake8-commas>=4.0.0",
30
+ "flake8-comprehensions>=3.16.0",
31
+ "flake8-docstrings>=1.7.0",
32
+ "flake8-import-order>=0.18.2",
33
+ "pep8-naming>=0.14.1",
34
+ "pytest-asyncio>=0.25.3",
35
+ "pytest-cov>=6.0.0",
36
+ "pytest-mock>=3.14.0",
37
+ "versioneer>=0.29",
38
+ "yapf>=0.43.0",
39
+ ]
40
+
41
+ [project.scripts]
42
+ simplyprint-duet3d = "simplyprint_duet3d.__main__:main"
43
+
44
+ [build-system]
45
+ requires = ["hatchling"]
46
+ build-backend = "hatchling.build"
47
+
48
+ [tool.hatch.build]
49
+ include = [
50
+ "simplyprint_duet3d",
51
+ ]
52
+
53
+ artifacts = [
54
+ "simplyprint-connector.service"
55
+ ]
@@ -0,0 +1,17 @@
1
+ [Unit]
2
+ Description=Meltingplot Duet <-> SimplyPrint.io connector
3
+ After=network.target
4
+
5
+ [Service]
6
+ Type=simple
7
+ Restart=always
8
+ StartLimitInterval=0
9
+ StartLimitBurst=1440
10
+ RestartSec=60
11
+ ExecStart=/usr/local/bin/simplyprint start
12
+ WorkingDirectory=/usr/local
13
+ User=ubuntu
14
+ Group=ubuntu
15
+
16
+ [Install]
17
+ WantedBy=multi-user.target
@@ -0,0 +1,7 @@
1
+ """Initialize the duet_simplyprint_connector package."""
2
+ import importlib.metadata
3
+
4
+ try:
5
+ __version__ = importlib.metadata.version("simplyprint_duet3d")
6
+ except importlib.metadata.PackageNotFoundError:
7
+ __version__ = "0.0.0"
@@ -0,0 +1,135 @@
1
+ """Main entry point for the Duet SimplyPrint connector."""
2
+ import ipaddress
3
+ import logging
4
+ import socket
5
+ from urllib.parse import urlparse
6
+
7
+ import PIL # noqa
8
+
9
+ import click
10
+
11
+ from simplyprint_ws_client.core.app import ClientApp
12
+ from simplyprint_ws_client.core.config import ConfigManagerType
13
+ from simplyprint_ws_client.core.settings import ClientSettings
14
+ from simplyprint_ws_client.core.ws_protocol.connection import ConnectionMode
15
+ from simplyprint_ws_client.shared.cli.cli import ClientCli
16
+ from simplyprint_ws_client.shared.logging import ClientHandler
17
+ from simplyprint_ws_client.shared.sp.url_builder import SimplyPrintBackend
18
+
19
+ from . import __version__
20
+ from .cli.autodiscover import AutoDiscover
21
+ from .cli.install import install_as_service
22
+ from .virtual_client import VirtualClient, VirtualConfig
23
+
24
+
25
+ def rescan_existing_networks(app):
26
+ """
27
+ Rescan the existing networks.
28
+
29
+ Gather all the existing networks and password from the configuration
30
+ manager and scan them.
31
+ """
32
+ configs = app.config_manager.get_all()
33
+ networks = {}
34
+ for config in configs:
35
+ try:
36
+ # Attempt to resolve the URI as a URL via DNS
37
+ hostname = urlparse(config.duet_uri).hostname # Extract hostname from URI
38
+
39
+ addr_info = socket.getaddrinfo(hostname, None)
40
+ for result in addr_info:
41
+ family, socktype, _, _, sockaddr = result
42
+ if socktype == socket.SOCK_STREAM:
43
+ if family == socket.AF_INET:
44
+ ip_address = sockaddr[0]
45
+ network = ipaddress.ip_network(ip_address, strict=False).supernet(new_prefix=24)
46
+ break
47
+ elif family == socket.AF_INET6:
48
+ ip_address = sockaddr[0]
49
+ # Using /64 as prefix is to large as it includes 18,446,744,073,709,551,616 addresses
50
+ # Using /120 as prefix is small enough as it includes 256 addresses
51
+ network = ipaddress.ip_network(ip_address, strict=False).supernet(new_prefix=120)
52
+ break
53
+ except (socket.gaierror, ValueError, TypeError):
54
+ # If DNS resolution fails, treat it as an IP address directly
55
+ network = ipaddress.ip_network(config.duet_uri, strict=False).supernet(new_prefix=24)
56
+ networks[f"{network}"] = config.duet_password
57
+ return networks
58
+
59
+
60
+ def run_app(autodiscover, app, profile):
61
+ """Run the application."""
62
+ click.echo("Starting the Meltingplot Duet SimplyPrint.io Connector")
63
+ click.echo('Perform network scans for existing networks')
64
+
65
+ networks = rescan_existing_networks(app)
66
+
67
+ for network, pwd in networks.items():
68
+ click.echo(f"Scanning existing network: {network} with password {pwd}")
69
+ if ':' in network:
70
+ autodiscover._autodiscover(password=pwd, ipv6_range=network, ipv4_range='127.0.0.1/32')
71
+ else:
72
+ autodiscover._autodiscover(password=pwd, ipv4_range=network, ipv6_range="::1/128")
73
+
74
+ if profile:
75
+ import cProfile
76
+ import atexit
77
+ import pstats
78
+ import io
79
+
80
+ click.echo("Profiling enabled")
81
+ pr = cProfile.Profile()
82
+ pr.enable()
83
+
84
+ def app_exit():
85
+ click.echo("Exiting the Meltingplot Duet SimplyPrint.io Connector")
86
+ pr.disable()
87
+ s = io.StringIO()
88
+ sortby = 'cumulative'
89
+ ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
90
+ ps.print_stats()
91
+ click.echo(s.getvalue())
92
+
93
+ atexit.register(app_exit)
94
+
95
+ app.run_blocking()
96
+
97
+
98
+ def main():
99
+ """Initiate the connector as the main entry point."""
100
+ settings = ClientSettings(
101
+ name="DuetConnector",
102
+ version=__version__,
103
+ mode=ConnectionMode.MULTI,
104
+ client_factory=VirtualClient,
105
+ config_factory=VirtualConfig,
106
+ allow_setup=True,
107
+ config_manager_t=ConfigManagerType.JSON,
108
+ backend=SimplyPrintBackend.PRODUCTION,
109
+ )
110
+
111
+ ClientHandler.setup_logging(settings)
112
+ logging.getLogger().setLevel(logging.INFO)
113
+ logging.getLogger("PIL").setLevel(logging.INFO)
114
+ logging.getLogger("aiohttp.client").setLevel(logging.INFO)
115
+
116
+ app = ClientApp(settings)
117
+ cli = ClientCli(app)
118
+
119
+ autodiscover = AutoDiscover(app)
120
+
121
+ cli.add_command(autodiscover.autodiscover)
122
+ cli.add_command(install_as_service)
123
+ cli.add_command(
124
+ click.Command(
125
+ "start",
126
+ callback=lambda profile: run_app(autodiscover, app, profile),
127
+ help="Start the client",
128
+ params=[click.Option(["--profile"], is_flag=True, help="Enable profiling")],
129
+ ),
130
+ )
131
+ cli(prog_name="python -m simplyprint_duet3d")
132
+
133
+
134
+ if __name__ == "__main__":
135
+ main()