from pkgutil import iter_modules
from subprocess import PIPE
from threading import Thread
-import errno, re, select, signal, subprocess
+import re, select, signal, subprocess
from bup import compat, path, helpers
from bup.compat import (
ModuleNotFoundError,
add_ex_ctx,
add_ex_tb,
- argv_bytes,
environ,
fsdecode,
int_types,
wrap_main
)
-from bup.compat import add_ex_tb, add_ex_ctx, argv_bytes, wrap_main
+from bup.compat import add_ex_tb, add_ex_ctx, wrap_main
from bup.helpers import (
columnate,
- debug1,
handle_ctrl_c,
log,
- merge_dict,
tty_width
)
from bup.git import close_catpipes
for cmd,synopsis in sorted(common.items()):
log(' %-10s %s\n' % (cmd, synopsis))
log('\n')
-
+
log('Other available commands:\n')
cmds = set()
for c in sorted(os.listdir(cmdpath)):
log(columnate(sorted(cmds), ' '))
log('\n')
-
+
log("See 'bup help COMMAND' for more information on " +
"a specific command.\n")
if msg:
log("\n%s\n" % msg)
sys.exit(99)
+def extract_argval(args):
+ """Assume args (all elements bytes) starts with a -x, --x, or --x=,
+argument that requires a value and return that value and the remaining
+args. Exit with an errror if the value is missing.
+
+ """
+ # Assumes that first arg is a valid arg
+ arg = args[0]
+ if b'=' in arg:
+ val = arg.split(b'=')[1]
+ if not val:
+ usage('error: no value provided for %s option' % arg)
+ return val, args[1:]
+ if len(args) < 2:
+ usage('error: no value provided for %s option' % arg)
+ return args[1], args[2:]
+
+
args = compat.get_argvb()
if len(args) < 2:
usage()
elif arg == b'--profile':
do_profile = True
args = args[1:]
- elif arg in (b'-d', b'--bup-dir'):
- if len(args) < 2:
- usage('error: no path provided for %s option' % arg)
- bup_dir = args[1]
- args = args[2:]
- elif arg == b'--import-py-module':
- args = args[2:]
+ elif arg in (b'-d', b'--bup-dir') or arg.startswith(b'--bup-dir='):
+ bup_dir, args = extract_argval(args)
+ elif arg == b'--import-py-module' or arg.startswith(b'--import-py-module='):
+ # Just need to skip it here
+ _, args = extract_argval(args)
elif arg.startswith(b'-'):
usage('error: unexpected option "%s"'
% arg.decode('ascii', 'backslashescape'))
fix_stderr = not already_fixed and os.isatty(2)
if fix_stdout or fix_stderr:
- tty_env = merge_dict(environ,
- {b'BUP_FORCE_TTY': (b'%d'
- % ((fix_stdout and 1 or 0)
- + (fix_stderr and 2 or 0))),
- b'BUP_TTY_WIDTH': b'%d' % _tty_width(), })
-else:
- tty_env = environ
+ _ttymask = (fix_stdout and 1 or 0) + (fix_stderr and 2 or 0)
+ environ[b'BUP_FORCE_TTY'] = b'%d' % _ttymask
+ environ[b'BUP_TTY_WIDTH'] = b'%d' % _tty_width()
sep_rx = re.compile(br'([\r\n])')
assert not sep_rx.match(x)
content = b''.join(content)
if sep == b'\r' and len(content) > width:
- content = content[width:]
+ content = content[:width]
os.write(dest, content)
if len(content) < width:
os.write(dest, b' ' * (width - len(content)))
"""
global sep_rx
- assert all(type(x) in int_types for x in srcs)
- assert all(type(x) in int_types for x in srcs)
+ assert all(isinstance(x, int_types) for x in srcs)
assert len(srcs) == len(dests)
srcs = tuple(srcs)
dest_for = dict(zip(srcs, dests))
p = subprocess.Popen(c,
stdout=PIPE if fix_stdout else out,
stderr=PIPE if fix_stderr else err,
- env=tty_env, bufsize=4096, close_fds=True)
+ bufsize=4096, close_fds=True)
# Assume p will receive these signals and quit, which will
# then cause us to quit.
for sig in (signal.SIGINT, signal.SIGTERM, signal.SIGQUIT):