[mirrorbrain-commits] r7798 - /trunk/tools/metalink-hasher.py

From: <poeml_at_mirrorbrain.org>
Date: Wed, 09 Sep 2009 02:26:18 -0000
Author: poeml
Date: Wed Sep  9 04:26:17 2009
New Revision: 7798

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=7798&view=rev
Log:
metalink-hasher:
- catch keyboard Ctrl-C and common interrupting signals

Modified:
    trunk/tools/metalink-hasher.py

Modified: trunk/tools/metalink-hasher.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/tools/metalink-hasher.py?rev=7798&r1=7797&r2=7798&view=diff
==============================================================================
--- trunk/tools/metalink-hasher.py (original)
+++ trunk/tools/metalink-hasher.py Wed Sep  9 04:26:17 2009
_at_@ -40,8 +40,20 @@
 import subprocess
 import errno
 import fcntl
+import signal
 
 line_mask = re.compile('.*</*(verification|hash|pieces).*>.*')
+
+class SignalInterrupt(Exception):
+    """Exception raised on SIGTERM and SIGHUP."""
+
+def catchterm(*args):
+    raise SignalInterrupt
+
+for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
+    num = getattr(signal, name, None)
+    if num: signal.signal(num, catchterm)
+
 
 class Hasheable:
     """represent a file and its metadata"""
_at_@ -372,5 +384,14 @@
 
 if __name__ == '__main__':
     import sys
-    metalinks = Metalinks()
-    sys.exit( metalinks.main() )
+
+    try:
+        metalinks = Metalinks()
+        sys.exit( metalinks.main() )
+
+    except SignalInterrupt:
+        print >>sys.stderr, 'killed!'
+
+    except KeyboardInterrupt:
+        print >>sys.stderr, 'interrupted!'
+




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Wed Sep 09 2009 - 02:26:19 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT