Skip to content

Commit

Permalink
Added SIGINT handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
RoliSoft committed Nov 2, 2016
1 parent e8f9c63 commit 0e10293
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
4 changes: 3 additions & 1 deletion get-prebuilt.py
Expand Up @@ -4,10 +4,12 @@
import sys
import json
import urllib.request
from utils import Fore, parse_image_arg, chunked_copy, clear_progress
from utils import Fore, parse_image_arg, chunked_copy, clear_progress, handle_sigint

# handle arguments

handle_sigint()

if len(sys.argv) < 2:
print('usage: ./get-prebuilt.py image[:tag]')
sys.exit(-1)
Expand Down
4 changes: 3 additions & 1 deletion get-source.py
Expand Up @@ -2,10 +2,12 @@
# coding=utf-8
import sys
import urllib.request
from utils import Fore, parse_image_arg, chunked_copy, clear_progress
from utils import Fore, parse_image_arg, chunked_copy, clear_progress, handle_sigint

# handle arguments

handle_sigint()

if len(sys.argv) < 2:
print('usage: ./get-source.py image[:tag]')
sys.exit(-1)
Expand Down
2 changes: 2 additions & 0 deletions install.py
Expand Up @@ -22,6 +22,8 @@

# handle arguments

handle_sigint()

imgarg = ''
runhooks = True

Expand Down
4 changes: 3 additions & 1 deletion switch.py
Expand Up @@ -4,10 +4,12 @@
import sys
import os.path
import subprocess
from utils import Fore, parse_image_arg, probe_wsl, get_label, path_trans
from utils import Fore, parse_image_arg, probe_wsl, get_label, path_trans, handle_sigint

# handle arguments

handle_sigint()

if len(sys.argv) < 2:

# print usage information
Expand Down
13 changes: 13 additions & 0 deletions utils.py
Expand Up @@ -7,6 +7,7 @@
import glob
import time
import shlex
import signal
import subprocess


Expand Down Expand Up @@ -55,6 +56,18 @@ class Fore:
RESET = ''


# registers for the interrupt signal in order to gracefully exit when Ctrl-C is hit

def handle_sigint():
def signal_handler(signal, frame):
clear_progress()
show_cursor()
print('%s[!]%s Terminating early due to interruption.' % (Fore.RED, Fore.RESET))
sys.exit(-1)

signal.signal(signal.SIGINT, signal_handler)


# parse image[:tag] | archive argument

def parse_image_arg(argv, can_be_file = False):
Expand Down

0 comments on commit 0e10293

Please sign in to comment.