Skip to content

Commit

Permalink
Fix network check spamming
Browse files Browse the repository at this point in the history
Irritating logspam happens if network check reverts to old
method of checking connectivity. This change makes it only happen
ONCE.
  • Loading branch information
mrworf committed Jun 26, 2021
1 parent 9b8c855 commit f723040
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions modules/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

class helper:
TOOL_ROTATE = '/usr/bin/jpegtran'
NETWORK_CHECK = None

MIMETYPES = {
'image/jpeg' : 'jpg',
Expand Down Expand Up @@ -73,19 +74,25 @@ def getResolution():

@staticmethod
def getDeviceIp():
try:
import netifaces
if helper.NETWORK_CHECK is None:
try:
import netifaces
helper.NETWORK_CHECK = True
except ImportError:
logging.error('User has not installed python-netifaces, using checkNetwork() instead (depends on internet)')
helper.NETWORK_CHECK = False
except:
logging.exception('netifaces call failed, using checkNetwork() instead (depends on internet)')
helper.NETWORK_CHECK = False

if helper.NETWORK_CHECK:
if 'default' in netifaces.gateways() and netifaces.AF_INET in netifaces.gateways()['default']:
dev = netifaces.gateways()['default'][netifaces.AF_INET][1]
if netifaces.ifaddresses(dev) and netifaces.AF_INET in netifaces.ifaddresses(dev):
net = netifaces.ifaddresses(dev)[netifaces.AF_INET]
if len(net) > 0 and 'addr' in net[0]:
return net[0]['addr']
except ImportError:
logging.error('User has not installed python-netifaces, using checkNetwork() instead (depends on internet)')
return helper._checkNetwork()
except:
logging.exception('netifaces call failed, using checkNetwork() instead (depends on internet)')
else:
return helper._checkNetwork()

@staticmethod
Expand Down

0 comments on commit f723040

Please sign in to comment.