From 88e3b8c1460966cbbe78b6f5d9b08376550555ff Mon Sep 17 00:00:00 2001 From: yashar-sb-sb Date: Fri, 10 Mar 2017 16:11:59 +0330 Subject: [PATCH 1/8] Update `pacman.py` Use widget to store parameters instead of using private variables. --- bumblebee/modules/pacman.py | 44 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/bumblebee/modules/pacman.py b/bumblebee/modules/pacman.py index 4fd0cd8..43ff18b 100644 --- a/bumblebee/modules/pacman.py +++ b/bumblebee/modules/pacman.py @@ -12,53 +12,49 @@ import bumblebee.input import bumblebee.output import bumblebee.engine +#list of repositories the last one sould always be other +repos = ["community", "core", "extra", "other"] + class Module(bumblebee.engine.Module): def __init__(self, engine, config): super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.updates) ) self._count = 0 - self._out = "" def updates(self, widget): - return self._out + return '/'.join(map(lambda x: str(widget.get(x,0)), repos)) def update(self, widgets): path = os.path.dirname(os.path.abspath(__file__)) if self._count == 0: - self._out = "?/?/?/?" try: result = bumblebee.util.execute("{}/../../bin/pacman-updates".format(path)) - self._community = 0 - self._core = 0 - self._extra = 0 - self._other = 0 + + count = len(repos)*[0] for line in result.splitlines(): if line.startswith("http"): - if "community" in line: - self._community += 1 - continue - if "core" in line: - self._core += 1; - continue - if "extra" in line: - self._extra += 1 - continue - self._other += 1 - self._out = str(self._core)+"/"+str(self._extra)+"/"+str(self._community)+"/"+str(self._other) - except RuntimeError: - self._out = "?/?/?/?" + for i in range(len(repos)-1): + if "/" + repos[i] + "/" in line: + count[i] += 1 + break + else: + result[-1] += 1 + + for i in range(len(repos)): + widgets[0].set(repos[i], count[i]) + + except BaseException as a: + raise a # TODO: improve this waiting mechanism a bit self._count += 1 self._count = 0 if self._count > 300 else self._count - def sumUpdates(self): - return self._core + self._community + self._extra + self._other - def state(self, widget): - if self.sumUpdates() > 0: + sumUpdates = sum(map(lambda x: widget.get(x,0), repos)) + if sumUpdates > 0: return "critical" # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 50d7a2748758d5cf8c121da857a9445c41693cbe Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Fri, 10 Mar 2017 18:51:30 +0330 Subject: [PATCH 2/8] Bug fix: pacman.py freezes the bar Move update in a seperate thread. --- bumblebee/modules/pacman.py | 46 ++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/bumblebee/modules/pacman.py b/bumblebee/modules/pacman.py index 43ff18b..2e1f8c7 100644 --- a/bumblebee/modules/pacman.py +++ b/bumblebee/modules/pacman.py @@ -8,6 +8,8 @@ Requires the following executables: """ import os +import threading + import bumblebee.input import bumblebee.output import bumblebee.engine @@ -15,6 +17,29 @@ import bumblebee.engine #list of repositories the last one sould always be other repos = ["community", "core", "extra", "other"] +def get_pacman_info(widget, path): + try: + result = bumblebee.util.execute("{}/../../bin/pacman-updates".format(path)) + except BaseException as a: + raise a + except: + pass + + count = len(repos)*[0] + + for line in result.splitlines(): + if line.startswith("http"): + for i in range(len(repos)-1): + if "/" + repos[i] + "/" in line: + count[i] += 1 + break + else: + result[-1] += 1 + + for i in range(len(repos)): + widget.set(repos[i], count[i]) + + class Module(bumblebee.engine.Module): def __init__(self, engine, config): super(Module, self).__init__(engine, config, @@ -28,25 +53,8 @@ class Module(bumblebee.engine.Module): def update(self, widgets): path = os.path.dirname(os.path.abspath(__file__)) if self._count == 0: - try: - result = bumblebee.util.execute("{}/../../bin/pacman-updates".format(path)) - - count = len(repos)*[0] - - for line in result.splitlines(): - if line.startswith("http"): - for i in range(len(repos)-1): - if "/" + repos[i] + "/" in line: - count[i] += 1 - break - else: - result[-1] += 1 - - for i in range(len(repos)): - widgets[0].set(repos[i], count[i]) - - except BaseException as a: - raise a + thread = threading.Thread(target=get_pacman_info, args=(widgets[0],path)) + thread.start() # TODO: improve this waiting mechanism a bit self._count += 1 From b9a4b590a47465a9a37505c457ab701b15360a8f Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Fri, 10 Mar 2017 19:09:31 +0330 Subject: [PATCH 3/8] [modules/pacman] Update list of repositories --- bumblebee/modules/pacman.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bumblebee/modules/pacman.py b/bumblebee/modules/pacman.py index 2e1f8c7..ffb1fbd 100644 --- a/bumblebee/modules/pacman.py +++ b/bumblebee/modules/pacman.py @@ -14,8 +14,9 @@ import bumblebee.input import bumblebee.output import bumblebee.engine -#list of repositories the last one sould always be other -repos = ["community", "core", "extra", "other"] +#list of repositories. +#the last one sould always be other +repos = ["core", "extra", "community", "multilib", "testing", "other"] def get_pacman_info(widget, path): try: From 82ce0ac834c5bd0a4a0726b897b5fbaf05d5f154 Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Fri, 10 Mar 2017 19:53:52 +0330 Subject: [PATCH 4/8] [modules/pacman] Set thresholds Compute weighted sum and set thresholds accordingly --- bumblebee/modules/pacman.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/pacman.py b/bumblebee/modules/pacman.py index ffb1fbd..bbc615a 100644 --- a/bumblebee/modules/pacman.py +++ b/bumblebee/modules/pacman.py @@ -62,8 +62,11 @@ class Module(bumblebee.engine.Module): self._count = 0 if self._count > 300 else self._count def state(self, widget): - sumUpdates = sum(map(lambda x: widget.get(x,0), repos)) - if sumUpdates > 0: - return "critical" + weightedCount = sum(map(lambda x: (len(repos)-x[0]) * widget.get(x[1],0), enumerate(repos))) + + if weightedCount < 10: + return "good" + + return self.threshold_state(weightedCount, 100, 150) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From e2fcbfae4fcd64af9aea405a82e355dcfbfa4925 Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Fri, 10 Mar 2017 20:02:28 +0330 Subject: [PATCH 5/8] [modules/pacman] Remove extra debugging raise --- bumblebee/modules/pacman.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bumblebee/modules/pacman.py b/bumblebee/modules/pacman.py index bbc615a..7b2ebb6 100644 --- a/bumblebee/modules/pacman.py +++ b/bumblebee/modules/pacman.py @@ -21,8 +21,6 @@ repos = ["core", "extra", "community", "multilib", "testing", "other"] def get_pacman_info(widget, path): try: result = bumblebee.util.execute("{}/../../bin/pacman-updates".format(path)) - except BaseException as a: - raise a except: pass From 9b71fc9c9d3469f97a8fec28ed2b6bf1d3ca0327 Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Fri, 10 Mar 2017 20:45:53 +0330 Subject: [PATCH 6/8] [themes/solarized-powerline] Add good for pacman --- themes/solarized-powerline.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/themes/solarized-powerline.json b/themes/solarized-powerline.json index cb9049b..e1fbe1d 100644 --- a/themes/solarized-powerline.json +++ b/themes/solarized-powerline.json @@ -21,6 +21,12 @@ "bg": "#859900" } }, + "pacman": { + "good": { + "fg": "#002b36", + "bg": "#859900" + } + }, "battery": { "charged": { "fg": "#002b36", From 4a5668654f2b75aea77807fa66e84d05de16e3fb Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Fri, 10 Mar 2017 20:53:02 +0330 Subject: [PATCH 7/8] [icons/awesome-fonts] Add prefix icon for pacman --- themes/icons/awesome-fonts.json | 1 + 1 file changed, 1 insertion(+) diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 8d6610c..69dd60f 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -9,6 +9,7 @@ "cpu": { "prefix": "" }, "disk": { "prefix": "" }, "dnf": { "prefix": "" }, + "pacman": { "prefix": "" }, "brightness": { "prefix": "" }, "load": { "prefix": "" }, "layout": { "prefix": "" }, From c203cd61738b4cbcd86d180caed1b9cbb7cce59e Mon Sep 17 00:00:00 2001 From: Yashar Shahi Date: Fri, 10 Mar 2017 21:18:34 +0330 Subject: [PATCH 8/8] [modules/pacman] Update url filtering Arch mirrors can also have rsync protocol --- bumblebee/modules/pacman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumblebee/modules/pacman.py b/bumblebee/modules/pacman.py index 7b2ebb6..a7780a8 100644 --- a/bumblebee/modules/pacman.py +++ b/bumblebee/modules/pacman.py @@ -27,7 +27,7 @@ def get_pacman_info(widget, path): count = len(repos)*[0] for line in result.splitlines(): - if line.startswith("http"): + if line.startswith(("http", "rsync")): for i in range(len(repos)-1): if "/" + repos[i] + "/" in line: count[i] += 1