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 environ, chdir, mkdir, symlink, unlink
10 from os.path import abspath, dirname
11 from subprocess import PIPE
12 from time import localtime, strftime
15 script_home = abspath(dirname(sys.argv[0] or '.'))
16 sys.path[:0] = [abspath(script_home + '/../lib'), abspath(script_home + '/..')]
18 bup_cmd = top + '/bup'
20 from buptest import ex, exo, logcmd, test_tempdir
21 from wvtest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
23 from bup.helpers import unlink as unlink_if_exists
25 def bup(*args, **kwargs):
26 if 'stdout' not in kwargs:
27 return exo((bup_cmd,) + args, **kwargs)
28 return ex((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 bup('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', stderr=PIPE).err)
66 wvpasseq('/\n', bup('ftp', input='pwd\n').out)
67 wvpasseq('', bup('ftp', input='cd src\n').out)
68 wvpasseq('/src\n', bup('ftp', input=jl('cd src', 'pwd')).out)
69 wvpasseq('/src\n/\n', bup('ftp', input=jl('cd src', 'pwd',
71 wvpasseq('/src\n/\n', bup('ftp', input=jl('cd src', 'pwd',
72 'cd ..', 'cd ..', 'pwd')).out)
73 wvpasseq('/src/%s/dir\n' % save_name,
74 bup('ftp', input=jl('cd src/latest/dir-symlink', 'pwd')).out)
75 wvpasseq('/src/%s/dir\n' % save_name,
76 bup('ftp', input=jl('cd src latest dir-symlink', 'pwd')).out)
77 wvpassne(0, bup('ftp',
78 input=jl('cd src/latest/bad-symlink', 'pwd'),
79 check=False, stdout=None).rc)
80 wvpassne(0, bup('ftp',
81 input=jl('cd src/latest/not-there', 'pwd'),
82 check=False, stdout=None).rc)
86 wvpasseq('src\n', bup('ftp', input='ls\n').out)
87 wvpasseq(save_name + '\nlatest\n',
88 bup('ftp', input='ls src\n').out)
91 wvpasseq('excitement!\n',
92 bup('ftp', input='cat src/latest/file-1\n').out)
93 wvpasseq('excitement!\nmore excitement!\n',
95 input='cat src/latest/file-1 src/latest/dir/file-2\n').out)
98 bup('ftp', input=jl('get src/latest/file-1 dest'))
99 with open('dest', 'rb') as f:
100 wvpasseq('excitement!\n', f.read())
102 bup('ftp', input=jl('get src/latest/file-symlink dest'))
103 with open('dest', 'rb') as f:
104 wvpasseq('excitement!\n', f.read())
106 wvpassne(0, bup('ftp',
107 input=jl('get src/latest/bad-symlink dest'),
108 check=False, stdout=None).rc)
109 wvpassne(0, bup('ftp',
110 input=jl('get src/latest/not-there'),
111 check=False, stdout=None).rc)
114 unlink_if_exists('file-1')
115 bup('ftp', input=jl('mget src/latest/file-1'))
116 with open('file-1', 'rb') as f:
117 wvpasseq('excitement!\n', f.read())
118 unlink_if_exists('file-1')
119 unlink_if_exists('file-2')
120 bup('ftp', input=jl('mget src/latest/file-1 src/latest/dir/file-2'))
121 with open('file-1', 'rb') as f:
122 wvpasseq('excitement!\n', f.read())
123 with open('file-2', 'rb') as f:
124 wvpasseq('more excitement!\n', f.read())
125 unlink_if_exists('file-symlink')
126 bup('ftp', input=jl('mget src/latest/file-symlink'))
127 with open('file-symlink', 'rb') as f:
128 wvpasseq('excitement!\n', f.read())
129 wvpassne(0, bup('ftp',
130 input=jl('mget src/latest/bad-symlink dest'),
131 check=False, stdout=None).rc)
132 # bup mget currently always does pattern matching
133 bup('ftp', input='mget src/latest/not-there\n')