ensure only one subprocess is running at a time
This commit is contained in:
parent
94ebd86d35
commit
943af1a316
@ -60,9 +60,8 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
self.buffer.set_text("")
|
||||
|
||||
def scroll_to_bottom(self):
|
||||
adj = self.scrolledwindow.get_vadjustment()
|
||||
adj.set_value(adj.get_upper())
|
||||
self.scrolledwindow.set_vadjustment(adj)
|
||||
self.buffer.get_end_iter()
|
||||
self.text_view.scroll_to_mark(self.text_mark_end, 0, False, 0, 0)
|
||||
|
||||
def level_to_color(self, level):
|
||||
if level == "INFO":
|
||||
@ -113,6 +112,25 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
def insert(self, text, iter):
|
||||
self.buffer.insert(iter, text + "\n")
|
||||
|
||||
def run_thread(self, args, env):
|
||||
if self.thread is None:
|
||||
do_run = True
|
||||
elif not self.thread.is_alive():
|
||||
do_run = True
|
||||
else:
|
||||
do_run = False
|
||||
|
||||
if do_run:
|
||||
self.thread = threading.Thread(
|
||||
target=self.run,
|
||||
args=(args, env,))
|
||||
|
||||
self.thread.start()
|
||||
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def execute(
|
||||
self,
|
||||
args,
|
||||
@ -136,11 +154,7 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
"INFO",
|
||||
"Running command \"%s\" ..." % " ".join(args))
|
||||
|
||||
thread = threading.Thread(
|
||||
target=self.run,
|
||||
args=(args, env,))
|
||||
|
||||
thread.start()
|
||||
GLib.timeout_add(250, self.run_thread, args, env)
|
||||
|
||||
def run(self, args, env={}):
|
||||
p = subprocess.Popen(
|
||||
@ -192,16 +206,15 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
env=env,
|
||||
empty_msg="No package upgrades were performed.")
|
||||
|
||||
def on_upgrade(self, *args):
|
||||
self.upgrade()
|
||||
|
||||
def update(self, clear=True):
|
||||
args = ['/usr/bin/apt-get', '-y', 'update']
|
||||
env = {'DEBIAN_FRONTEND': 'noninteractive'}
|
||||
self.execute(args, env=env, clear=clear)
|
||||
|
||||
def on_update(self, *args):
|
||||
self.update()
|
||||
self.execute(
|
||||
args,
|
||||
env=env,
|
||||
clear=clear,
|
||||
output_msg="The package cache was refreshed."
|
||||
)
|
||||
|
||||
def list(self, clear=True):
|
||||
args = ['/usr/bin/apt', '-qq', 'list', '--upgradable']
|
||||
@ -210,7 +223,14 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
ignore_stderr=True,
|
||||
clear=clear,
|
||||
output_msg="Found the following package upgrades:",
|
||||
empty_msg="No package upgrades found.")
|
||||
empty_msg="No package upgrades found."
|
||||
)
|
||||
|
||||
def on_update(self, *args):
|
||||
self.update()
|
||||
|
||||
def on_upgrade(self, *args):
|
||||
self.upgrade()
|
||||
|
||||
def on_list(self, *args):
|
||||
self.list()
|
||||
@ -228,15 +248,17 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
self.append_mesg("STDOUT", text)
|
||||
else:
|
||||
exit_code = int(match.group(1))
|
||||
self.thread.join()
|
||||
|
||||
if exit_code != 0:
|
||||
self.append_mesg(
|
||||
"ERROR",
|
||||
"Command exited with code %d" % exit_code)
|
||||
"Command exited with code %d" % exit_code
|
||||
)
|
||||
elif self.stdout == '' and self.empty_msg is not None:
|
||||
self.append_mesg("INFO", self.empty_msg)
|
||||
elif self.stdout != '' and self.output_msg is not None:
|
||||
self.append_mesg("INFO", self.empty_msg)
|
||||
self.append_mesg("INFO", self.output_msg)
|
||||
|
||||
self.unlock()
|
||||
|
||||
@ -265,6 +287,7 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
)
|
||||
|
||||
self.application = application
|
||||
self.thread = None
|
||||
self.stdout_queue = queue.Queue()
|
||||
self.stderr_queue = queue.Queue()
|
||||
|
||||
@ -327,12 +350,16 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
self.scrolledwindow.set_max_content_height(300)
|
||||
self.buffer = Gtk.TextBuffer()
|
||||
|
||||
text_view = Gtk.TextView(buffer=self.buffer)
|
||||
text_view.set_editable(False)
|
||||
text_view.set_monospace(True)
|
||||
text_view.set_cursor_visible(False)
|
||||
self.text_view = Gtk.TextView(buffer=self.buffer)
|
||||
self.text_view.set_editable(False)
|
||||
self.text_view.set_monospace(True)
|
||||
self.text_view.set_cursor_visible(False)
|
||||
|
||||
self.scrolledwindow.add(text_view)
|
||||
text_buffer = self.text_view.get_buffer()
|
||||
iter = text_buffer.get_end_iter()
|
||||
self.text_mark_end = text_buffer.create_mark("", iter, False)
|
||||
|
||||
self.scrolledwindow.add(self.text_view)
|
||||
hbox.pack_start(self.scrolledwindow, True, True, 0)
|
||||
|
||||
|
||||
@ -350,9 +377,6 @@ class SimpleAptUpdate(Gtk.Application):
|
||||
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
|
||||
def do_command_line(self, cmdline):
|
||||
pass
|
||||
|
||||
def on_activate(self, application):
|
||||
self.window = UpdateWindow(application)
|
||||
|
||||
@ -381,7 +405,6 @@ class SimpleAptUpdate(Gtk.Application):
|
||||
|
||||
self.window.present()
|
||||
self.window.show_all()
|
||||
self.window.update()
|
||||
self.window.list(clear=False)
|
||||
|
||||
|
||||
|
@ -7,19 +7,14 @@
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="31.72216mm"
|
||||
height="36.307823mm"
|
||||
viewBox="0 0 31.72216 36.307823"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="1.0.2 (e86c870879, 2021-01-15)"
|
||||
sodipodi:docname="simple-apt-update.svg">
|
||||
id="svg8">
|
||||
<defs
|
||||
id="defs2">
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient4117">
|
||||
<stop
|
||||
style="stop-color:#000000;stop-opacity:1;"
|
||||
@ -55,7 +50,6 @@
|
||||
id="stop4093" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient1878"
|
||||
osb:paint="gradient">
|
||||
<stop
|
||||
@ -72,24 +66,14 @@
|
||||
id="Arrow2Lend"
|
||||
refX="0"
|
||||
refY="0"
|
||||
orient="auto"
|
||||
inkscape:stockid="Arrow2Lend"
|
||||
inkscape:isstock="true">
|
||||
orient="auto">
|
||||
<path
|
||||
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
|
||||
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
|
||||
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
|
||||
id="path892" />
|
||||
</marker>
|
||||
<inkscape:perspective
|
||||
sodipodi:type="inkscape:persp3d"
|
||||
inkscape:vp_x="177.41502 : 38.534923 : 1"
|
||||
inkscape:vp_y="57.01026 : -606.09557 : 0"
|
||||
inkscape:vp_z="-849.50931 : -58.059119 : 1"
|
||||
inkscape:persp3d-origin="-338.86915 : 20.239614 : 1"
|
||||
id="perspective833" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4095"
|
||||
id="linearGradient4087"
|
||||
x1="41.938935"
|
||||
@ -98,7 +82,6 @@
|
||||
y2="60.562257"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4095"
|
||||
id="linearGradient4089"
|
||||
x1="22.932867"
|
||||
@ -107,7 +90,6 @@
|
||||
y2="48.843493"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4095"
|
||||
id="linearGradient4097"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
@ -116,7 +98,6 @@
|
||||
x2="51.607597"
|
||||
y2="48.390368" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4117"
|
||||
id="linearGradient4121"
|
||||
x1="22.932867"
|
||||
@ -125,7 +106,6 @@
|
||||
y2="48.843493"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4117"
|
||||
id="linearGradient4123"
|
||||
x1="19.885436"
|
||||
@ -134,29 +114,6 @@
|
||||
y2="48.390368"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="3.959798"
|
||||
inkscape:cx="81.30198"
|
||||
inkscape:cy="102.74857"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
inkscape:document-rotation="0"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1885"
|
||||
inkscape:window-height="1236"
|
||||
inkscape:window-x="2101"
|
||||
inkscape:window-y="111"
|
||||
inkscape:window-maximized="0"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
fit-margin-bottom="0" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
@ -170,8 +127,6 @@
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(-19.885436,-34.013894)">
|
||||
<rect
|
||||
@ -181,18 +136,14 @@
|
||||
height="27.752951"
|
||||
x="20.385435"
|
||||
y="34.513893"
|
||||
ry="2.9184699"
|
||||
inkscape:transform-center-x="13.051673"
|
||||
inkscape:transform-center-y="11.996269" />
|
||||
ry="2.9184699" />
|
||||
<path
|
||||
style="fill:url(#linearGradient4121);stroke:url(#linearGradient4089);stroke-width:3.765;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;fill-opacity:1"
|
||||
d="m 24.815338,34.950563 c 0.145105,26.252732 17.704313,25.913942 17.704313,25.913942"
|
||||
id="path1321"
|
||||
sodipodi:nodetypes="cc" />
|
||||
id="path1321" />
|
||||
<path
|
||||
style="fill:#bebebe;fill-opacity:1;stroke:url(#linearGradient4087);stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 42.10017,59.891406 -0.02493,-8.714785 8.491092,10.446869 -8.494225,8.380984 z"
|
||||
id="path1869"
|
||||
sodipodi:nodetypes="ccccc" />
|
||||
id="path1869" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 4.6 KiB |
Loading…
Reference in New Issue
Block a user