Browse Source

plugins: improve readability, move to str().format() in many places

master
Von Random 1 year ago
parent
commit
d824345ba1
10 changed files with 23 additions and 17 deletions
  1. +1
    -1
      plugins/__init__.py
  2. +6
    -6
      plugins/batt.py
  3. +4
    -2
      plugins/date.py
  4. +1
    -0
      plugins/disk.py
  5. +1
    -1
      plugins/filecat.py
  6. +1
    -0
      plugins/fortune.py
  7. +2
    -1
      plugins/load.py
  8. +3
    -2
      plugins/mem.py
  9. +3
    -3
      plugins/pacman.py
  10. +1
    -1
      plugins/ping.py

+ 1
- 1
plugins/__init__.py View File

@ -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})


+ 6
- 6
plugins/batt.py View File

@ -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)

+ 4
- 2
plugins/date.py View File

@ -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)

+ 1
- 0
plugins/disk.py View File

@ -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)

+ 1
- 1
plugins/filecat.py View File

@ -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)

+ 1
- 0
plugins/fortune.py View File

@ -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):


+ 2
- 1
plugins/load.py View File

@ -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)

+ 3
- 2
plugins/mem.py View File

@ -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)

+ 3
- 3
plugins/pacman.py View File

@ -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)

+ 1
- 1
plugins/ping.py View File

@ -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…
Cancel
Save