[dnf] simplify threading
use framework threading to simplify the dnf module see #692
This commit is contained in:
parent
38e54a7c81
commit
db41792afb
1 changed files with 33 additions and 42 deletions
|
@ -5,13 +5,8 @@
|
||||||
Requires the following executable:
|
Requires the following executable:
|
||||||
* dnf
|
* dnf
|
||||||
|
|
||||||
Parameters:
|
|
||||||
* dnf.interval: Time in minutes between two consecutive update checks (defaults to 30 minutes)
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import threading
|
|
||||||
|
|
||||||
import core.event
|
import core.event
|
||||||
import core.module
|
import core.module
|
||||||
import core.widget
|
import core.widget
|
||||||
|
@ -20,7 +15,20 @@ import core.decorators
|
||||||
import util.cli
|
import util.cli
|
||||||
|
|
||||||
|
|
||||||
def get_dnf_info(widget):
|
class Module(core.module.Module):
|
||||||
|
@core.decorators.every(minutes=30)
|
||||||
|
def __init__(self, config, theme):
|
||||||
|
super().__init__(config, theme, core.widget.Widget(self.updates))
|
||||||
|
|
||||||
|
self.background = True
|
||||||
|
|
||||||
|
def updates(self, widget):
|
||||||
|
result = []
|
||||||
|
for t in ["security", "bugfixes", "enhancements", "other"]:
|
||||||
|
result.append(str(widget.get(t, 0)))
|
||||||
|
return "/".join(result)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
res = util.cli.execute("dnf updateinfo", ignore_errors=True)
|
res = util.cli.execute("dnf updateinfo", ignore_errors=True)
|
||||||
|
|
||||||
security = 0
|
security = 0
|
||||||
|
@ -52,23 +60,6 @@ def get_dnf_info(widget):
|
||||||
widget.set("enhancements", enhancements)
|
widget.set("enhancements", enhancements)
|
||||||
widget.set("other", other)
|
widget.set("other", other)
|
||||||
|
|
||||||
core.event.trigger("update", [widget.module.id], redraw_only=True)
|
|
||||||
|
|
||||||
|
|
||||||
class Module(core.module.Module):
|
|
||||||
@core.decorators.every(minutes=30)
|
|
||||||
def __init__(self, config, theme):
|
|
||||||
super().__init__(config, theme, core.widget.Widget(self.updates))
|
|
||||||
|
|
||||||
def updates(self, widget):
|
|
||||||
result = []
|
|
||||||
for t in ["security", "bugfixes", "enhancements", "other"]:
|
|
||||||
result.append(str(widget.get(t, 0)))
|
|
||||||
return "/".join(result)
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
thread = threading.Thread(target=get_dnf_info, args=(self.widget(),))
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
cnt = 0
|
cnt = 0
|
||||||
|
|
Loading…
Reference in a new issue