Added Update
indicator module with pacman
and cower
backends.
This commit is contained in:
parent
0891a0ef87
commit
a42d78c5c5
62
i3pystatus/updates/__init__.py
Normal file
62
i3pystatus/updates/__init__.py
Normal 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
|
19
i3pystatus/updates/cower.py
Normal file
19
i3pystatus/updates/cower.py
Normal 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
|
20
i3pystatus/updates/pacman.py
Normal file
20
i3pystatus/updates/pacman.py
Normal 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
|
Loading…
Reference in New Issue
Block a user