3 bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from __future__ import absolute_import, print_function
9 from os import chdir, mkdir, symlink, unlink
10 from os.path import abspath, dirname
11 from subprocess import PIPE
12 from time import localtime, strftime
15 # For buptest, wvtest, ...
16 sys.path[:0] = (abspath(os.path.dirname(__file__) + '/..'),)
18 from buptest import ex, exo, logcmd, test_tempdir
19 from wvtest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
21 from bup.compat import environ
22 from bup.helpers import unlink as unlink_if_exists
25 bup_cmd = bup.path.exe()
27 def bup(*args, **kwargs):
28 if 'stdout' not in kwargs:
29 return exo((bup_cmd,) + args, **kwargs)
30 return ex((bup_cmd,) + args, **kwargs)
33 return b''.join(line + b'\n' for line in lines)
35 environ[b'GIT_AUTHOR_NAME'] = b'bup test'
36 environ[b'GIT_COMMITTER_NAME'] = b'bup test'
37 environ[b'GIT_AUTHOR_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
38 environ[b'GIT_COMMITTER_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
40 with test_tempdir(b'ftp-') as tmpdir:
41 environ[b'BUP_DIR'] = tmpdir + b'/repo'
42 environ[b'GIT_DIR'] = tmpdir + b'/repo'
48 with open(b'file-1', 'wb') as f:
49 f.write(b'excitement!\n')
50 with open(b'dir/file-2', 'wb') as f:
51 f.write(b'more excitement!\n')
52 symlink(b'file-1', b'file-symlink')
53 symlink(b'dir', b'dir-symlink')
54 symlink(b'not-there', b'bad-symlink')
59 bup(b'save', b'-n', b'src', b'--strip', b'src')
60 save_utc = int(exo((b'git', b'show',
61 b'-s', b'--format=%at', b'src')).out.strip())
62 save_name = strftime('%Y-%m-%d-%H%M%S', localtime(save_utc)).encode('ascii')
65 wvpasseq(b'Commands: ls cd pwd cat get mget help quit\n',
66 exo((bup_cmd, b'ftp'), input=b'help\n', stderr=PIPE).err)
69 wvpasseq(b'/\n', bup(b'ftp', input=b'pwd\n').out)
70 wvpasseq(b'', bup(b'ftp', input=b'cd src\n').out)
71 wvpasseq(b'/src\n', bup(b'ftp', input=jl(b'cd src', b'pwd')).out)
72 wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
73 b'cd ..', b'pwd')).out)
74 wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
77 wvpasseq(b'/src/%s/dir\n' % save_name,
78 bup(b'ftp', input=jl(b'cd src/latest/dir-symlink', b'pwd')).out)
79 wvpasseq(b'/src/%s/dir\n' % save_name,
80 bup(b'ftp', input=jl(b'cd src latest dir-symlink', b'pwd')).out)
81 wvpassne(0, bup(b'ftp',
82 input=jl(b'cd src/latest/bad-symlink', b'pwd'),
83 check=False, stdout=None).rc)
84 wvpassne(0, bup(b'ftp',
85 input=jl(b'cd src/latest/not-there', b'pwd'),
86 check=False, stdout=None).rc)
90 wvpasseq(b'src\n', bup(b'ftp', input=b'ls\n').out)
91 wvpasseq(save_name + b'\nlatest\n',
92 bup(b'ftp', input=b'ls src\n').out)
95 wvpasseq(b'excitement!\n',
96 bup(b'ftp', input=b'cat src/latest/file-1\n').out)
97 wvpasseq(b'excitement!\nmore excitement!\n',
99 input=b'cat src/latest/file-1 src/latest/dir/file-2\n').out)
102 bup(b'ftp', input=jl(b'get src/latest/file-1 dest'))
103 with open(b'dest', 'rb') as f:
104 wvpasseq(b'excitement!\n', f.read())
106 bup(b'ftp', input=jl(b'get src/latest/file-symlink dest'))
107 with open(b'dest', 'rb') as f:
108 wvpasseq(b'excitement!\n', f.read())
110 wvpassne(0, bup(b'ftp',
111 input=jl(b'get src/latest/bad-symlink dest'),
112 check=False, stdout=None).rc)
113 wvpassne(0, bup(b'ftp',
114 input=jl(b'get src/latest/not-there'),
115 check=False, stdout=None).rc)
118 unlink_if_exists(b'file-1')
119 bup(b'ftp', input=jl(b'mget src/latest/file-1'))
120 with open(b'file-1', 'rb') as f:
121 wvpasseq(b'excitement!\n', f.read())
122 unlink_if_exists(b'file-1')
123 unlink_if_exists(b'file-2')
124 bup(b'ftp', input=jl(b'mget src/latest/file-1 src/latest/dir/file-2'))
125 with open(b'file-1', 'rb') as f:
126 wvpasseq(b'excitement!\n', f.read())
127 with open(b'file-2', 'rb') as f:
128 wvpasseq(b'more excitement!\n', f.read())
129 unlink_if_exists(b'file-symlink')
130 bup(b'ftp', input=jl(b'mget src/latest/file-symlink'))
131 with open(b'file-symlink', 'rb') as f:
132 wvpasseq(b'excitement!\n', f.read())
133 wvpassne(0, bup(b'ftp',
134 input=jl(b'mget src/latest/bad-symlink dest'),
135 check=False, stdout=None).rc)
136 # bup mget currently always does pattern matching
137 bup(b'ftp', input=b'mget src/latest/not-there\n')