Show More
@@ -173,7 +173,8 b' class FileLinks(FileLink):' | |||
|
173 | 173 | dirname_output_format, |
|
174 | 174 | fname_output_format, |
|
175 | 175 | fp_format): |
|
176 | """ generate func to pass to os.path.walk | |
|
176 | """ generate function to format output- the resulting function will | |
|
177 | take a list to be populated with the output lines to print, | |
|
177 | 178 | |
|
178 | 179 | dirname_output_format: string to use for formatting directory |
|
179 | 180 | names, dirname will be substituted for a single "%s" which |
@@ -190,8 +191,8 b' class FileLinks(FileLink):' | |||
|
190 | 191 | |
|
191 | 192 | included_suffixes = self.included_suffixes |
|
192 | 193 | |
|
193 |
def f( |
|
|
194 | """ func to be passed to os.path.walk """ | |
|
194 | def f(dirname, fnames): | |
|
195 | result = [] | |
|
195 | 196 | # begin by figuring out which filenames, if any, |
|
196 | 197 | # are going to be displayed |
|
197 | 198 | display_fnames = [] |
@@ -209,7 +210,7 b' class FileLinks(FileLink):' | |||
|
209 | 210 | # otherwise print the formatted directory name followed by |
|
210 | 211 | # the formatted filenames |
|
211 | 212 | dirname_output_line = dirname_output_format % dirname |
|
212 |
|
|
|
213 | result.append(dirname_output_line) | |
|
213 | 214 | for fname in display_fnames: |
|
214 | 215 | fp = fp_format % (dirname,fname) |
|
215 | 216 | try: |
@@ -218,8 +219,8 b' class FileLinks(FileLink):' | |||
|
218 | 219 | except TypeError: |
|
219 | 220 | # ... or just a single filepath |
|
220 | 221 | fname_output_line = fname_output_format % fname |
|
221 |
|
|
|
222 | return | |
|
222 | result.append(fname_output_line) | |
|
223 | return result | |
|
223 | 224 | return f |
|
224 | 225 | |
|
225 | 226 | def _get_notebook_display_formatter(self, |
@@ -253,7 +254,7 b' class FileLinks(FileLink):' | |||
|
253 | 254 | walked_dir = list(walk(self.path)) |
|
254 | 255 | walked_dir.sort() |
|
255 | 256 | for dirname, subdirs, fnames in walked_dir: |
|
256 |
self.notebook_display_formatter( |
|
|
257 | result_lines += self.notebook_display_formatter(dirname, fnames) | |
|
257 | 258 | return '\n'.join(result_lines) |
|
258 | 259 | |
|
259 | 260 | def __repr__(self): |
@@ -263,5 +264,5 b' class FileLinks(FileLink):' | |||
|
263 | 264 | walked_dir = list(walk(self.path)) |
|
264 | 265 | walked_dir.sort() |
|
265 | 266 | for dirname, subdirs, fnames in walked_dir: |
|
266 |
self.terminal_display_formatter( |
|
|
267 | result_lines += self.terminal_display_formatter(dirname, fnames) | |
|
267 | 268 | return '\n'.join(result_lines) |
@@ -90,9 +90,8 b' def test_existing_path_FileLinks_alt_formatter():' | |||
|
90 | 90 | td = mkdtemp() |
|
91 | 91 | tf1 = NamedTemporaryFile(dir=td) |
|
92 | 92 | tf2 = NamedTemporaryFile(dir=td) |
|
93 |
def fake_formatter( |
|
|
94 |
|
|
|
95 | return | |
|
93 | def fake_formatter(dirname,fnames): | |
|
94 | return ["hello","world"] | |
|
96 | 95 | fl = display.FileLinks(td,notebook_display_formatter=fake_formatter) |
|
97 | 96 | actual = fl._repr_html_() |
|
98 | 97 | actual = actual.split('\n') |
@@ -122,9 +121,8 b' def test_existing_path_FileLinks_repr_alt_formatter():' | |||
|
122 | 121 | td = mkdtemp() |
|
123 | 122 | tf1 = NamedTemporaryFile(dir=td) |
|
124 | 123 | tf2 = NamedTemporaryFile(dir=td) |
|
125 |
def fake_formatter( |
|
|
126 |
|
|
|
127 | return | |
|
124 | def fake_formatter(dirname,fnames): | |
|
125 | return ["hello","world"] | |
|
128 | 126 | fl = display.FileLinks(td,terminal_display_formatter=fake_formatter) |
|
129 | 127 | actual = repr(fl) |
|
130 | 128 | actual = actual.split('\n') |
General Comments 0
You need to be logged in to leave comments.
Login now