Bug fix: pacman.py freezes the bar
Move update in a seperate thread.
This commit is contained in:
parent
88e3b8c146
commit
50d7a27487
1 changed files with 27 additions and 19 deletions
|
@ -8,6 +8,8 @@ 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
|
||||||
|
@ -15,6 +17,29 @@ import bumblebee.engine
|
||||||
#list of repositories the last one sould always be other
|
#list of repositories the last one sould always be other
|
||||||
repos = ["community", "core", "extra", "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):
|
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,
|
||||||
|
@ -28,25 +53,8 @@ class Module(bumblebee.engine.Module):
|
||||||
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:
|
||||||
try:
|
thread = threading.Thread(target=get_pacman_info, args=(widgets[0],path))
|
||||||
result = bumblebee.util.execute("{}/../../bin/pacman-updates".format(path))
|
thread.start()
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
# TODO: improve this waiting mechanism a bit
|
# TODO: improve this waiting mechanism a bit
|
||||||
self._count += 1
|
self._count += 1
|
||||||
|
|
Loading…
Reference in a new issue