summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2023-04-08 14:20:06 +0100
committerV3n3RiX <venerix@koprulu.sector>2023-04-08 14:20:06 +0100
commit9433b5e797848546351ae3dc7602813191e01bf6 (patch)
tree273b8dce53cdd4e0fdcf1bd25799683e4473e333 /src/backend
parentaab2a6ca78f41a41673d03d22da2c562ee90901b (diff)
update : handle KeyboardInterrupt gracefully
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/syncenv.py108
-rw-r--r--src/backend/update.py8
2 files changed, 106 insertions, 10 deletions
diff --git a/src/backend/syncenv.py b/src/backend/syncenv.py
index 25b418e..9e41b78 100644
--- a/src/backend/syncenv.py
+++ b/src/backend/syncenv.py
@@ -1,10 +1,18 @@
#!/usr/bin/python3
import os
+import signal
import subprocess
import sisyphus.getfs
+def sigint_handler(signal, frame):
+ sys.exit(0)
+
+
+signal.signal(signal.SIGINT, sigint_handler)
+
+
def g_repo():
os.chdir(sisyphus.getfs.g_src_dir)
lcl_brch = subprocess.check_output(
@@ -14,11 +22,27 @@ def g_repo():
g_exe1 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] +
lcl_brch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE)
- g_exe1.wait()
+ try:
+ g_exe1.wait()
+ except KeyboardInterrupt:
+ g_exe1.terminate()
+ try:
+ g_exe1.wait(1)
+ except subprocess.TimeoutExpired:
+ g_exe1.kill()
+ sys.exit()
g_exe2 = subprocess.Popen(['git', 'reset', '--hard'] + rmt_brch.decode().strip(
).replace('refs/remotes/', '').split() + ['--quiet'], stdout=subprocess.PIPE)
- g_exe2.wait()
+ try:
+ g_exe2.wait()
+ except KeyboardInterrupt:
+ g_exe2.terminate()
+ try:
+ g_exe2.wait()
+ except subprocess.TimeoutExpired:
+ g_exe2.kill()
+ sys.exit()
def r_repo():
@@ -30,11 +54,27 @@ def r_repo():
g_exe1 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] +
lcl_brch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE)
- g_exe1.wait()
+ try:
+ g_exe1.wait()
+ except KeyboardInterrupt:
+ g_exe1.terminate()
+ try:
+ g_exe1.wait(1)
+ except subprocess.TimeoutExpired:
+ g_exe1.kill()
+ sys.exit()
g_exe2 = subprocess.Popen(['git', 'reset', '--hard'] + rmt_brch.decode().strip(
).replace('refs/remotes/', '').split() + ['--quiet'], stdout=subprocess.PIPE)
- g_exe2.wait()
+ try:
+ g_exe2.wait()
+ except KeyboardInterrupt:
+ g_exe2.terminate()
+ try:
+ g_exe2.wait(1)
+ except subprocess.TimeoutExpired:
+ g_exe2.kill()
+ sys.exit()
def p_cfg_repo():
@@ -45,19 +85,67 @@ def p_cfg_repo():
['git', 'rev-parse', '--symbolic-full-name', '@{u}'])
g_exe1 = subprocess.Popen(['git', 'stash'], stdout=subprocess.PIPE)
- g_exe1.wait()
+ try:
+ g_exe1.wait()
+ except KeyboardInterrupt:
+ g_exe1.terminate()
+ try:
+ g_exe1.wait(1)
+ except subprocess.TimeoutExpired:
+ g_exe1.kill()
+ sys.exit()
g_exe2 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] +
lcl_brch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE)
- g_exe2.wait()
+ try:
+ g_exe2.wait()
+ except KeyboardInterrupt:
+ g_exe2.terminate()
+ try:
+ g_exe2.wait(1)
+ except subprocess.TimeoutExpired:
+ g_exe2.kill()
+ sys.exit()
g_exe3 = subprocess.Popen(['git', 'reset', '--hard'] + rmt_brch.decode().strip(
).replace('refs/remotes/', '').split() + ['--quiet'], stdout=subprocess.PIPE)
- g_exe3.wait()
+ try:
+ g_exe3.wait()
+ except KeyboardInterrupt:
+ g_exe3.terminate()
+ try:
+ g_exe3.wait(1)
+ except subprocess.TimeoutExpired:
+ g_exe3.kill()
+ sys.exit()
g_exe4 = subprocess.Popen(
['git', 'stash', 'apply'], stdout=subprocess.PIPE)
- g_exe4.wait()
+ try:
+ g_exe4.wait()
+ except KeyboardInterrupt:
+ g_exe4.terminate()
+ try:
+ g_exe4.wait(1)
+ except subprocess.TimeoutExpired:
+ g_exe4.kill()
+ sys.exit()
g_exe5 = subprocess.Popen(
['git', 'stash', 'clear'], stdout=subprocess.PIPE)
- g_exe5.wait()
+ try:
+ g_exe5.wait()
+ except KeyboardInterrupt:
+ g_exe5.terminate()
+ try:
+ g_exe5.wait(1)
+ except subprocess.TimeoutExpired:
+ g_exe5.kill()
+ sys.exit()
g_exe6 = subprocess.Popen(
['git', 'gc', '--prune=now', '--quiet'], stdout=subprocess.PIPE)
- g_exe6.wait()
+ try:
+ g_exe6.wait()
+ except KeyboardInterrupt:
+ g_exe6.terminate()
+ try:
+ g_exe6.wait(1)
+ except subprocess.TimeoutExpired:
+ g_exe6.kill()
+ sys.exit()
diff --git a/src/backend/update.py b/src/backend/update.py
index 54e07e3..0c25068 100644
--- a/src/backend/update.py
+++ b/src/backend/update.py
@@ -1,6 +1,7 @@
#!/usr/bin/python3
import animation
+import signal
import sys
import time
import sisyphus.checkenv
@@ -11,6 +12,13 @@ import sisyphus.syncdb
import sisyphus.syncenv
+def sigint_handler(signal, frame):
+ sys.exit(0)
+
+
+signal.signal(signal.SIGINT, sigint_handler)
+
+
def sync_evrth():
sisyphus.syncenv.g_repo()
sisyphus.syncenv.r_repo()