git @ Cat's Eye Technologies ellsync / 2908dc0
Add --manifest command-line option for ellsync verify. Chris Pressey 1 year, 1 month ago
2 changed file(s) with 36 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
142142 from_dir, to_dir = obtain_dirs_for_stream(router, options.stream_name)
143143
144144 active = False
145 if options.skip_until:
146 print("Skipping until", options.skip_until)
145 if options.continue_from:
146 print("Continuing from", options.continue_from)
147147 else:
148148 active = True
149149
150 manifest = "/tmp/manifest.lst"
151 if not os.path.isfile(manifest):
152 print("Cannot read", manifest)
153 print("Collecting manifest")
154 with open(manifest, "w") as f:
150 if not options.manifest:
151 # TODO get tmpdir for system
152 manifest_filename = "/tmp/ellsync-manifest-{}.lst".format(options.stream_name)
153 else:
154 manifest_filename = options.manifest
155 if not os.path.isfile(manifest_filename):
156 print("Cannot read {}, creating it".format(manifest_filename))
157 with open(manifest_filename, "w") as f:
155158 traverse_directories(f, from_dir)
156159
157 print("Traversing manifest")
158
159 with open(manifest, "r") as f:
160 print("Traversing manifest {}".format(manifest_filename))
161
162 with open(manifest_filename, "r") as f:
160163 for line in f:
161164 path = line.strip()
162 if path == options.skip_until:
165
166 if not active and path == options.continue_from:
167 print("Found {}, resuming verify".format(options.continue_from))
163168 active = True
164
169 if not active:
170 continue
165171 if os.path.isdir(path):
166 continue
167 if not active:
168 print("skipping ", path)
169172 continue
170173
171174 # execute diff --brief --new-file "$F" "$TARGET$F"
217220 parser_verify.add_argument('stream_name', metavar='STREAM', type=str,
218221 help='Name of stream (or stream:subdirectory) to verify across'
219222 )
220 parser_verify.add_argument('--skip-until', default=None, type=str,
221 help='If given, do not start verification until (i.e. continue verification at) this filename'
223 parser_verify.add_argument('--manifest', metavar='FILENAME', default=None, type=str,
224 help='Specify the name of the manifest file to use. If not given, a name derived from '
225 'the name of the stream will be used. If the file does not exist, it will be created.'
226 )
227 parser_verify.add_argument('--continue-from', metavar='FILENAME', default=None, type=str,
228 help='If given, skip over filenames in the manifest until seeing this filename'
222229 )
223230 parser_verify.set_defaults(func=verify)
224231
164164 ])
165165
166166 def test_verify(self):
167 check_call("rm -f /tmp/manifest.lst", shell=True)
167 check_call("rm -f /tmp/ellsync-manifest-basic.lst", shell=True)
168168 main(['backup.json', 'verify', 'basic'])
169169 output = sys.stdout.getvalue()
170170 lines = [l for l in output.split('\n')]
171171 self.assertEqual(lines, [
172 'Cannot read /tmp/manifest.lst',
173 'Collecting manifest',
174 'Traversing manifest',
172 'Cannot read /tmp/ellsync-manifest-basic.lst, creating it',
173 'Traversing manifest /tmp/ellsync-manifest-basic.lst',
175174 'canonical/thing',
176175 ''
177176 ])
177
178 def test_verify_manifest(self):
179 check_call("rm -f /tmp/foo.lst", shell=True)
180 main(['backup.json', 'verify', 'basic', '--manifest', '/tmp/foo.lst'])
181 with open('/tmp/foo.lst', 'r') as f:
182 contents = f.read()
183 self.assertEqual(contents, """\
184 canonical/thing
185 """)
178186
179187 def test_rename(self):
180188 check_call("mkdir -p canonical/sclupture", shell=True)