From 090306d37cb16868f001d7dc078d53d0f5356b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Dupr=C3=A9?= Date: Fri, 7 Sep 2018 16:17:09 +0200 Subject: [PATCH 1/5] Added module progress --- bumblebee/modules/progress.py | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 bumblebee/modules/progress.py diff --git a/bumblebee/modules/progress.py b/bumblebee/modules/progress.py new file mode 100644 index 0000000..bb55e2e --- /dev/null +++ b/bumblebee/modules/progress.py @@ -0,0 +1,70 @@ +""" +Show progress for cp, mv, dd, ... + +Parameters: + * progress.placeholder: Text to display while no process is running (defaults to "n/a") + * progress.barwidth: Width of the progressbar if it is used (defaults to 8) + * progress.format: Format string (defaults to "{bar} {cmd} {arg}") + Available values are: {bar} {pid} {cmd} {arg} {per} {qty} + +Requires the following executable: + * progress +""" + +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +import re + + +class Module(bumblebee.engine.Module): + + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text=self.get_progress_text) + ) + + def get_progress_text(self, widget): + if self.update_progress_info(widget): + width = self.parameter("barwidth", 8) + count = round((width * widget.get("per")) / 100) + bar = "[{}{}]".format( + "#" * count, + "--" * (width - count) + ) + + str_format = self.parameter("format", '{bar} {cmd} {arg}') + return " " + str_format.format( + bar = bar, + pid = widget.get("pid"), + cmd = widget.get("cmd"), + arg = widget.get("arg"), + per = widget.get("per"), + qty = widget.get("qty") + ) + else: + return self.parameter("placeholder", 'n/a') + + def update_progress_info(self, widget): + # This regex extracts following groups: + # 1. pid + # 2. command + # 3. arguments + # 4. progress (xx.x formated) + # 5. quantity (.. unit / .. unit formated) + extract_nospeed = re.compile("\[ *(\d*)\] ([a-zA-Z]*) (.*)\n\t(\d*\.*\d*)% \((.*)\)\n.*") + + try: + raw = bumblebee.util.execute("progress -q") + result = extract_nospeed.match(raw) + + widget.set("pid", int(result.group(1))) + widget.set("cmd", result.group(2)) + widget.set("arg", result.group(3)) + widget.set("per", float(result.group(4))) + widget.set("qty", result.group(5)) + return True + except Exception: + return False + From 870d4d75d5cbba3ff8470ed46271df6b0715dd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Dupr=C3=A9?= Date: Fri, 7 Sep 2018 16:36:09 +0200 Subject: [PATCH 2/5] Using progress's speed measures --- bumblebee/modules/progress.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/bumblebee/modules/progress.py b/bumblebee/modules/progress.py index bb55e2e..b53914a 100644 --- a/bumblebee/modules/progress.py +++ b/bumblebee/modules/progress.py @@ -5,7 +5,7 @@ Parameters: * progress.placeholder: Text to display while no process is running (defaults to "n/a") * progress.barwidth: Width of the progressbar if it is used (defaults to 8) * progress.format: Format string (defaults to "{bar} {cmd} {arg}") - Available values are: {bar} {pid} {cmd} {arg} {per} {qty} + Available values are: {bar} {pid} {cmd} {arg} {per} {qty} {spd} Requires the following executable: * progress @@ -41,23 +41,39 @@ class Module(bumblebee.engine.Module): cmd = widget.get("cmd"), arg = widget.get("arg"), per = widget.get("per"), - qty = widget.get("qty") + qty = widget.get("qty"), + spd = widget.get("spd"), + tim = widget.get("tim") ) else: return self.parameter("placeholder", 'n/a') def update_progress_info(self, widget): - # This regex extracts following groups: + # These regex extracts following groups: # 1. pid # 2. command # 3. arguments # 4. progress (xx.x formated) # 5. quantity (.. unit / .. unit formated) + # 6. speed + # 7. time remaining extract_nospeed = re.compile("\[ *(\d*)\] ([a-zA-Z]*) (.*)\n\t(\d*\.*\d*)% \((.*)\)\n.*") + extract_wtspeed = re.compile('\[ *(\d*)\] ([a-zA-Z]*) (.*)\n\t(\d*\.*\d*)% \((.*)\) (\d*\.\d .*) remaining (\d*:\d*:\d*)\n.*') try: - raw = bumblebee.util.execute("progress -q") - result = extract_nospeed.match(raw) + raw = bumblebee.util.execute("progress -qW 0.1") + result = extract_wtspeed.match(raw) + + if not result: + # Abord speed measures + raw = bumblebee.util.execute("progress -q") + result = extract_nospeed.match(raw) + + widget.set("spd", "??? b/s") + widget.set("tim", "??:??:??") + else: + widget.set("spd", result.group(6)) + widget.set("tim", result.group(7)) widget.set("pid", int(result.group(1))) widget.set("cmd", result.group(2)) From 56426ee0a6ed4b5cdbd79d649e23efc6021dffd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Dupr=C3=A9?= Date: Fri, 7 Sep 2018 16:48:03 +0200 Subject: [PATCH 3/5] Added parameters to module "progress" to change bar design, changed format keys --- bumblebee/modules/progress.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bumblebee/modules/progress.py b/bumblebee/modules/progress.py index b53914a..e111ce9 100644 --- a/bumblebee/modules/progress.py +++ b/bumblebee/modules/progress.py @@ -5,7 +5,9 @@ Parameters: * progress.placeholder: Text to display while no process is running (defaults to "n/a") * progress.barwidth: Width of the progressbar if it is used (defaults to 8) * progress.format: Format string (defaults to "{bar} {cmd} {arg}") - Available values are: {bar} {pid} {cmd} {arg} {per} {qty} {spd} + Available values are: {bar} {pid} {cmd} {arg} {percentage} {quantity} {speed} {time} + * progress.barfilledchar: Character used to draw the filled part of the bar (defaults to "#"), notice that it can be a string + * progress.baremptychar: Character used to draw the empty part of the bar (defaults to "-"), notice that it can be a string Requires the following executable: * progress @@ -29,9 +31,12 @@ class Module(bumblebee.engine.Module): if self.update_progress_info(widget): width = self.parameter("barwidth", 8) count = round((width * widget.get("per")) / 100) + filledchar = self.parameter("barfilledchar", "#") + emptychar = self.parameter("baremptychar", "-") + bar = "[{}{}]".format( - "#" * count, - "--" * (width - count) + filledchar * count, + emptychar * (width - count) ) str_format = self.parameter("format", '{bar} {cmd} {arg}') @@ -40,10 +45,10 @@ class Module(bumblebee.engine.Module): pid = widget.get("pid"), cmd = widget.get("cmd"), arg = widget.get("arg"), - per = widget.get("per"), - qty = widget.get("qty"), - spd = widget.get("spd"), - tim = widget.get("tim") + percentage = widget.get("per"), + quantity = widget.get("qty"), + speed = widget.get("spd"), + time = widget.get("tim") ) else: return self.parameter("placeholder", 'n/a') @@ -69,7 +74,7 @@ class Module(bumblebee.engine.Module): raw = bumblebee.util.execute("progress -q") result = extract_nospeed.match(raw) - widget.set("spd", "??? b/s") + widget.set("spd", "???.? B/s") widget.set("tim", "??:??:??") else: widget.set("spd", result.group(6)) From 384f23c34f26a7f1a4130487a8d245e77b9b8060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Dupr=C3=A9?= Date: Fri, 7 Sep 2018 17:14:40 +0200 Subject: [PATCH 4/5] Module progress: added states --- bumblebee/modules/progress.py | 14 +++++++++++++- themes/icons/awesome-fonts.json | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bumblebee/modules/progress.py b/bumblebee/modules/progress.py index e111ce9..79396ca 100644 --- a/bumblebee/modules/progress.py +++ b/bumblebee/modules/progress.py @@ -40,7 +40,7 @@ class Module(bumblebee.engine.Module): ) str_format = self.parameter("format", '{bar} {cmd} {arg}') - return " " + str_format.format( + return str_format.format( bar = bar, pid = widget.get("pid"), cmd = widget.get("cmd"), @@ -54,6 +54,8 @@ class Module(bumblebee.engine.Module): return self.parameter("placeholder", 'n/a') def update_progress_info(self, widget): + """Update widget's informations about the copy""" + # These regex extracts following groups: # 1. pid # 2. command @@ -89,3 +91,13 @@ class Module(bumblebee.engine.Module): except Exception: return False + def state(self, widget): + if self._active(): + return "copying" + return "pending" + + def _active(self): + """Checks wether a copy is running or not""" + raw = bumblebee.util.execute("progress -q") + return bool(raw) + diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 4d43115..699ab21 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -138,5 +138,8 @@ }, "taskwarrior": { "prefix": "  " + }, + "progress": { + "copying": { "prefix": "" } } } From 6d271fc745021336c9d45edb308deabfe03d76eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Dupr=C3=A9?= Date: Fri, 7 Sep 2018 17:31:47 +0200 Subject: [PATCH 5/5] Module progress: added dependancy in README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3232b17..c5ee5e4 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,7 @@ Modules and commandline utilities are only required for modules, the core itself * nvidia-smi (for module 'nvidiagpu') * sensors (for module 'sensors', as fallback) * zpool (for module 'zpool') +* progress (for module 'progress') # Examples Here are some screenshots for all themes that currently exist: