-
Notifications
You must be signed in to change notification settings - Fork 10
Bugfix/sw 300 software update refresh issue #1447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rc/beta
Are you sure you want to change the base?
Changes from all commits
78310c5
321f0c0
8d22e4e
06e6794
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,10 +13,10 @@ | |
| _instance = None | ||
|
|
||
|
|
||
| def deviceInfo(use_dummy_values=False): | ||
| def deviceInfo(plugin, use_dummy_values=False): | ||
| global _instance | ||
| if _instance is None: | ||
| _instance = DeviceInfo(use_dummy_values=use_dummy_values) | ||
| _instance = DeviceInfo(plugin, use_dummy_values=use_dummy_values) | ||
| return _instance | ||
|
|
||
|
|
||
|
|
@@ -48,8 +48,9 @@ class DeviceInfo(object): | |
| KEY_PRODUCTION_DATE = "production_date" | ||
| KEY_MODEL = "model" | ||
|
|
||
| def __init__(self, use_dummy_values=False): | ||
| def __init__(self, plugin, use_dummy_values=False): | ||
| self._logger = mrb_logger("octoprint.plugins.mrbeam.util.device_info") | ||
| self._plugin = plugin | ||
| self._device_data = ( | ||
| self._read_file() if not use_dummy_values else self._get_dummy_values() | ||
| ) | ||
|
|
@@ -137,6 +138,42 @@ def get_beamos_version_number(self): | |
| self._logger.debug("beamos_version invalid: " + beamos_version) | ||
| return None | ||
|
|
||
| def get_software_versions(self): | ||
| result = dict() | ||
| software_info = None | ||
|
|
||
| try: | ||
| plugin_info = self._plugin._plugin_manager.get_plugin_info("softwareupdate") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is softwareupdate_plugin_info right? This is also the only place where we need the plugin... I don't think we need to store a reference to the plugin from the DeviceInfo. It seems like to initialise this class we need to pass any plugin to it... Doesn't feel like it belongs here... If we need the softwareupdate info I think we should directly pass it in the constructor. |
||
| impl = plugin_info.implementation | ||
| # using the method get_current_versions() is OK as it is threadsafe | ||
| software_info, _, _ = impl.get_current_versions() | ||
| self._logger.debug("Software_info: \n {}".format(software_info)) | ||
| except Exception as e: | ||
| self._logger.exception( | ||
| "Exception while reading software_info from softwareupdate plugin. Error:{} ".format(e) | ||
| ) | ||
| return result | ||
|
|
||
| if isinstance(software_info, dict) is False: | ||
| self._logger.warn( | ||
| "get_current_versions() Can't read software version from softwareupdate plugin." | ||
| ) | ||
| return result | ||
|
|
||
| # Reaching this section means we are OK so far | ||
| for name, info in software_info.iteritems(): | ||
| commit_hash = info["information"]["local"].get("name", None) | ||
| if commit_hash is not None: | ||
| # regex: "Commit 89nhfbffnf7f8fbfgfndhf" --> "89nhfbffnf7f8fbfgfndhf" | ||
| regex_match = re.match(r"Commit (\S+)", commit_hash) | ||
| if regex_match is not None: | ||
| commit_hash = regex_match.group(1) | ||
| result[name] = dict( | ||
| version=info.get("displayVersion", None), | ||
| commit_hash=commit_hash, | ||
| ) | ||
| return result | ||
|
|
||
| def _read_file(self): | ||
| try: | ||
| # See configparser for a better solution | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using quotes you could try to use some of flask filters to make it easier. They seem to be pretty powerful.
Here is an example that would match this needs using tojson and safe https://stackoverflow.com/questions/24719592/sending-data-as-json-object-from-python-to-javascript-with-jinja
You would also need to remove the json.dumps call on the initialisation.