Make it use existing shutdown events

Also adds check to powerline-lint that "args" dictionary does not set
shutdown_event, segment_info or pl keyword arguments, this will lead to problems
This commit is contained in:
ZyX 2013-04-03 23:48:01 +04:00
parent f45084057a
commit f0e5f43d48
4 changed files with 22 additions and 5 deletions

View File

@ -235,6 +235,7 @@ class Powerline(object):
'ext': self.ext,
'common_config': self.common_config,
'run_once': self.run_once,
'shutdown_event': self.shutdown_event,
},
)

View File

@ -34,7 +34,6 @@ class ThreadedSegment(MultiRunnedThread):
def __init__(self):
super(ThreadedSegment, self).__init__()
self.shutdown_event = Event()
self.run_once = True
self.skip = False
self.crashed_value = None
@ -98,8 +97,9 @@ class ThreadedSegment(MultiRunnedThread):
interval = interval or getattr(self, 'interval')
self.interval = interval
def set_state(self, interval=None, update_first=True, **kwargs):
def set_state(self, interval=None, update_first=True, shutdown_event=None, **kwargs):
self.set_interval(interval)
self.shutdown_event = shutdown_event or Event()
self.updated = not (update_first and self.update_first)
def startup(self, pl, **kwargs):
@ -177,8 +177,9 @@ class KwThreadedSegment(ThreadedSegment):
return update_value
def set_state(self, interval=None, **kwargs):
def set_state(self, interval=None, shutdown_event=None, **kwargs):
self.set_interval(interval)
self.shutdown_event = shutdown_event or Event()
@staticmethod
def render_one(update_state, **kwargs):

View File

@ -242,6 +242,11 @@ class Spec(object):
msg_func))
return self
def error(self, msg):
self.checks.append(('check_func', lambda *args: (True, True, True),
lambda value: msg.format(value)))
return self
def either(self, *specs):
start = len(self.specs)
self.specs.extend(specs)
@ -788,6 +793,9 @@ def check_segment_data_key(key, data, context, echoerr):
args_spec = Spec(
interval=Spec().either(Spec().type(float), Spec().type(int)).optional(),
update_first=Spec().type(bool).optional(),
shutdown_event=Spec().error('Shutdown event must be set by powerline').optional(),
pl=Spec().error('pl object must be set by powerline').optional(),
segment_info=Spec().error('Segment info dictionary must be set by powerline').optional(),
).unknown_spec(Spec(), Spec()).optional().copy
highlight_group_spec = Spec().type(unicode).copy
segment_module_spec = Spec().type(unicode).func(check_segment_module).optional().copy

View File

@ -22,7 +22,14 @@ def requires_segment_info(func):
class Theme(object):
def __init__(self, ext, theme_config, common_config, pl, top_theme_config=None, run_once=False):
def __init__(self,
ext,
theme_config,
common_config,
pl,
top_theme_config=None,
run_once=False,
shutdown_event=None):
self.dividers = theme_config.get('dividers', common_config['dividers'])
self.spaces = theme_config.get('spaces', common_config['spaces'])
self.segments = {
@ -44,7 +51,7 @@ class Theme(object):
if not run_once:
if segment['startup']:
try:
segment['startup'](pl=pl, **segment['args'])
segment['startup'](pl=pl, shutdown_event=shutdown_event, **segment['args'])
except Exception as e:
pl.error('Exception during {0} startup: {1}', segment['name'], str(e))
continue