[modules/redshift] Update to latest framework
This commit is contained in:
parent
2592069fb9
commit
be2864b063
1 changed files with 25 additions and 21 deletions
|
@ -6,22 +6,26 @@ Requires the following executable:
|
||||||
* redshift
|
* redshift
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* redshift.location : location provider, either of 'geoclue2' (default), \
|
* redshift.location : location provider, either of 'auto' (default), 'geoclue2',
|
||||||
'ipinfo' (requires the requests package), or 'manual'
|
'ipinfo' (requires the requests package), or 'manual'
|
||||||
|
'auto' uses whatever redshift is configured to do
|
||||||
* redshift.lat : latitude if location is set to 'manual'
|
* redshift.lat : latitude if location is set to 'manual'
|
||||||
* redshift.lon : longitude if location is set to 'manual'
|
* redshift.lon : longitude if location is set to 'manual'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
try:
|
try:
|
||||||
import requests
|
import requests
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
log.warning('unable to import module "requests": Location via IP disabled')
|
||||||
|
|
||||||
import bumblebee.input
|
import core.module
|
||||||
import bumblebee.output
|
import core.widget
|
||||||
import bumblebee.engine
|
import core.input
|
||||||
|
|
||||||
|
import util.cli
|
||||||
|
|
||||||
def is_terminated():
|
def is_terminated():
|
||||||
for thread in threading.enumerate():
|
for thread in threading.enumerate():
|
||||||
|
@ -43,14 +47,14 @@ def get_redshift_value(widget, location, lat, lon):
|
||||||
break
|
break
|
||||||
widget.get('condition').release()
|
widget.get('condition').release()
|
||||||
|
|
||||||
command = ['redshift', '-p', '-l']
|
command = ['redshift', '-p']
|
||||||
if location == 'manual':
|
if location == 'manual':
|
||||||
command.append(lat + ':' + lon)
|
command.extend(['-l', '{}:{}'.format(lat, lon)])
|
||||||
else:
|
if location == 'geoclue2':
|
||||||
command.append('geoclue2')
|
command.extend(['-l', 'geoclue2'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = bumblebee.util.execute(' '.join(command))
|
res = util.cli.execute(' '.join(command))
|
||||||
except Exception:
|
except Exception:
|
||||||
res = ''
|
res = ''
|
||||||
widget.set('temp', 'n/a')
|
widget.set('temp', 'n/a')
|
||||||
|
@ -70,18 +74,18 @@ def get_redshift_value(widget, location, lat, lon):
|
||||||
widget.set('state', 'transition')
|
widget.set('state', 'transition')
|
||||||
widget.set('transition', ' '.join(line.split(' ')[2:]))
|
widget.set('transition', ' '.join(line.split(' ')[2:]))
|
||||||
|
|
||||||
|
class Module(core.module.Module):
|
||||||
|
def __init__(self, config=None):
|
||||||
|
widget = core.widget.Widget(self.text)
|
||||||
|
super().__init__(config, widget)
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
self._location = self.parameter('location', 'auto')
|
||||||
def __init__(self, engine, config):
|
|
||||||
widget = bumblebee.output.Widget(full_text=self.text)
|
|
||||||
super(Module, self).__init__(engine, config, widget)
|
|
||||||
|
|
||||||
self._location = self.parameter('location', 'geoclue2')
|
|
||||||
self._lat = self.parameter('lat', None)
|
self._lat = self.parameter('lat', None)
|
||||||
self._lon = self.parameter('lon', None)
|
self._lon = self.parameter('lon', None)
|
||||||
|
|
||||||
# Even if location method is set to manual, if we have no lat or lon,
|
# Even if location method is set to manual, if we have no lat or lon,
|
||||||
# fall back to the geoclue2 method.
|
# fall back to the geoclue2 method.
|
||||||
|
#
|
||||||
if self._location == 'manual' and (self._lat is None
|
if self._location == 'manual' and (self._lat is None
|
||||||
or self._lon is None):
|
or self._lon is None):
|
||||||
self._location == 'geoclue2'
|
self._location == 'geoclue2'
|
||||||
|
@ -102,8 +106,8 @@ class Module(bumblebee.engine.Module):
|
||||||
self._condition = threading.Condition()
|
self._condition = threading.Condition()
|
||||||
widget.set('condition', self._condition)
|
widget.set('condition', self._condition)
|
||||||
self._thread = threading.Thread(target=get_redshift_value,
|
self._thread = threading.Thread(target=get_redshift_value,
|
||||||
args=(widget, self._location,
|
args=(widget, self._location,
|
||||||
self._lat, self._lon))
|
self._lat, self._lon))
|
||||||
self._thread.start()
|
self._thread.start()
|
||||||
self._condition.acquire()
|
self._condition.acquire()
|
||||||
self._condition.notify()
|
self._condition.notify()
|
||||||
|
@ -112,8 +116,8 @@ class Module(bumblebee.engine.Module):
|
||||||
def text(self, widget):
|
def text(self, widget):
|
||||||
return '{}'.format(self._text)
|
return '{}'.format(self._text)
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self):
|
||||||
widget = widgets[0]
|
widget = self.widget()
|
||||||
self._condition.acquire()
|
self._condition.acquire()
|
||||||
self._condition.notify()
|
self._condition.notify()
|
||||||
self._condition.release()
|
self._condition.release()
|
||||||
|
|
Loading…
Reference in a new issue