From: Avery Pennarun Date: Mon, 30 May 2011 00:02:29 +0000 (-0400) Subject: Merge branch 'config' X-Git-Tag: bup-0.25-rc1~7 X-Git-Url: https://arthur.barton.de/gitweb/?a=commitdiff_plain;h=bf6e0c48f278f3ea9917a7704ef5770a84cdb1b7;hp=9fd2cd540967d094a5bb9ab3649b787283e3ad52;p=bup.git Merge branch 'config' * config: config: more config stuff to config/ subdir, call it from Makefile. Initial import of configure.sh --- diff --git a/Documentation/bup-ftp.md b/Documentation/bup-ftp.md index 8173320..a6117cc 100644 --- a/Documentation/bup-ftp.md +++ b/Documentation/bup-ftp.md @@ -27,10 +27,13 @@ lot of typing. The following commands are available inside `bup ftp`: -ls [-a] -: print the contents of the current working directory. +ls [-s] [-a] [*path*] +: print the contents of a directory. If no path argument + is given, the current directory's contents are listed. If -a is given, also include hidden files (files which - start with a `.` character). + start with a `.` character). If -s is given, each file + is displayed with its hash from the bup archive to its + left. cd *dirname* : change to a different working directory diff --git a/Documentation/bup-ls.md b/Documentation/bup-ls.md index cef01be..ed07ca6 100644 --- a/Documentation/bup-ls.md +++ b/Documentation/bup-ls.md @@ -21,6 +21,13 @@ the `-n` option in `bup save`), the next level is the date of the backup, and subsequent levels correspond to files in the backup. +When `bup ls` is asked to output on a tty, it formats its output +in columns so that it can list as much as possible in as few lines +as possible. However, when `bup ls` is asked to output to something +other than a tty (say you pipe the output to another command, or you +redirect it to a file), it will output one file name per line. This +makes the listing easier to parse with external tools. + Note that `bup ls` doesn't show hidden files by default and one needs to use the `-a` option to show them. Files are hidden when their name begins with a dot. For example, on the topmost level, the special directories named `.commit` diff --git a/README.md b/README.md index 94d5c56..acc5e53 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,11 @@ Reasons you might want to avoid bup Getting started ---------------- +=============== + + +From source +----------- - Check out the bup source code using git: @@ -108,7 +112,23 @@ Getting started (The tests should pass. If they don't pass for you, stop here and send me an email.) - + + +From binary packages +-------------------- + +Binary packages of bup are known to be built for the following OSes: + + - Debian: + http://packages.debian.org/search?searchon=names&keywords=bup + - Ubuntu: + http://packages.ubuntu.com/search?searchon=names&keywords=bup + - NetBSD + + +Using bup +--------- + - Try making a local backup as a tar file: tar -cvf - /etc | bup split -n local-etc -vv @@ -171,7 +191,7 @@ That's all there is to it! Notes on FreeBSD -================ +---------------- - FreeBSD's default 'make' command doesn't like bup's Makefile. In order to compile the code, run tests and install bup, you need to install GNU Make @@ -192,7 +212,7 @@ Notes on FreeBSD How it works ------------- +============ Basic storage: @@ -326,7 +346,7 @@ join, index, save, etc.) to get details on that command. How you can help ----------------- +================ bup is a work in progress and there are many ways it can still be improved. If you'd like to contribute patches, ideas, or bug reports, please join the diff --git a/cmd/ftp-cmd.py b/cmd/ftp-cmd.py index d63a710..62f2cbc 100755 --- a/cmd/ftp-cmd.py +++ b/cmd/ftp-cmd.py @@ -1,51 +1,22 @@ #!/usr/bin/env python import sys, os, stat, fnmatch -from bup import options, git, shquote, vfs +from bup import options, git, shquote, vfs, ls from bup.helpers import * handle_ctrl_c() -def node_name(text, n): - if stat.S_ISDIR(n.mode): - return '%s/' % text - elif stat.S_ISLNK(n.mode): - return '%s@' % text - else: - return '%s' % text - - class OptionError(Exception): pass -ls_optspec = """ -ls [-a] [path...] --- -a,all include hidden files in the listing -""" -ls_opt = options.Options(ls_optspec, onabort=OptionError) - +# Check out lib/bup/ls.py for the opt spec def do_ls(cmd_args): try: - (opt, flags, extra) = ls_opt.parse(cmd_args) + ls.do_ls(cmd_args, pwd, onabort=OptionError) except OptionError, e: return - L = [] - - for path in (extra or ['.']): - n = pwd.try_resolve(path) - - if stat.S_ISDIR(n.mode): - for sub in n: - name = sub.name - if opt.all or not len(name)>1 or not name.startswith('.'): - L.append(node_name(name, sub)) - else: - L.append(node_name(path, n)) - print columnate(L, '') - def write_to_file(inf, outf): for blob in chunkyreader(inf): @@ -58,6 +29,7 @@ def inputiter(): try: yield raw_input('bup> ') except EOFError: + print '' # Clear the line for the terminal's next prompt break else: for line in sys.stdin: diff --git a/cmd/ls-cmd.py b/cmd/ls-cmd.py index 3854a50..581d6e1 100755 --- a/cmd/ls-cmd.py +++ b/cmd/ls-cmd.py @@ -1,48 +1,13 @@ #!/usr/bin/env python -import sys, stat -from bup import options, git, vfs +import sys +from bup import git, vfs, ls from bup.helpers import * -def print_node(text, n): - prefix = '' - if opt.hash: - prefix += "%s " % n.hash.encode('hex') - if stat.S_ISDIR(n.mode): - print '%s%s/' % (prefix, text) - elif stat.S_ISLNK(n.mode): - print '%s%s@' % (prefix, text) - else: - print '%s%s' % (prefix, text) - - -optspec = """ -bup ls --- -s,hash show hash for each file -a,all show hidden files -""" -o = options.Options(optspec) -(opt, flags, extra) = o.parse(sys.argv[1:]) git.check_repo_or_die() top = vfs.RefList(None) -if not extra: - extra = ['/'] - -ret = 0 -for d in extra: - try: - n = top.lresolve(d) - if stat.S_ISDIR(n.mode): - for sub in n: - if opt.all or not sub.name.startswith('.'): - print_node(sub.name, sub) - else: - if opt.all or not n.name.startswith('.'): - print_node(d, n) - except vfs.NodeError, e: - log('error: %s\n' % e) - ret = 1 +# Check out lib/bup/ls.py for the opt spec +ret = ls.do_ls(sys.argv[1:], top, default='/', spec_prefix='bup ') sys.exit(ret) diff --git a/lib/bup/git.py b/lib/bup/git.py index 58cd4a6..421c306 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -843,7 +843,8 @@ def check_repo_or_die(path=None): except OSError, e: if e.errno == errno.ENOENT: if repodir != home_repodir: - log('error: %r is not a bup/git repository\n' % repo()) + log('error: %r is not a bup repository; run "bup init"\n' + % repo()) sys.exit(15) else: init_repo() diff --git a/lib/bup/ls.py b/lib/bup/ls.py new file mode 100644 index 0000000..fe04f8a --- /dev/null +++ b/lib/bup/ls.py @@ -0,0 +1,67 @@ +"""Common code for listing files from a bup repository.""" +import stat +from bup import options, vfs +from helpers import * + + +def node_name(text, n, show_hash): + """Add symbols to a node's name to differentiate file types.""" + prefix = '' + if show_hash: + prefix += "%s " % n.hash.encode('hex') + if stat.S_ISDIR(n.mode): + return '%s%s/' % (prefix, text) + elif stat.S_ISLNK(n.mode): + return '%s%s@' % (prefix, text) + else: + return '%s%s' % (prefix, text) + + +optspec = """ +%sls [-a] [path...] +-- +s,hash show hash for each file +a,all show hidden files +""" + +def do_ls(args, pwd, default='.', onabort=None, spec_prefix=''): + """Output a listing of a file or directory in the bup repository. + + When stdout is attached to a tty, the output is formatted in columns. When + not attached to tty (for example when the output is piped to another + command), one file is listed per line. + """ + if onabort: + o = options.Options(optspec % spec_prefix, onabort=onabort) + else: + o = options.Options(optspec % spec_prefix) + (opt, flags, extra) = o.parse(args) + + L = [] + + ret = 0 + for path in (extra or [default]): + try: + n = pwd.try_resolve(path) + + if stat.S_ISDIR(n.mode): + for sub in n: + name = sub.name + if opt.all or not len(name)>1 or not name.startswith('.'): + if istty1: + L.append(node_name(name, sub, opt.hash)) + else: + print node_name(name, sub, opt.hash) + else: + if istty1: + L.append(node_name(path, n, opt.hash)) + else: + print node_name(path, n, opt.hash) + except vfs.NodeError, e: + log('error: %s\n' % e) + ret = 1 + + if istty1: + sys.stdout.write(columnate(L, '')) + + return ret