selinux: fix exception, remove hardcoded strings
"""
Display SELinux state.
-This module displays the current state of selinux on your machine: Enforcing
-(good), Permissive (bad), or Disabled (bad).
+This module displays the current state of selinux on your machine:
+Enforcing (good), Permissive (bad), or Disabled (bad).
Configuration parameters:
- cache_timeout: how often we refresh this module in seconds (default 10)
- format: see placeholders below, (default 'selinux: {state}')
+ cache_timeout: refresh interval for this module (default 10)
+ format: display format for this module (default 'selinux: {state}')
+ string_disabled: show when no SELinux policy is loaded.
+ (default 'disabled')
+ string_enforcing: show when SELinux security policy is enforced.
+ (default 'enforcing')
+ string_permissive: show when SELinux prints warnings instead of enforcing.
+ (default 'permissive')
Format placeholders:
- {state} the current selinux state
+ {state} current selinux state
Color options:
color_bad: Enforcing
@@ -18,9 +24,7 @@ Color options:
color_good: Disabled
Requires:
- libselinux-python:
- or
- libselinux-python3: (optional for python3 support)
+ libselinux-python: SELinux python bindings for libselinux
@author bstinsonmhk
@license BSD
@@ -36,27 +40,28 @@ class Py3status:
# available configuration parameters
cache_timeout = 10
format = 'selinux: {state}'
+ string_disabled = 'disabled'
+ string_enforcing = 'enforcing'
+ string_permissive = 'permissive'
def selinux_status(self):
try:
if selinux.security_getenforce():
- selinuxstring = 'enforcing'
+ state = self.string_enforcing
color = self.py3.COLOR_GOOD
else:
- selinuxstring = 'permissive'
+ state = self.string_permissive
color = self.py3.COLOR_BAD
- except OSError:
- selinuxstring = 'disabled'
+ except:
+ state = self.string_disabled
color = self.py3.COLOR_BAD
- response = {
+ return {
'cached_until': self.py3.time_in(self.cache_timeout),
- 'full_text': self.py3.safe_format(self.format, {'state': selinuxstring}),
- 'color': color,
+ 'full_text': self.py3.safe_format(self.format, {'state': state}),
+ 'color': color
}
- return response
-
if __name__ == '__main__':
"""
