Closed EllieTheYeen closed 5 years ago
Ah I returned None by just writing return since the function will always return None if false and not an explicit false
I don't know what's happen that there is no your comment. But this method could be written in some other way to be more consistent.
Yes, so this part of code should be rewritten to be more consistent. Now I see problem. I just copied old code. @GoatTGirl on which HW you run it that you have problem with regex?
I see that you already closed this PR (?). Today I will try to rewrite this part of code.
This is so strange I clicked to comment once and it seemed to have done something weird
So this is what happens of I run the code on a Raspberry Pi which works as expected
>>> import re
>>> with open('/proc/cpuinfo', 'r') as infile:
... cpuinfo = infile.read()
...
>>> match = re.search('Hardware\s+:\s+(\w+)', cpuinfo, flags=re.MULTILINE | re.IGNORECASE)
>>>
>>> repr(match)
'<_sre.SRE_Match object at 0x769ff420>'
>>>
>>> match.group(1)
'BCM2835'
but the problem happens when I run it on another computer which I think has a x86 processor
>>> import re
>>> with open('/proc/cpuinfo', 'r') as infile:
... cpuinfo = infile.read()
...
>>> match = re.search('Hardware\s+:\s+(\w+)', cpuinfo, flags=re.MULTILINE | re.IGNORECASE)
>>>
>>> repr(match)
'None'
>>>
>>> match.group(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
And this happens at start so an error is raised and the plugin does not load
2018-10-21 15:18:00,655 - octoprint.plugin - ERROR - Error while calling plugin navbartemp
Traceback (most recent call last):
File "/home/klong/oprint/local/lib/python2.7/site-packages/OctoPrint-1.3.9-py2.7.egg/octoprint/plugin/__init__.py", line 225, in call_plugin
result = getattr(plugin, method)(*args, **kwargs)
File "/home/klong/oprint/local/lib/python2.7/site-packages/octoprint_navbartemp/__init__.py", line 35, in on_after_startup
self.sbc = SBCFactory().factory(self._logger)
File "/home/klong/oprint/local/lib/python2.7/site-packages/octoprint_navbartemp/libs/sbc.py", line 29, in factory
elif self._is_rpi(logger):
File "/home/klong/oprint/local/lib/python2.7/site-packages/octoprint_navbartemp/libs/sbc.py", line 45, in _is_rpi
if match.group(1) in self.piSocTypes:
AttributeError: 'NoneType' object has no attribute 'group'
@GoatTGirl I will make fix for this issue. I hope today
But I'm still thinking why regex is not working if you have rpi
It only works on a pi
The reason is that on some processors the line starting with "Hardware" will not exist in /proc/cpuinfo
@GoatTGirl are the newest changes working ok for you after plugin re-installation?
I see no more changes after what I did and yes they work now
The first commit that had the bug was 647d856597429d72c572fa03c7f3a32193c514c8 and when I upgraded to it the stuff broke
@GoatTGirl to be honest I don't understand you. Fix based on your part of code is already on a master. We could close discussion. If something is not working please report an issue.
No everything works perfectly fine
There was a crash that prevented the plugin from loading in octoprint due to re.search returning None causing match.group to raise an error