git @ Cat's Eye Technologies ellsync / 150ee6a
Fix traverse_directories, refactor, actually shell out to diff Chris Pressey 1 year, 3 months ago
2 changed file(s) with 28 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
3232 for line in p.stdout:
3333 sys.stdout.write(decode_line(line))
3434 sys.stdout.flush()
35 p.wait()
36
37
38 def traverse_directories(f, dirname):
39 for filename in sorted(os.listdir(dirname)):
40 fullname = os.path.join(dirname, filename)
41 if os.path.islink(fullname):
42 f.write(fullname + "\n")
43 elif os.path.isdir(fullname):
44 _traverse(fullname)
35 return p.wait()
36
37
38 def traverse_directories(f, basedir, dirname):
39 fulldirname = os.path.join(basedir, dirname)
40 for filename in sorted(os.listdir(fulldirname)):
41 subname = os.path.join(dirname, filename)
42 fullname = os.path.join(fulldirname, filename)
43 if os.path.isdir(fullname) and not os.path.islink(fullname):
44 traverse_directories(f, basedir, subname)
4545 else:
46 f.write(fullname + "\n")
46 f.write(subname + "\n")
4747
4848
4949 def obtain_dirs_for_stream(router, stream_name):
155155 if not os.path.isfile(manifest_filename):
156156 print("Cannot read {}, creating it".format(manifest_filename))
157157 with open(manifest_filename, "w") as f:
158 traverse_directories(f, from_dir)
158 traverse_directories(f, from_dir, '')
159159
160160 print("Traversing manifest {}".format(manifest_filename))
161161
163163 for line in f:
164164 path = line.strip()
165165
166 if not active and path == options.continue_from:
167 print("Found {}, resuming verify".format(options.continue_from))
168 active = True
166 from_path = os.path.join(from_dir, path)
167 to_path = os.path.join(to_dir, path)
168
169 assert not os.path.isdir(from_path)
170
169171 if not active:
170 continue
171 if os.path.isdir(path):
172 continue
173
174 # execute diff --brief --new-file "$F" "$TARGET$F"
175 diffs = False
176 if diffs:
177 print("!!!", path)
178 else:
179 print(path)
172 if path == options.continue_from:
173 print("Found {}, resuming verify".format(options.continue_from))
174 active = True
175 else:
176 continue
177
178 exit_code = run_command(['diff', '--brief', '--new-file', from_path, to_path])
179 print("[OK]" if exit_code == 0 else "[!!]", path)
180180
181181
182182 # - - - - driver - - - -
171171 self.assertEqual(lines, [
172172 'Cannot read /tmp/ellsync-manifest-basic.lst, creating it',
173173 'Traversing manifest /tmp/ellsync-manifest-basic.lst',
174 'canonical/thing',
174 'diff --brief --new-file canonical/thing cache/thing',
175 '[OK] thing',
175176 ''
176177 ])
177178
181182 with open('/tmp/foo.lst', 'r') as f:
182183 contents = f.read()
183184 self.assertEqual(contents, """\
184 canonical/thing
185 thing
185186 """)
186187
187188 def test_rename(self):