From 8a50eb6f81ee31764950d70ecd47cb0ae17a784b Mon Sep 17 00:00:00 2001 From: Marco Genasci Date: Thu, 6 Jan 2022 08:06:57 +0100 Subject: [PATCH 1/2] New module emerge_status Display information about the currently running emerge process. Signed-off-by: Marco Genasci --- .../modules/contrib/emerge_status.py | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 bumblebee_status/modules/contrib/emerge_status.py diff --git a/bumblebee_status/modules/contrib/emerge_status.py b/bumblebee_status/modules/contrib/emerge_status.py new file mode 100644 index 0000000..3758585 --- /dev/null +++ b/bumblebee_status/modules/contrib/emerge_status.py @@ -0,0 +1,113 @@ +"""Display information about the currently running emerge process. + +Requires the following executable: + * emerge + +Parameters: + * emerge_status.format: Format string (defaults to '{current}/{total} {action} {category}/{pkg}') + +This code is based on emerge_status module from p3status [1] original created by AnwariasEu. + +[1] https://github.com/ultrabug/py3status/blob/master/py3status/modules/emerge_status.py +""" + +import re +import copy + +import core.module +import core.widget +import core.decorators + +import util.cli +import util.format + + +class Module(core.module.Module): + @core.decorators.every(seconds=10) + def __init__(self, config, theme): + super().__init__(config, theme, []) + self.__format = self.parameter( + "format", "{current}/{total} {action} {category}/{pkg}" + ) + self.__ret_default = { + "action": "", + "category": "", + "current": 0, + "pkg": "", + "total": 0, + } + + def update(self): + response = {} + ret = copy.deepcopy(self.__ret_default) + if self.__emerge_running(): + ret = self.__get_progress() + + widget = self.widget("status") + if not widget: + widget = self.add_widget(name="status") + + if ret["total"] == 0: + widget.full_text("emrg calculating...") + else: + widget.full_text( + " ".join( + self.__format.format( + current=ret["current"], + total=ret["total"], + action=ret["action"], + category=ret["category"], + pkg=ret["pkg"], + ).split() + ) + ) + else: + self.clear_widgets() + + def __emerge_running(self): + """ + Check if emerge is running. + Returns true if at least one instance of emerge is running. + """ + try: + util.cli.execute("pgrep emerge") + return True + except Exception: + return False + + def __get_progress(self): + """ + Get current progress of emerge. + Returns a dict containing current and total value. + """ + input_data = [] + ret = {} + + # traverse emerge.log from bottom up to get latest information + last_lines = util.cli.execute("tail -50 /var/log/emerge.log") + input_data = last_lines.split("\n") + input_data.reverse() + + for line in input_data: + if "*** terminating." in line: + # copy content of ret_default, not only the references + ret = copy.deepcopy(self.__ret_default) + break + else: + status_re = re.compile( + r"\((?P[\d]+) of (?P[\d]+)\) " + r"(?P[a-zA-Z/]+( [a-zA-Z]+)?) " + r"\((?P[\w\-]+)/(?P

[\w.]+)" + ) + res = status_re.search(line) + if res is not None: + ret["action"] = res.group("a").lower() + ret["category"] = res.group("ca") + ret["current"] = res.group("cu") + ret["pkg"] = res.group("p") + ret["total"] = res.group("t") + break + return ret + + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From f4ca5eaa3b177a874da07cc0946fd99b4016f239 Mon Sep 17 00:00:00 2001 From: Marco Genasci Date: Thu, 6 Jan 2022 08:07:49 +0100 Subject: [PATCH 2/2] Added documentation and screenshot for emerge_status module Signed-off-by: Marco Genasci --- docs/modules.rst | 15 +++++++++++++++ screenshots/emerge_status.png | Bin 0 -> 9403 bytes 2 files changed, 15 insertions(+) create mode 100644 screenshots/emerge_status.png diff --git a/docs/modules.rst b/docs/modules.rst index 442d461..413f6cf 100644 --- a/docs/modules.rst +++ b/docs/modules.rst @@ -725,6 +725,21 @@ contributed by `joachimmathes `_ - many thanks .. image:: ../screenshots/dunstctl.png +emerge_status +~~~~~~~~~~~~~ + +Display information about the currently running emerge process. + +Requires the following executable: + * emerge + +Parameters: + * emerge_status.format: Format string (defaults to '{current}/{total} {action} {category}/{pkg}') + +This code is based on `emerge_status module from p3status `_ original created by `AnwariasEu `_. + +.. image:: ../screenshots/emerge_status.png + getcrypto ~~~~~~~~~ diff --git a/screenshots/emerge_status.png b/screenshots/emerge_status.png new file mode 100644 index 0000000000000000000000000000000000000000..1e2a93aed29e07ccee8e56e98310c5b6d73b3217 GIT binary patch literal 9403 zcmeHtc{r3^`2UbXB!viNnj~S&n8q-ZeF=qRjcj8U`!-`=ix5J#Bzty3ku^({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