]> arthur.barton.de Git - bup.git/blobdiff - main.py
Bloom filter & server index: Hide some progress messages
[bup.git] / main.py
diff --git a/main.py b/main.py
index 3554179d4c5a5272b2c6ec2960443fc528a30ab5..d7dc1eba5dabfd522727a7ae42a50f9cb339da4a 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -31,7 +31,8 @@ os.environ['WIDTH'] = str(tty_width())
 
 def usage(msg=""):
     log('Usage: bup [-?|--help] [-d BUP_DIR] [--debug] [--profile] '
-        '<command> [options...]\n\n')
+        '<command> [options...]')
+    log('')
     common = dict(
         ftp = 'Browse backup sets using an ftp-like client',
         fsck = 'Check backup sets for damage and add redundancy information',
@@ -45,12 +46,12 @@ def usage(msg=""):
         web = 'Launch a web server to examine backup sets',
     )
 
-    log('Common commands:\n')
+    log('Common commands:')
     for cmd,synopsis in sorted(common.items()):
-        log('    %-10s %s\n' % (cmd, synopsis))
-    log('\n')
-    
-    log('Other available commands:\n')
+        log('    %-10s %s' % (cmd, synopsis))
+    log('')
+
+    log('Other available commands:')
     cmds = []
     for c in sorted(os.listdir(cmdpath) + os.listdir(exepath)):
         if c.startswith('bup-') and c.find('.') < 0:
@@ -58,12 +59,12 @@ def usage(msg=""):
             if cname not in common:
                 cmds.append(c[4:])
     log(columnate(cmds, '    '))
-    log('\n')
-    
+
     log("See 'bup help COMMAND' for more information on " +
-        "a specific command.\n")
+        "a specific command.")
     if msg:
-        log("\n%s\n" % msg)
+        log('')
+        log("%s" % msg)
     sys.exit(99)
 
 
@@ -75,7 +76,7 @@ try:
     optspec = ['help', 'version', 'debug', 'profile', 'bup-dir=']
     global_args, subcmd = getopt.getopt(argv[1:], '?VDd:', optspec)
 except getopt.GetoptError, ex:
-    usage('error: %s' % ex.msg)
+    usage('Error: %s!' % ex.msg)
 
 help_requested = None
 do_profile = False
@@ -93,7 +94,7 @@ for opt in global_args:
     elif opt[0] in ['-d', '--bup-dir']:
         os.environ['BUP_DIR'] = opt[1]
     else:
-        usage('error: unexpected option "%s"' % opt[0])
+        usage('Error: Unexpected option "%s"!' % opt[0])
 
 # Make BUP_DIR absolute, so we aren't affected by chdir (i.e. save -C, etc.).
 if 'BUP_DIR' in os.environ:
@@ -123,7 +124,7 @@ def subpath(s):
 
 subcmd[0] = subpath(subcmd_name)
 if not os.path.exists(subcmd[0]):
-    usage('error: unknown command "%s"' % subcmd_name)
+    usage('Error: Unknown command "%s"!' % subcmd_name)
 
 already_fixed = atoi(os.environ.get('BUP_FORCE_TTY'))
 if subcmd_name in ['mux', 'ftp', 'help']:
@@ -151,19 +152,29 @@ else:
     outf = None
     errf = None
 
+ret = 95
+p = None
+forward_signals = True
 
-class SigException(Exception):
-    def __init__(self, signum):
-        self.signum = signum
-        Exception.__init__(self, 'signal %d received' % signum)
 def handler(signum, frame):
-    raise SigException(signum)
+    debug1('bup: Signal %d received!' % signum)
+    if not p or not forward_signals:
+        return
+    if signum != signal.SIGTSTP:
+        os.kill(p.pid, signum)
+    else: # SIGTSTP: stop the child, then ourselves.
+        os.kill(p.pid, signal.SIGSTOP)
+        signal.signal(signal.SIGTSTP, signal.SIG_DFL)
+        os.kill(os.getpid(), signal.SIGTSTP)
+        # Back from suspend -- reestablish the handler.
+        signal.signal(signal.SIGTSTP, handler)
+    ret = 94
 
 signal.signal(signal.SIGTERM, handler)
 signal.signal(signal.SIGINT, handler)
+signal.signal(signal.SIGTSTP, handler)
+signal.signal(signal.SIGCONT, handler)
 
-ret = 95
-p = None
 try:
     try:
         c = (do_profile and [sys.executable, '-m', 'cProfile'] or []) + subcmd
@@ -176,15 +187,11 @@ try:
         while 1:
             # if we get a signal while waiting, we have to keep waiting, just
             # in case our child doesn't die.
-            try:
-                ret = p.wait()
-                break
-            except SigException, e:
-                log('\nbup: %s\n' % e)
-                os.kill(p.pid, e.signum)
-                ret = 94
+            ret = p.wait()
+            forward_signals = False
+            break
     except OSError, e:
-        log('%s: %s\n' % (subcmd[0], e))
+        log('%s: %s' % (subcmd[0], e))
         ret = 98
 finally:
     if p and p.poll() == None: