2 from os import chdir, mkdir, symlink, unlink
3 from subprocess import PIPE
4 from time import localtime, strftime, tzset
7 from bup.compat import environ
8 from bup.helpers import unlink as unlink_if_exists
9 from buptest import ex, exo
10 from wvpytest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
13 bup_cmd = bup.path.exe()
15 def bup(*args, **kwargs):
16 if 'stdout' not in kwargs:
17 return exo((bup_cmd,) + args, **kwargs)
18 return ex((bup_cmd,) + args, **kwargs)
21 return b''.join(line + b'\n' for line in lines)
23 def match_rx_grp(rx, expected, src):
24 match = re.fullmatch(rx, src)
25 wvpass(match, 're.fullmatch(%r, %r)' % (rx, src))
28 wvpasseq(expected, match.groups())
30 environ[b'GIT_AUTHOR_NAME'] = b'bup test'
31 environ[b'GIT_COMMITTER_NAME'] = b'bup test'
32 environ[b'GIT_AUTHOR_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
33 environ[b'GIT_COMMITTER_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
36 environ[b'BUP_DIR'] = tmpdir + b'/repo'
37 environ[b'GIT_DIR'] = tmpdir + b'/repo'
38 environ[b'TZ'] = b'UTC'
45 with open(b'file-1', 'wb') as f:
46 f.write(b'excitement!\n')
47 with open(b'dir/file-2', 'wb') as f:
48 f.write(b'more excitement!\n')
49 symlink(b'file-1', b'file-symlink')
50 symlink(b'dir', b'dir-symlink')
51 symlink(b'not-there', b'bad-symlink')
56 bup(b'save', b'-n', b'src', b'--strip', b'src')
57 save_utc = int(exo((b'git', b'show',
58 b'-s', b'--format=%at', b'src')).out.strip())
59 save_name = strftime('%Y-%m-%d-%H%M%S', localtime(save_utc)).encode('ascii')
62 wvpasseq(b'Commands: ls cd pwd cat get mget help quit\n',
63 exo((bup_cmd, b'ftp'), input=b'help\n', stderr=PIPE).out)
66 wvpasseq(b'/\n', bup(b'ftp', input=b'pwd\n').out)
67 wvpasseq(b'', bup(b'ftp', input=b'cd src\n').out)
68 wvpasseq(b'/src\n', bup(b'ftp', input=jl(b'cd src', b'pwd')).out)
69 wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
70 b'cd ..', b'pwd')).out)
71 wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
74 wvpasseq(b'/src/%s/dir\n' % save_name,
75 bup(b'ftp', input=jl(b'cd src/latest/dir-symlink', b'pwd')).out)
76 wvpasseq(b'/src/%s/dir\n' % save_name,
77 bup(b'ftp', input=jl(b'cd src latest dir-symlink', b'pwd')).out)
79 match_rx_grp(br'(error: path does not exist: /src/)[0-9-]+(/not-there\n/\n)',
80 (b'error: path does not exist: /src/', b'/not-there\n/\n'),
81 bup(b'ftp', input=jl(b'cd src/latest/bad-symlink', b'pwd')).out)
83 match_rx_grp(br'(error: path does not exist: /src/)[0-9-]+(/not-there\n/\n)',
84 (b'error: path does not exist: /src/', b'/not-there\n/\n'),
85 bup(b'ftp', input=jl(b'cd src/latest/not-there', b'pwd')).out)
89 wvpasseq(b'src\n', bup(b'ftp', input=b'ls\n').out)
90 wvpasseq(save_name + b'\nlatest\n',
91 bup(b'ftp', input=b'ls src\n').out)
94 wvpasseq(b'excitement!\n',
95 bup(b'ftp', input=b'cat src/latest/file-1\n').out)
96 wvpasseq(b'excitement!\nmore excitement!\n',
98 input=b'cat src/latest/file-1 src/latest/dir/file-2\n').out)
101 bup(b'ftp', input=jl(b'get src/latest/file-1 dest'))
102 with open(b'dest', 'rb') as f:
103 wvpasseq(b'excitement!\n', f.read())
105 bup(b'ftp', input=jl(b'get src/latest/file-symlink dest'))
106 with open(b'dest', 'rb') as f:
107 wvpasseq(b'excitement!\n', f.read())
110 match_rx_grp(br'(error: path does not exist: /src/)[0-9-]+(/not-there\n)',
111 (b'error: path does not exist: /src/', b'/not-there\n'),
112 bup(b'ftp', input=jl(b'get src/latest/bad-symlink dest')).out)
114 match_rx_grp(br'(error: path does not exist: /src/)[0-9-]+(/not-there\n)',
115 (b'error: path does not exist: /src/', b'/not-there\n'),
116 bup(b'ftp', input=jl(b'get src/latest/not-there dest')).out)
119 unlink_if_exists(b'file-1')
120 bup(b'ftp', input=jl(b'mget src/latest/file-1'))
121 with open(b'file-1', 'rb') as f:
122 wvpasseq(b'excitement!\n', f.read())
123 unlink_if_exists(b'file-1')
124 unlink_if_exists(b'file-2')
125 bup(b'ftp', input=jl(b'mget src/latest/file-1 src/latest/dir/file-2'))
126 with open(b'file-1', 'rb') as f:
127 wvpasseq(b'excitement!\n', f.read())
128 with open(b'file-2', 'rb') as f:
129 wvpasseq(b'more excitement!\n', f.read())
130 unlink_if_exists(b'file-symlink')
131 bup(b'ftp', input=jl(b'mget src/latest/file-symlink'))
132 with open(b'file-symlink', 'rb') as f:
133 wvpasseq(b'excitement!\n', f.read())
134 # bup mget currently always does pattern matching
135 bup(b'ftp', input=b'mget src/latest/not-there\n')