forked from fieldOfView/Cura-OctoPrintPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
54 lines (44 loc) · 1.94 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright (c) 2019 Aldo Hoeben / fieldOfView
# OctoPrintPlugin is released under the terms of the AGPLv3 or higher.
import os, json
from . import OctoPrintOutputDevicePlugin
from . import DiscoverOctoPrintAction
from . import NetworkMJPGImage
from UM.Version import Version
from UM.Application import Application
from UM.Logger import Logger
from PyQt5.QtQml import qmlRegisterType
def getMetaData():
return {}
def register(app):
qmlRegisterType(NetworkMJPGImage.NetworkMJPGImage, "OctoPrintPlugin", 1, 0, "NetworkMJPGImage")
if __matchVersion():
return {
"output_device": OctoPrintOutputDevicePlugin.OctoPrintOutputDevicePlugin(),
"machine_action": DiscoverOctoPrintAction.DiscoverOctoPrintAction()
}
else:
Logger.log("w", "Plugin not loaded because of a version mismatch")
return {}
def __matchVersion():
cura_version = Application.getInstance().getVersion()
if cura_version == "master":
Logger.log("d", "Running Cura from source, ignoring version of the plugin")
return True
cura_version = Version(cura_version)
cura_version = Version([cura_version.getMajor(), cura_version.getMinor()])
# Get version information from plugin.json
plugin_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "plugin.json")
try:
with open(plugin_file_path) as plugin_file:
plugin_info = json.load(plugin_file)
minimum_cura_version = Version(plugin_info["minimum_cura_version"])
maximum_cura_version = Version(plugin_info["maximum_cura_version"])
except:
Logger.log("w", "Could not get version information for the plugin")
return False
if cura_version >= minimum_cura_version and cura_version <= maximum_cura_version:
return True
else:
Logger.log("d", "This version of the plugin is not compatible with this version of Cura. Please check for an update.")
return False