def connect(rhost, port, subcmd): """Connect to 'rhost' and execute the bup subcommand 'subcmd' on it.""" assert(not re.search(r'[^\w-]', subcmd)) nicedir = re.sub(r':', "_", path.exedir()) if rhost == '-': rhost = None if not rhost: argv = ['bup', subcmd] else: # WARNING: shell quoting security holes are possible here, so we # have to be super careful. We have to use 'sh -c' because # csh-derived shells can't handle PATH= notation. We can't # set PATH in advance, because ssh probably replaces it. We # can't exec *safely* using argv, because *both* ssh and 'sh -c' # allow shellquoting. So we end up having to double-shellquote # stuff here. escapedir = re.sub(r'([^\w/])', r'\\\\\\\1', nicedir) buglvl = helpers.atoi(os.environ.get('BUP_DEBUG')) force_tty = helpers.atoi(os.environ.get('BUP_FORCE_TTY')) cmd = r""" sh -c PATH=%s:'$PATH BUP_DEBUG=%s BUP_FORCE_TTY=%s bup %s' """ % (escapedir, buglvl, force_tty, subcmd) argv = ['ssh'] if port: argv.extend(('-p', port)) argv.extend((rhost, '--', cmd.strip())) #helpers.log('argv is: %r\n' % argv) def setup(): # runs in the child process if not rhost: os.environ['PATH'] = ':'.join([nicedir, os.environ.get('PATH', '')]) os.setsid() return subprocess.Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE, preexec_fn=setup)
def connect(rhost, port, subcmd, stderr=None): """Connect to 'rhost' and execute the bup subcommand 'subcmd' on it.""" assert not re.search(br'[^\w-]', subcmd) nicedir = re.sub(b':', b'_', path.exedir()) if rhost == b'-': rhost = None if not rhost: argv = [b'bup', subcmd] else: # WARNING: shell quoting security holes are possible here, so we # have to be super careful. We have to use 'sh -c' because # csh-derived shells can't handle PATH= notation. We can't # set PATH in advance, because ssh probably replaces it. We # can't exec *safely* using argv, because *both* ssh and 'sh -c' # allow shellquoting. So we end up having to double-shellquote # stuff here. escapedir = re.sub(br'([^\w/])', br'\\\\\\\1', nicedir) buglvl = helpers.atoi(environ.get(b'BUP_DEBUG')) force_tty = helpers.atoi(environ.get(b'BUP_FORCE_TTY')) cmd = b""" sh -c PATH=%s:'$PATH BUP_DEBUG=%s BUP_FORCE_TTY=%s bup %s' """ % (escapedir, buglvl, force_tty, subcmd) argv = [b'ssh'] if port: argv.extend((b'-p', port)) argv.extend((rhost, b'--', cmd.strip())) #helpers.log('argv is: %r\n' % argv) if rhost: env = environ else: envpath = environ.get(b'PATH') env = environ.copy() env[b'PATH'] = nicedir if not envpath else nicedir + b':' + envpath if sys.version_info[0] < 3: return subprocess.Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr, env=env, preexec_fn=lambda: os.setsid()) else: return subprocess.Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr, env=env, start_new_session=True)
def connect(rhost, port, subcmd, stderr=None): """Connect to 'rhost' and execute the bup subcommand 'subcmd' on it.""" assert (not re.search(r'[^\w-]', subcmd)) nicedir = re.sub(r':', "_", path.exedir()) if rhost == '-': rhost = None if not rhost: argv = ['bup', subcmd] else: # WARNING: shell quoting security holes are possible here, so we # have to be super careful. We have to use 'sh -c' because # csh-derived shells can't handle PATH= notation. We can't # set PATH in advance, because ssh probably replaces it. We # can't exec *safely* using argv, because *both* ssh and 'sh -c' # allow shellquoting. So we end up having to double-shellquote # stuff here. escapedir = re.sub(r'([^\w/])', r'\\\\\\\1', nicedir) buglvl = helpers.atoi(os.environ.get('BUP_DEBUG')) force_tty = helpers.atoi(os.environ.get('BUP_FORCE_TTY')) cmd = r""" sh -c PATH=%s:'$PATH BUP_DEBUG=%s BUP_FORCE_TTY=%s bup %s' """ % (escapedir, buglvl, force_tty, subcmd) argv = ['ssh'] if port: argv.extend(('-p', port)) argv.extend((rhost, '--', cmd.strip())) #helpers.log('argv is: %r\n' % argv) def setup(): # runs in the child process if not rhost: os.environ['PATH'] = ':'.join( [nicedir, os.environ.get('PATH', '')]) os.setsid() return subprocess.Popen(argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr, preexec_fn=setup)
def main(argv): o = options.Options(optspec) opt, flags, extra = o.parse_bytes(argv[1:]) if len(extra) == 0: # the wrapper program provides the default usage string os.execvp(path.exe(), [path.exe()]) elif len(extra) == 1: docname = (extra[0] == 'bup' and b'bup' or (b'bup-%s' % argv_bytes(extra[0]))) manpath = os.path.join(path.exedir(), b'../../Documentation/' + docname + b'.[1-9]') g = glob.glob(manpath) try: if g: os.execvp('man', ['man', '-l', g[0]]) else: os.execvp('man', ['man', docname]) except OSError as e: sys.stderr.write('Unable to run man command: %s\n' % e) sys.exit(1) else: o.fatal("exactly one command name expected")
sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/..'] from bup import compat, options, path from bup.compat import argv_bytes optspec = """ bup help <command> """ o = options.Options(optspec) opt, flags, extra = o.parse(compat.argv[1:]) if len(extra) == 0: # the wrapper program provides the default usage string os.execvp(path.exe(), [b'bup']) elif len(extra) == 1: docname = (extra[0] == 'bup' and b'bup' or (b'bup-%s' % argv_bytes(extra[0]))) manpath = os.path.join(path.exedir(), b'../../Documentation/' + docname + b'.[1-9]') g = glob.glob(manpath) try: if g: os.execvp('man', ['man', '-l', g[0]]) else: os.execvp('man', ['man', docname]) except OSError as e: sys.stderr.write('Unable to run man command: %s\n' % e) sys.exit(1) else: o.fatal("exactly one command name expected")
exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble import sys, os, glob from bup import options, path optspec = """ bup help <command> """ o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) if len(extra) == 0: # the wrapper program provides the default usage string os.execvp(os.environ['BUP_MAIN_EXE'], ['bup']) elif len(extra) == 1: docname = (extra[0]=='bup' and 'bup' or ('bup-%s' % extra[0])) manpath = os.path.join(path.exedir(), 'Documentation/' + docname + '.[1-9]') g = glob.glob(manpath) try: if g: os.execvp('man', ['man', '-l', g[0]]) else: os.execvp('man', ['man', docname]) except OSError, e: sys.stderr.write('Unable to run man command: %s\n' % e) sys.exit(1) else: o.fatal("exactly one command name expected")
#!/usr/bin/env python import sys, os, glob from bup import options, path optspec = """ bup help <command> """ o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) if len(extra) == 0: # the wrapper program provides the default usage string os.execvp(os.environ["BUP_MAIN_EXE"], ["bup"]) elif len(extra) == 1: docname = extra[0] == "bup" and "bup" or ("bup-%s" % extra[0]) manpath = os.path.join(path.exedir(), "Documentation/" + docname + ".[1-9]") g = glob.glob(manpath) try: if g: os.execvp("man", ["man", "-l", g[0]]) else: os.execvp("man", ["man", docname]) except OSError, e: sys.stderr.write("Unable to run man command: %s\n" % e) sys.exit(1) else: o.fatal("exactly one command name expected")