sys.stderr.write(s)
def usage():
- log('Usage: %s <subcmd> <options...>\n\n' % exe)
+ log('Usage: bup <subcmd> <options...>\n\n')
log('Available subcommands:\n')
for c in sorted(os.listdir(exepath)):
if c.startswith('bup-') and c.find('.') < 0:
subpath = os.path.join(exepath, 'bup-%s' % subcmd)
if not os.path.exists(subpath):
- log('%s: unknown command "%s"\n' % (exe, subcmd))
+ log('error: unknown command "%s"\n' % subcmd)
usage()
try:
(opt, flags, extra) = o.parse(sys.argv[1:])
if not extra:
- o.usage()
+ o.fatal('filenames expected')
if opt.seed != None:
random.seed(opt.seed)
(opt, flags, extra) = o.parse(sys.argv[1:])
if len(extra) != 1:
- log("drecurse: exactly one filename expected\n")
- o.usage()
+ o.fatal("exactly one filename expected")
it = drecurse.recursive_dirlist(extra, opt.xdev)
if opt.profile:
(opt, flags, extra) = o.parse(sys.argv[1:])
if len(extra) != 1:
- log("bup fuse: exactly one argument expected\n")
- o.usage()
+ o.fatal("exactly one argument expected")
git.check_repo_or_die()
top = vfs.RefList(None)
(opt, flags, extra) = o.parse(sys.argv[1:])
if not (opt.modified or opt['print'] or opt.status or opt.update or opt.check):
- log('bup index: supply one or more of -p, -s, -m, -u, or --check\n')
- o.usage()
+ o.fatal('supply one or more of -p, -s, -m, -u, or --check')
if (opt.fake_valid or opt.fake_invalid) and not opt.update:
- log('bup index: --fake-{in,}valid are meaningless without -u\n')
- o.usage()
+ o.fatal('--fake-{in,}valid are meaningless without -u')
if opt.fake_valid and opt.fake_invalid:
- log('bup index: --fake-valid is incompatible with --fake-invalid\n')
- o.usage()
+ o.fatal('--fake-valid is incompatible with --fake-invalid')
git.check_repo_or_die()
indexfile = opt.indexfile or git.repo('bupindex')
if opt.update:
if not paths:
- log('bup index: update (-u) requested but no paths given\n')
- o.usage()
+ o.fatal('update (-u) requested but no paths given')
for (rp,path) in paths:
update_index(rp)
(opt, flags, extra) = o.parse(sys.argv[1:])
if extra:
- log("bup init: no arguments expected\n")
- o.usage()
+ o.fatal("no arguments expected")
if opt.remote:
(opt, flags, extra) = o.parse(sys.argv[1:])
if extra:
- log("bup margin: no arguments expected\n")
- o.usage()
+ o.fatal("no arguments expected")
git.check_repo_or_die()
#git.ignore_midx = 1
(opt, flags, extra) = o.parse(sys.argv[1:])
if extra and (opt.auto or opt.force):
- log("bup midx: you can't use -f/-a and also provide filenames\n")
- o.usage()
+ o.fatal("you can't use -f/-a and also provide filenames")
git.check_repo_or_die()
do_midx(path, opt.output, needed.keys())
log('\n')
else:
- log("bup midx: you must use -f or -a or provide input filenames\n")
- o.usage()
+ o.fatal("you must use -f or -a or provide input filenames")
(opt, flags, extra) = o.parse(sys.argv[1:])
if len(extra) != 1:
- log("bup random: exactly one argument expected\n")
- o.usage()
+ o.fatal("exactly one argument expected")
total = parse_num(extra[0])
_hashsplit.write_random(sys.stdout.fileno(), total, opt.seed or 0)
git.check_repo_or_die()
if not (opt.tree or opt.commit or opt.name):
- log("bup save: use one or more of -t, -c, -n\n")
- o.usage()
+ o.fatal("use one or more of -t, -c, -n")
if not extra:
- log("bup save: no filenames given.\n")
- o.usage()
+ o.fatal("no filenames given")
opt.progress = (istty and not opt.quiet)
(opt, flags, extra) = o.parse(sys.argv[1:])
if extra:
- log('bup server: no arguments expected\n')
- o.usage()
+ o.fatal('no arguments expected')
log('bup server: reading from stdin.\n')
git.check_repo_or_die()
if not (opt.blobs or opt.tree or opt.commit or opt.name or
opt.noop or opt.copy):
- log("bup split: use one or more of -b, -t, -c, -n, -N, --copy\n")
- o.usage()
+ o.fatal("use one or more of -b, -t, -c, -n, -N, --copy")
if (opt.noop or opt.copy) and (opt.blobs or opt.tree or
opt.commit or opt.name):
- log('bup split: -N is incompatible with -b, -t, -c, -n\n')
- o.usage()
+ o.fatal('-N is incompatible with -b, -t, -c, -n')
if opt.verbose >= 2:
git.verbose = opt.verbose - 1
(opt, flags, extra) = o.parse(sys.argv[1:])
if extra:
- log("bup tick: no arguments expected\n")
- o.usage()
+ o.fatal("no arguments expected")
t = time.time()
tleft = 1 - (t - int(t))
(opt, flags, extra) = o.parse(sys.argv[1:])
if extra:
- o.usage()
+ o.fatal('no arguments expected')
git.ignore_midx = opt.ignore_midx
out.append(argtext + '\n')
else:
out.append('\n')
- return ''.join(out)
+ return ''.join(out).rstrip() + '\n'
def usage(self):
log(self._usagestr)
sys.exit(97)
+
+ def fatal(self, s):
+ log('error: %s\n' % s)
+ return self.usage()
def parse(self, args):
try:
(flags,extra) = getopt.gnu_getopt(args,
self._shortopts, self._longopts)
except getopt.GetoptError, e:
- log('%s: %s\n' % (self.exe, e))
- self.usage()
+ self.fatal(e)
opt = OptDict()
for f in self._aliases.values():