3 bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from __future__ import print_function
9 from os import environ, chdir, mkdir, symlink, unlink
10 from os.path import abspath, dirname
11 from time import localtime, strftime
14 script_home = abspath(dirname(sys.argv[0] or '.'))
15 sys.path[:0] = [abspath(script_home + '/../lib'), abspath(script_home + '/..')]
17 bup_cmd = top + '/bup'
19 from buptest import exc, exo, logcmd, test_tempdir
20 from wvtest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
22 from bup.helpers import unlink as unlink_if_exists
24 def bup(*args, **kwargs):
25 return exo((bup_cmd,) + args, **kwargs)[0]
27 def bupc(*args, **kwargs):
28 return exc((bup_cmd,) + args, **kwargs)
31 return ''.join(line + '\n' for line in lines)
33 environ['GIT_AUTHOR_NAME'] = 'bup test'
34 environ['GIT_COMMITTER_NAME'] = 'bup test'
35 environ['GIT_AUTHOR_EMAIL'] = 'bup@a425bc70a02811e49bdf73ee56450e6f'
36 environ['GIT_COMMITTER_EMAIL'] = 'bup@a425bc70a02811e49bdf73ee56450e6f'
38 with test_tempdir('ftp-') as tmpdir:
39 environ['BUP_DIR'] = tmpdir + '/repo'
40 environ['GIT_DIR'] = tmpdir + '/repo'
46 with open('file-1', 'wb') as f:
47 print('excitement!', file=f)
48 with open('dir/file-2', 'wb') as f:
49 print('more excitement!', file=f)
50 symlink('file-1', 'file-symlink')
51 symlink('dir', 'dir-symlink')
52 symlink('not-there', 'bad-symlink')
57 bupc('save', '-n', 'src', '--strip', 'src')
58 save_utc = int(exo(('git', 'show', '-s', '--format=%at', 'src')).out.strip())
59 save_name = strftime('%Y-%m-%d-%H%M%S', localtime(save_utc))
62 wvpasseq('Commands: ls cd pwd cat get mget help quit\n',
63 exo((bup_cmd, 'ftp'), input='help\n').err)
66 wvpasseq('/\n', bup('ftp', input='pwd\n'))
67 wvpasseq('', bup('ftp', input='cd src\n'))
68 wvpasseq('/src\n', bup('ftp', input=jl('cd src', 'pwd')))
69 wvpasseq('/src\n/\n', bup('ftp', input=jl('cd src', 'pwd', 'cd ..', 'pwd')))
70 wvpasseq('/src\n/\n', bup('ftp', input=jl('cd src', 'pwd',
71 'cd ..', 'cd ..', 'pwd')))
72 wvpasseq('/src/latest/dir\n',
73 bup('ftp', input=jl('cd src/latest/dir-symlink', 'pwd')))
74 wvpasseq('/src/latest/dir\n',
75 bup('ftp', input=jl('cd src latest dir-symlink', 'pwd')))
76 wvpassne(0, bupc('ftp',
77 input=jl('cd src/latest/bad-symlink', 'pwd'),
79 wvpassne(0, bupc('ftp',
80 input=jl('cd src/latest/not-there', 'pwd'),
85 wvpasseq('src\n', bup('ftp', input='ls\n'))
86 wvpasseq(save_name + '\nlatest\n',
87 bup('ftp', input='ls src\n'))
90 wvpasseq('excitement!\n',
91 bup('ftp', input='cat src/latest/file-1\n'))
92 wvpasseq('excitement!\nmore excitement!\n',
93 bup('ftp', input='cat src/latest/file-1 src/latest/dir/file-2\n'))
96 bupc('ftp', input=jl('get src/latest/file-1 dest'))
97 with open('dest', 'rb') as f:
98 wvpasseq('excitement!\n', f.read())
100 bupc('ftp', input=jl('get src/latest/file-symlink dest'))
101 with open('dest', 'rb') as f:
102 wvpasseq('excitement!\n', f.read())
104 wvpassne(0, bupc('ftp',
105 input=jl('get src/latest/bad-symlink dest'),
107 wvpassne(0, bupc('ftp',
108 input=jl('get src/latest/not-there'),
112 unlink_if_exists('file-1')
113 bupc('ftp', input=jl('mget src/latest/file-1'))
114 with open('file-1', 'rb') as f:
115 wvpasseq('excitement!\n', f.read())
116 unlink_if_exists('file-1')
117 unlink_if_exists('file-2')
118 bupc('ftp', input=jl('mget src/latest/file-1 src/latest/dir/file-2'))
119 with open('file-1', 'rb') as f:
120 wvpasseq('excitement!\n', f.read())
121 with open('file-2', 'rb') as f:
122 wvpasseq('more excitement!\n', f.read())
123 unlink_if_exists('file-symlink')
124 bupc('ftp', input=jl('mget src/latest/file-symlink'))
125 with open('file-symlink', 'rb') as f:
126 wvpasseq('excitement!\n', f.read())
127 wvpassne(0, bupc('ftp',
128 input=jl('mget src/latest/bad-symlink dest'),
130 # bup mget currently always does pattern matching
131 bupc('ftp', input='mget src/latest/not-there\n')