[modules/progress] Update to latest API

This commit is contained in:
tobi-wan-kenobi 2020-04-10 17:11:06 +02:00
parent 55c8f6af28
commit 9b50e96b21

View file

@ -13,23 +13,22 @@ Requires the following executable:
* progress * progress
""" """
import bumblebee.input import core.module
import bumblebee.output import core.widget
import bumblebee.engine
import util.cli
import util.format
import re import re
class Module(core.module.Module):
class Module(bumblebee.engine.Module): def __init__(self, config):
super().__init__(config, core.widget.Widget(self.get_progress_text))
def __init__(self, engine, config): self.__active = False
super(Module, self).__init__(engine, config,
bumblebee.output.Widget(full_text=self.get_progress_text)
)
def get_progress_text(self, widget): def get_progress_text(self, widget):
if self.update_progress_info(widget): if self.update_progress_info(widget):
width = self.parameter('barwidth', 8) width = util.format.asint(self.parameter('barwidth', 8))
count = round((width * widget.get('per')) / 100) count = round((width * widget.get('per')) / 100)
filledchar = self.parameter('barfilledchar', '#') filledchar = self.parameter('barfilledchar', '#')
emptychar = self.parameter('baremptychar', '-') emptychar = self.parameter('baremptychar', '-')
@ -55,6 +54,7 @@ class Module(bumblebee.engine.Module):
def update_progress_info(self, widget): def update_progress_info(self, widget):
"""Update widget's informations about the copy""" """Update widget's informations about the copy"""
if not self.__active: return
# These regex extracts following groups: # These regex extracts following groups:
# 1. pid # 1. pid
@ -68,12 +68,12 @@ class Module(bumblebee.engine.Module):
extract_wtspeed = re.compile('\[ *(\d*)\] ([a-zA-Z]*) (.*)\n\t(\d*\.*\d*)% \((.*)\) (\d*\.\d .*) remaining (\d*:\d*:\d*)\n.*') extract_wtspeed = re.compile('\[ *(\d*)\] ([a-zA-Z]*) (.*)\n\t(\d*\.*\d*)% \((.*)\) (\d*\.\d .*) remaining (\d*:\d*:\d*)\n.*')
try: try:
raw = bumblebee.util.execute('progress -qW 0.1') raw = util.cli.execute('progress -qW 0.1')
result = extract_wtspeed.match(raw) result = extract_wtspeed.match(raw)
if not result: if not result:
# Abord speed measures # Abord speed measures
raw = bumblebee.util.execute('progress -q') raw = util.cli.execute('progress -q')
result = extract_nospeed.match(raw) result = extract_nospeed.match(raw)
widget.set('spd', '???.? B/s') widget.set('spd', '???.? B/s')
@ -91,14 +91,12 @@ class Module(bumblebee.engine.Module):
except Exception: except Exception:
return False return False
def update(self):
self.__active = bool(util.cli.execute('progress -q'))
def state(self, widget): def state(self, widget):
if self._active(): if self.__active:
return 'copying' return 'copying'
return 'pending' return 'pending'
def _active(self):
"""Checks wether a copy is running or not"""
raw = bumblebee.util.execute('progress -q')
return bool(raw)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4