plugins: improve readability, move to str().format() in many places
This commit is contained in:
parent
bd549b0cc9
commit
d824345ba1
10 changed files with 23 additions and 17 deletions
|
@ -19,7 +19,7 @@ class PluginThreadCommon:
|
|||
|
||||
def format_status(self, status, urgent=False):
|
||||
if 'title' in self.conf:
|
||||
full_text = self.conf['title'] + ': ' + status
|
||||
full_text = '{}: {}'.format(self.conf['title'], status)
|
||||
else:
|
||||
full_text = status
|
||||
self.status.update({'full_text': full_text, 'urgent': urgent})
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import plugins
|
||||
|
||||
|
||||
BATTERY_DIR = '/sys/class/power_supply/BAT0/'
|
||||
BATT_DEFAULTS = {
|
||||
'problem': 15,
|
||||
'symbol_charging': '\u2191',
|
||||
|
@ -15,10 +14,10 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
|
||||
def main(self):
|
||||
with \
|
||||
open(BATTERY_DIR + 'capacity', 'r') as batt_capacity, \
|
||||
open(BATTERY_DIR + 'status', 'r') as batt_status:
|
||||
capacity = batt_capacity.readline().strip()
|
||||
status_value = batt_status.readline().strip()
|
||||
open('/sys/class/power_supply/BAT0/capacity', 'r') as bcap, \
|
||||
open('/sys/class/power_supply/BAT0/status', 'r') as bstat:
|
||||
capacity = bcap.readline().strip()
|
||||
status_value = bstat.readline().strip()
|
||||
|
||||
if status_value != 'Discharging':
|
||||
symbol = self.conf['symbol_charging']
|
||||
|
@ -27,4 +26,5 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
symbol = self.conf['symbol_discharging']
|
||||
urgent = float(capacity) <= self.conf['problem']
|
||||
|
||||
self.format_status(capacity + '% ' + symbol, urgent=urgent)
|
||||
status = '{}% {}'.format(capacity, symbol)
|
||||
self.format_status(status, urgent)
|
||||
|
|
|
@ -14,5 +14,7 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
self.timezone = pytz.timezone(self.conf['tz'])
|
||||
|
||||
def main(self):
|
||||
now = datetime.datetime.now(tz=self.timezone)
|
||||
self.format_status(now.strftime(self.conf['format']))
|
||||
now = datetime.datetime\
|
||||
.now(tz=self.timezone)\
|
||||
.strftime(self.conf['format'])
|
||||
self.format_status(now)
|
||||
|
|
|
@ -19,5 +19,6 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
else:
|
||||
self.hide = True
|
||||
self.status['urgent'] = False
|
||||
|
||||
status = '{:.2f}G'.format(du_stat.free / 2**30)
|
||||
self.format_status(status)
|
||||
|
|
|
@ -11,7 +11,6 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
def __init__(self, config):
|
||||
super(PluginThread, self).__init__(config, FILECAT_DEFAULTS)
|
||||
self.hide = False
|
||||
self.format_status(self.conf['title'], False)
|
||||
|
||||
def main(self):
|
||||
try:
|
||||
|
@ -21,4 +20,5 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
except FileNotFoundError:
|
||||
contents = self.conf['nofile']
|
||||
urgent = True
|
||||
|
||||
self.format_status(contents, urgent)
|
||||
|
|
|
@ -25,6 +25,7 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
except requests.exceptions.ConnectionError:
|
||||
fortune = 'N/A (offline)'
|
||||
self.retry = True
|
||||
|
||||
self.format_status(fortune)
|
||||
|
||||
def run(self):
|
||||
|
|
|
@ -18,4 +18,5 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
self.hide = True
|
||||
urgent = False
|
||||
status = '{:.2f} {:.2f} {:.2f}'.format(*loads)
|
||||
self.format_status(status, urgent=urgent)
|
||||
|
||||
self.format_status(status, urgent)
|
||||
|
|
|
@ -17,5 +17,6 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
else:
|
||||
self.hide = True
|
||||
urgent = False
|
||||
mem_available = round(mem_stat.available / 2**30, 2)
|
||||
self.format_status('{:.2f}G'.format(mem_available), urgent)
|
||||
|
||||
status = '{:.2f}G'.format(mem_stat.available / 2**30)
|
||||
self.format_status(status, urgent)
|
||||
|
|
|
@ -24,6 +24,6 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
self.hide = False
|
||||
else:
|
||||
self.hide = True
|
||||
self.format_status(
|
||||
str(packages), urgent=packages >= self.conf['problem']
|
||||
)
|
||||
|
||||
urgent = packages >= self.conf['problem']
|
||||
self.format_status(packages, urgent)
|
||||
|
|
|
@ -23,4 +23,4 @@ class PluginThread(plugins.PluginThreadCommon):
|
|||
if fping.returncode == 0:
|
||||
self.format_status('up')
|
||||
else:
|
||||
self.format_status('down', urgent=True)
|
||||
self.format_status('down', True)
|
||||
|
|
Loading…
Reference in a new issue