summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2024-02-25 19:22:11 +0000
committerV3n3RiX <venerix@koprulu.sector>2024-02-25 19:22:11 +0000
commit17b776830e4468080c1b0f09685b4aa4f7b9eaf3 (patch)
tree740ba94196aeb4ed8e1eead48b620b96d384d825 /src/backend
parente3fa4634750ccceb23998fadefc249b35f86ca5b (diff)
bugfix : https://bugs.redcorelinux.org/show_bug.cgi?id=143
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/install.py94
-rw-r--r--src/backend/upgrade.py94
2 files changed, 180 insertions, 8 deletions
diff --git a/src/backend/install.py b/src/backend/install.py
index 8dab0ef..6a95bee 100644
--- a/src/backend/install.py
+++ b/src/backend/install.py
@@ -1,9 +1,11 @@
#!/usr/bin/python3
import atexit
+import fcntl
import io
import os
import pickle
+import selectors
import signal
import subprocess
import sys
@@ -18,6 +20,26 @@ import sisyphus.syncdb
import sisyphus.update
+def set_nonblocking(fd):
+ flags = fcntl.fcntl(fd, fcntl.F_GETFL)
+ fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
+
+
+def spinner_animation():
+ spinner = ['-', '\\', '|', '/']
+ sel = selectors.DefaultSelector()
+ sel.register(sys.stdin, selectors.EVENT_READ)
+
+ for _ in range(10):
+ for char in spinner:
+ sys.stdout.write('\b' + char)
+ sys.stdout.flush()
+ events = sel.select(timeout=0.1)
+ if events:
+ return
+ sys.stdout.write('\b')
+
+
def sigint_handler(signal, frame):
sys.exit(0)
@@ -106,7 +128,21 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False):
p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--with-bdeps=y', '--misspell-suggestion=n',
'--fuzzy-search=n'] + (['--oneshot'] if oneshot else []) + list(pkgname))
try:
- p_exe.wait()
+ set_nonblocking(sys.stdout.fileno())
+ spinner_animation()
+
+ sel = selectors.DefaultSelector()
+ sel.register(sys.stdin, selectors.EVENT_READ)
+
+ while True:
+ events = sel.select(timeout=0.1)
+ for key, mask in events:
+ if key.fileobj == sys.stdin:
+ line = sys.stdin.readline().strip()
+ if line.lower() == 'q':
+ sys.exit()
+ if p_exe.poll() is not None:
+ break
except KeyboardInterrupt:
p_exe.terminate()
try:
@@ -114,6 +150,8 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False):
except subprocess.TimeoutExpired:
p_exe.kill()
sys.exit()
+ finally:
+ p_exe.wait()
sisyphus.syncdb.lcl_tbl()
break
elif user_input.lower() in ['no', 'n']:
@@ -145,7 +183,21 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False):
p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--usepkg', '--rebuilt-binaries', '--with-bdeps=y',
'--misspell-suggestion=n', '--fuzzy-search=n'] + (['--oneshot'] if oneshot else []) + list(pkgname))
try:
- p_exe.wait()
+ set_nonblocking(sys.stdout.fileno())
+ spinner_animation()
+
+ sel = selectors.DefaultSelector()
+ sel.register(sys.stdin, selectors.EVENT_READ)
+
+ while True:
+ events = sel.select(timeout=0.1)
+ for key, mask in events:
+ if key.fileobj == sys.stdin:
+ line = sys.stdin.readline().strip()
+ if line.lower() == 'q':
+ sys.exit()
+ if p_exe.poll() is not None:
+ break
except KeyboardInterrupt:
p_exe.terminate()
try:
@@ -153,6 +205,8 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False):
except subprocess.TimeoutExpired:
p_exe.kill()
sys.exit()
+ finally:
+ p_exe.wait()
sisyphus.syncdb.lcl_tbl()
break
elif user_input.lower() in ['no', 'n']:
@@ -177,7 +231,21 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False):
p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--usepkg', '--usepkgonly', '--rebuilt-binaries',
'--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + (['--oneshot'] if oneshot else []) + list(pkgname))
try:
- p_exe.wait()
+ set_nonblocking(sys.stdout.fileno())
+ spinner_animation()
+
+ sel = selectors.DefaultSelector()
+ sel.register(sys.stdin, selectors.EVENT_READ)
+
+ while True:
+ events = sel.select(timeout=0.1)
+ for key, mask in events:
+ if key.fileobj == sys.stdin:
+ line = sys.stdin.readline().strip()
+ if line.lower() == 'q':
+ sys.exit()
+ if p_exe.poll() is not None:
+ break
except KeyboardInterrupt:
p_exe.terminate()
try:
@@ -185,6 +253,8 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False):
except subprocess.TimeoutExpired:
p_exe.kill()
sys.exit()
+ finally:
+ p_exe.wait()
sisyphus.syncdb.lcl_tbl()
break
elif user_input.lower() in ['no', 'n']:
@@ -263,7 +333,21 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False):
p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--usepkg', '--usepkgonly', '--rebuilt-binaries',
'--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + (['--oneshot'] if oneshot else []) + list(pkgname))
try:
- p_exe.wait()
+ set_nonblocking(sys.stdout.fileno())
+ spinner_animation()
+
+ sel = selectors.DefaultSelector()
+ sel.register(sys.stdin, selectors.EVENT_READ)
+
+ while True:
+ events = sel.select(timeout=0.1)
+ for key, mask in events:
+ if key.fileobj == sys.stdin:
+ line = sys.stdin.readline().strip()
+ if line.lower() == 'q':
+ sys.exit()
+ if p_exe.poll() is not None:
+ break
except KeyboardInterrupt:
p_exe.terminate()
try:
@@ -271,6 +355,8 @@ def start(pkgname, ebuild=False, gfx_ui=False, oneshot=False):
except subprocess.TimeoutExpired:
p_exe.kill()
sys.exit()
+ finally:
+ p_exe.wait()
sisyphus.syncdb.lcl_tbl()
break
elif user_input.lower() in ['no', 'n']:
diff --git a/src/backend/upgrade.py b/src/backend/upgrade.py
index 61e40ed..31e3463 100644
--- a/src/backend/upgrade.py
+++ b/src/backend/upgrade.py
@@ -1,9 +1,11 @@
#!/usr/bin/python3
import atexit
+import fcntl
import io
import os
import pickle
+import selectors
import signal
import subprocess
import sys
@@ -18,6 +20,26 @@ import sisyphus.syncdb
import sisyphus.update
+def set_nonblocking(fd):
+ flags = fcntl.fcntl(fd, fcntl.F_GETFL)
+ fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
+
+
+def spinner_animation():
+ spinner = ['-', '\\', '|', '/']
+ sel = selectors.DefaultSelector()
+ sel.register(sys.stdin, selectors.EVENT_READ)
+
+ for _ in range(10):
+ for char in spinner:
+ sys.stdout.write('\b' + char)
+ sys.stdout.flush()
+ events = sel.select(timeout=0.1)
+ if events:
+ return
+ sys.stdout.write('\b')
+
+
def sigint_handler(signal, frame):
sys.exit(0)
@@ -92,7 +114,21 @@ def start(ebuild=False, gfx_ui=False):
p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--update', '--deep', '--newuse',
'--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'])
try:
- p_exe.wait()
+ set_nonblocking(sys.stdout.fileno())
+ spinner_animation()
+
+ sel = selectors.DefaultSelector()
+ sel.register(sys.stdin, selectors.EVENT_READ)
+
+ while True:
+ events = sel.select(timeout=0.1)
+ for key, mask in events:
+ if key.fileobj == sys.stdin:
+ line = sys.stdin.readline().strip()
+ if line.lower() == 'q':
+ sys.exit()
+ if p_exe.poll() is not None:
+ break
except KeyboardInterrupt:
p_exe.terminate()
try:
@@ -100,6 +136,8 @@ def start(ebuild=False, gfx_ui=False):
except subprocess.TimeoutExpired:
p_exe.kill()
sys.exit()
+ finally:
+ p_exe.wait()
sisyphus.syncdb.lcl_tbl()
break
elif user_input.lower() in ['no', 'n']:
@@ -131,7 +169,21 @@ def start(ebuild=False, gfx_ui=False):
p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--update', '--deep', '--newuse', '--usepkg',
'--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'])
try:
- p_exe.wait()
+ set_nonblocking(sys.stdout.fileno())
+ spinner_animation()
+
+ sel = selectors.DefaultSelector()
+ sel.register(sys.stdin, selectors.EVENT_READ)
+
+ while True:
+ events = sel.select(timeout=0.1)
+ for key, mask in events:
+ if key.fileobj == sys.stdin:
+ line = sys.stdin.readline().strip()
+ if line.lower() == 'q':
+ sys.exit()
+ if p_exe.poll() is not None:
+ break
except KeyboardInterrupt:
p_exe.terminate()
try:
@@ -139,6 +191,8 @@ def start(ebuild=False, gfx_ui=False):
except subprocess.TimeoutExpired:
p_exe.kill()
sys.exit()
+ finally:
+ p_exe.wait()
sisyphus.syncdb.lcl_tbl()
break
elif user_input.lower() in ['no', 'n']:
@@ -163,7 +217,21 @@ def start(ebuild=False, gfx_ui=False):
p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--update', '--deep', '--newuse', '--usepkg', '--usepkgonly',
'--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'])
try:
- p_exe.wait()
+ set_nonblocking(sys.stdout.fileno())
+ spinner_animation()
+
+ sel = selectors.DefaultSelector()
+ sel.register(sys.stdin, selectors.EVENT_READ)
+
+ while True:
+ events = sel.select(timeout=0.1)
+ for key, mask in events:
+ if key.fileobj == sys.stdin:
+ line = sys.stdin.readline().strip()
+ if line.lower() == 'q':
+ sys.exit()
+ if p_exe.poll() is not None:
+ break
except KeyboardInterrupt:
p_exe.terminate()
try:
@@ -171,6 +239,8 @@ def start(ebuild=False, gfx_ui=False):
except subprocess.TimeoutExpired:
p_exe.kill()
sys.exit()
+ finally:
+ p_exe.wait()
sisyphus.syncdb.lcl_tbl()
break
elif user_input.lower() in ['no', 'n']:
@@ -249,7 +319,21 @@ def start(ebuild=False, gfx_ui=False):
p_exe = subprocess.Popen(['emerge', '--quiet', '--verbose', '--update', '--deep', '--newuse', '--usepkg', '--usepkgonly',
'--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'])
try:
- p_exe.wait()
+ set_nonblocking(sys.stdout.fileno())
+ spinner_animation()
+
+ sel = selectors.DefaultSelector()
+ sel.register(sys.stdin, selectors.EVENT_READ)
+
+ while True:
+ events = sel.select(timeout=0.1)
+ for key, mask in events:
+ if key.fileobj == sys.stdin:
+ line = sys.stdin.readline().strip()
+ if line.lower() == 'q':
+ sys.exit()
+ if p_exe.poll() is not None:
+ break
except KeyboardInterrupt:
p_exe.terminate()
try:
@@ -257,6 +341,8 @@ def start(ebuild=False, gfx_ui=False):
except subprocess.TimeoutExpired:
p_exe.kill()
sys.exit()
+ finally:
+ p_exe.wait()
sisyphus.syncdb.lcl_tbl()
break
elif user_input.lower() in ['no', 'n']: