3 bup_python="$(dirname "$0")/../../dev/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__) + '/../..'),)
17 sys.path[:0] = (abspath(os.path.dirname(__file__) + '/../../test/lib'),)
18 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/../../lib']
20 from buptest import ex, exo, logcmd, test_tempdir
21 from wvtest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
23 from bup.compat import environ
24 from bup.helpers import unlink as unlink_if_exists
27 bup_cmd = bup.path.exe()
29 def bup(*args, **kwargs):
30 if 'stdout' not in kwargs:
31 return exo((bup_cmd,) + args, **kwargs)
32 return ex((bup_cmd,) + args, **kwargs)
35 return b''.join(line + b'\n' for line in lines)
37 environ[b'GIT_AUTHOR_NAME'] = b'bup test'
38 environ[b'GIT_COMMITTER_NAME'] = b'bup test'
39 environ[b'GIT_AUTHOR_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
40 environ[b'GIT_COMMITTER_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
42 with test_tempdir(b'ftp-') as tmpdir:
43 environ[b'BUP_DIR'] = tmpdir + b'/repo'
44 environ[b'GIT_DIR'] = tmpdir + b'/repo'
50 with open(b'file-1', 'wb') as f:
51 f.write(b'excitement!\n')
52 with open(b'dir/file-2', 'wb') as f:
53 f.write(b'more excitement!\n')
54 symlink(b'file-1', b'file-symlink')
55 symlink(b'dir', b'dir-symlink')
56 symlink(b'not-there', b'bad-symlink')
61 bup(b'save', b'-n', b'src', b'--strip', b'src')
62 save_utc = int(exo((b'git', b'show',
63 b'-s', b'--format=%at', b'src')).out.strip())
64 save_name = strftime('%Y-%m-%d-%H%M%S', localtime(save_utc)).encode('ascii')
67 wvpasseq(b'Commands: ls cd pwd cat get mget help quit\n',
68 exo((bup_cmd, b'ftp'), input=b'help\n', stderr=PIPE).out)
71 wvpasseq(b'/\n', bup(b'ftp', input=b'pwd\n').out)
72 wvpasseq(b'', bup(b'ftp', input=b'cd src\n').out)
73 wvpasseq(b'/src\n', bup(b'ftp', input=jl(b'cd src', b'pwd')).out)
74 wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
75 b'cd ..', b'pwd')).out)
76 wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
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 wvpasseq(b'/src/%s/dir\n' % save_name,
82 bup(b'ftp', input=jl(b'cd src latest dir-symlink', b'pwd')).out)
83 wvpassne(0, bup(b'ftp',
84 input=jl(b'cd src/latest/bad-symlink', b'pwd'),
85 check=False, stdout=None).rc)
86 wvpassne(0, bup(b'ftp',
87 input=jl(b'cd src/latest/not-there', b'pwd'),
88 check=False, stdout=None).rc)
92 wvpasseq(b'src\n', bup(b'ftp', input=b'ls\n').out)
93 wvpasseq(save_name + b'\nlatest\n',
94 bup(b'ftp', input=b'ls src\n').out)
97 wvpasseq(b'excitement!\n',
98 bup(b'ftp', input=b'cat src/latest/file-1\n').out)
99 wvpasseq(b'excitement!\nmore excitement!\n',
101 input=b'cat src/latest/file-1 src/latest/dir/file-2\n').out)
104 bup(b'ftp', input=jl(b'get src/latest/file-1 dest'))
105 with open(b'dest', 'rb') as f:
106 wvpasseq(b'excitement!\n', f.read())
108 bup(b'ftp', input=jl(b'get src/latest/file-symlink dest'))
109 with open(b'dest', 'rb') as f:
110 wvpasseq(b'excitement!\n', f.read())
112 wvpassne(0, bup(b'ftp',
113 input=jl(b'get src/latest/bad-symlink dest'),
114 check=False, stdout=None).rc)
115 wvpassne(0, bup(b'ftp',
116 input=jl(b'get src/latest/not-there'),
117 check=False, stdout=None).rc)
120 unlink_if_exists(b'file-1')
121 bup(b'ftp', input=jl(b'mget src/latest/file-1'))
122 with open(b'file-1', 'rb') as f:
123 wvpasseq(b'excitement!\n', f.read())
124 unlink_if_exists(b'file-1')
125 unlink_if_exists(b'file-2')
126 bup(b'ftp', input=jl(b'mget src/latest/file-1 src/latest/dir/file-2'))
127 with open(b'file-1', 'rb') as f:
128 wvpasseq(b'excitement!\n', f.read())
129 with open(b'file-2', 'rb') as f:
130 wvpasseq(b'more excitement!\n', f.read())
131 unlink_if_exists(b'file-symlink')
132 bup(b'ftp', input=jl(b'mget src/latest/file-symlink'))
133 with open(b'file-symlink', 'rb') as f:
134 wvpasseq(b'excitement!\n', f.read())
135 wvpassne(0, bup(b'ftp',
136 input=jl(b'mget src/latest/bad-symlink dest'),
137 check=False, stdout=None).rc)
138 # bup mget currently always does pattern matching
139 bup(b'ftp', input=b'mget src/latest/not-there\n')