Added Update indicator module with pacman and cower backends.

This commit is contained in:
Lukáš Mandák 2015-06-01 12:55:47 +02:00
parent 0891a0ef87
commit a42d78c5c5
4 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,62 @@
from i3pystatus import SettingsBase, IntervalModule, formatp
class Backend(SettingsBase):
"""
TODO: doc
"""
updates = 0
class Updates(IntervalModule):
"""
Generic update checker
TODO: doc
"""
interval = 60 * 5 # 5 minutes
settings = (
("backends", "List of backends used to check for updates."),
("format", ""),
("format_no_updates", ""),
("color", ""),
("color_no_updates", ""),
)
required = ("backends",)
backends = None
format = "U {count}"
format_no_updates = None
color = "#00DD00"
color_no_updates = "#FFFFFF"
on_leftclick = "run"
def init(self):
if not isinstance(self.backends, list):
self.backends = [self.backends]
return
def run(self):
updates_count = 0
for backend in self.backends:
updates_count += backend.updates
if updates_count == 0:
self.output = {} if not self.format_no_updates else {
"full_text": self.format_no_updates,
"color": self.color_no_updates,
}
return
fdict = {
"count": updates_count,
}
self.output = {
"full_text": formatp(self.format, **fdict).strip(),
"color": self.color,
}
return

View File

@ -0,0 +1,19 @@
from i3pystatus.core.command import run_through_shell
from i3pystatus.updates import Backend
class Cower(Backend):
"""
Checks for updates in Arch User Repositories using the `cower` AUR helper.
"""
@property
def updates(self):
command = ["cower", "-u"]
cower = run_through_shell(command)
out = cower.out.strip()
return len(out.split("\n")) if len(out) > 0 else 0
Backend = Cower

View File

@ -0,0 +1,20 @@
from i3pystatus.core.command import run_through_shell
from i3pystatus.updates import Backend
class Pacman(Backend):
"""
Checks for updates in Arch Linux pacman repositories using the
`checkupdates` script.
"""
@property
def updates(self):
command = ["checkupdates"]
checkupdates = run_through_shell(command)
out = checkupdates.out.strip()
return len(out.split("\n")) if len(out) > 0 else 0
Backend = Pacman

View File

@ -20,6 +20,7 @@ setup(name="i3pystatus",
"i3pystatus.core",
"i3pystatus.mail",
"i3pystatus.pulseaudio",
"i3pystatus.updates",
],
entry_points={
"console_scripts": [