Merge pull request #50 from yashar-sb-sb/master
Fix issue number #49 and other improvements.
This commit is contained in:
commit
8767bcf4ec
3 changed files with 43 additions and 30 deletions
|
@ -8,57 +8,63 @@ Requires the following executables:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import threading
|
||||||
|
|
||||||
import bumblebee.input
|
import bumblebee.input
|
||||||
import bumblebee.output
|
import bumblebee.output
|
||||||
import bumblebee.engine
|
import bumblebee.engine
|
||||||
|
|
||||||
|
#list of repositories.
|
||||||
|
#the last one sould always be other
|
||||||
|
repos = ["core", "extra", "community", "multilib", "testing", "other"]
|
||||||
|
|
||||||
|
def get_pacman_info(widget, path):
|
||||||
|
try:
|
||||||
|
result = bumblebee.util.execute("{}/../../bin/pacman-updates".format(path))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
count = len(repos)*[0]
|
||||||
|
|
||||||
|
for line in result.splitlines():
|
||||||
|
if line.startswith(("http", "rsync")):
|
||||||
|
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):
|
class Module(bumblebee.engine.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
super(Module, self).__init__(engine, config,
|
super(Module, self).__init__(engine, config,
|
||||||
bumblebee.output.Widget(full_text=self.updates)
|
bumblebee.output.Widget(full_text=self.updates)
|
||||||
)
|
)
|
||||||
self._count = 0
|
self._count = 0
|
||||||
self._out = ""
|
|
||||||
|
|
||||||
def updates(self, widget):
|
def updates(self, widget):
|
||||||
return self._out
|
return '/'.join(map(lambda x: str(widget.get(x,0)), repos))
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self, widgets):
|
||||||
path = os.path.dirname(os.path.abspath(__file__))
|
path = os.path.dirname(os.path.abspath(__file__))
|
||||||
if self._count == 0:
|
if self._count == 0:
|
||||||
self._out = "?/?/?/?"
|
thread = threading.Thread(target=get_pacman_info, args=(widgets[0],path))
|
||||||
try:
|
thread.start()
|
||||||
result = bumblebee.util.execute("{}/../../bin/pacman-updates".format(path))
|
|
||||||
self._community = 0
|
|
||||||
self._core = 0
|
|
||||||
self._extra = 0
|
|
||||||
self._other = 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 = "?/?/?/?"
|
|
||||||
|
|
||||||
# TODO: improve this waiting mechanism a bit
|
# TODO: improve this waiting mechanism a bit
|
||||||
self._count += 1
|
self._count += 1
|
||||||
self._count = 0 if self._count > 300 else self._count
|
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):
|
def state(self, widget):
|
||||||
if self.sumUpdates() > 0:
|
weightedCount = sum(map(lambda x: (len(repos)-x[0]) * widget.get(x[1],0), enumerate(repos)))
|
||||||
return "critical"
|
|
||||||
|
if weightedCount < 10:
|
||||||
|
return "good"
|
||||||
|
|
||||||
|
return self.threshold_state(weightedCount, 100, 150)
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"cpu": { "prefix": "" },
|
"cpu": { "prefix": "" },
|
||||||
"disk": { "prefix": "" },
|
"disk": { "prefix": "" },
|
||||||
"dnf": { "prefix": "" },
|
"dnf": { "prefix": "" },
|
||||||
|
"pacman": { "prefix": "" },
|
||||||
"brightness": { "prefix": "" },
|
"brightness": { "prefix": "" },
|
||||||
"load": { "prefix": "" },
|
"load": { "prefix": "" },
|
||||||
"layout": { "prefix": "" },
|
"layout": { "prefix": "" },
|
||||||
|
|
|
@ -21,6 +21,12 @@
|
||||||
"bg": "#859900"
|
"bg": "#859900"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"pacman": {
|
||||||
|
"good": {
|
||||||
|
"fg": "#002b36",
|
||||||
|
"bg": "#859900"
|
||||||
|
}
|
||||||
|
},
|
||||||
"battery": {
|
"battery": {
|
||||||
"charged": {
|
"charged": {
|
||||||
"fg": "#002b36",
|
"fg": "#002b36",
|
||||||
|
|
Loading…
Reference in a new issue