Show More
@@ -368,7 +368,8 b' class FileLinks(FileLink):' | |||
|
368 | 368 | result_html_prefix='', |
|
369 | 369 | result_html_suffix='<br>', |
|
370 | 370 | notebook_display_formatter=None, |
|
371 |
terminal_display_formatter=None |
|
|
371 | terminal_display_formatter=None, | |
|
372 | recursive=True): | |
|
372 | 373 | """ |
|
373 | 374 | See :class:`FileLink` for the ``path``, ``url_prefix``, |
|
374 | 375 | ``result_html_prefix`` and ``result_html_suffix`` parameters. |
@@ -396,6 +397,8 b' class FileLinks(FileLink):' | |||
|
396 | 397 | included_suffixes : list |
|
397 | 398 | The file suffixes that should be included in the output (passing None |
|
398 | 399 | meansto include all suffixes in the output in the built-in formatters) |
|
400 | recursive : boolean | |
|
401 | Whether to recurse into subdirectories. Default is True. | |
|
399 | 402 | |
|
400 | 403 | The function should return a list of lines that will be printed in the |
|
401 | 404 | notebook (if passing notebook_display_formatter) or the terminal (if |
@@ -421,6 +424,8 b' class FileLinks(FileLink):' | |||
|
421 | 424 | self.terminal_display_formatter = \ |
|
422 | 425 | terminal_display_formatter or self._get_terminal_display_formatter() |
|
423 | 426 | |
|
427 | self.recursive = recursive | |
|
428 | ||
|
424 | 429 | def _get_display_formatter(self, |
|
425 | 430 | dirname_output_format, |
|
426 | 431 | fname_output_format, |
@@ -516,7 +521,10 b' class FileLinks(FileLink):' | |||
|
516 | 521 | |
|
517 | 522 | def _format_path(self): |
|
518 | 523 | result_lines = [] |
|
519 | walked_dir = list(walk(self.path)) | |
|
524 | if self.recursive: | |
|
525 | walked_dir = list(walk(self.path)) | |
|
526 | else: | |
|
527 | walked_dir = [next(walk(self.path))] | |
|
520 | 528 | walked_dir.sort() |
|
521 | 529 | for dirname, subdirs, fnames in walked_dir: |
|
522 | 530 | result_lines += self.notebook_display_formatter(dirname, fnames, self.included_suffixes) |
@@ -526,7 +534,10 b' class FileLinks(FileLink):' | |||
|
526 | 534 | """return newline-separated absolute paths |
|
527 | 535 | """ |
|
528 | 536 | result_lines = [] |
|
529 | walked_dir = list(walk(self.path)) | |
|
537 | if self.recursive: | |
|
538 | walked_dir = list(walk(self.path)) | |
|
539 | else: | |
|
540 | walked_dir = [next(walk(self.path))] | |
|
530 | 541 | walked_dir.sort() |
|
531 | 542 | for dirname, subdirs, fnames in walked_dir: |
|
532 | 543 | result_lines += self.terminal_display_formatter(dirname, fnames, self.included_suffixes) |
@@ -156,7 +156,23 b' def test_error_on_file_to_FileLinks():' | |||
|
156 | 156 | tf1 = NamedTemporaryFile(dir=td) |
|
157 | 157 | nt.assert_raises(ValueError,display.FileLinks,tf1.name) |
|
158 | 158 | |
|
159 | def test_recursive_FileLinks(): | |
|
160 | """FileLinks: Does not recurse when recursive=False | |
|
161 | """ | |
|
162 | td = mkdtemp() | |
|
163 | tf = NamedTemporaryFile(dir=td) | |
|
164 | subtd = mkdtemp(dir=td) | |
|
165 | subtf = NamedTemporaryFile(dir=subtd) | |
|
166 | fl = display.FileLinks(td) | |
|
167 | actual = str(fl) | |
|
168 | actual = actual.split('\n') | |
|
169 | nt.assert_equal(len(actual), 4, actual) | |
|
170 | fl = display.FileLinks(td, recursive=False) | |
|
171 | actual = str(fl) | |
|
172 | actual = actual.split('\n') | |
|
173 | nt.assert_equal(len(actual), 2, actual) | |
|
174 | ||
|
159 | 175 | @skipif_not_numpy |
|
160 | 176 | def test_audio_from_file(): |
|
161 | 177 | path = pjoin(dirname(__file__), 'test.wav') |
|
162 | display.Audio(filename=path) No newline at end of file | |
|
178 | display.Audio(filename=path) |
General Comments 0
You need to be logged in to leave comments.
Login now