##// END OF EJS Templates
Merge pull request #7090 from dsblank/master...
Min RK -
r19375:1a89b81d merge
parent child Browse files
Show More
@@ -368,7 +368,8 b' class FileLinks(FileLink):'
368 result_html_prefix='',
368 result_html_prefix='',
369 result_html_suffix='<br>',
369 result_html_suffix='<br>',
370 notebook_display_formatter=None,
370 notebook_display_formatter=None,
371 terminal_display_formatter=None):
371 terminal_display_formatter=None,
372 recursive=True):
372 """
373 """
373 See :class:`FileLink` for the ``path``, ``url_prefix``,
374 See :class:`FileLink` for the ``path``, ``url_prefix``,
374 ``result_html_prefix`` and ``result_html_suffix`` parameters.
375 ``result_html_prefix`` and ``result_html_suffix`` parameters.
@@ -396,6 +397,8 b' class FileLinks(FileLink):'
396 included_suffixes : list
397 included_suffixes : list
397 The file suffixes that should be included in the output (passing None
398 The file suffixes that should be included in the output (passing None
398 meansto include all suffixes in the output in the built-in formatters)
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 The function should return a list of lines that will be printed in the
403 The function should return a list of lines that will be printed in the
401 notebook (if passing notebook_display_formatter) or the terminal (if
404 notebook (if passing notebook_display_formatter) or the terminal (if
@@ -421,6 +424,8 b' class FileLinks(FileLink):'
421 self.terminal_display_formatter = \
424 self.terminal_display_formatter = \
422 terminal_display_formatter or self._get_terminal_display_formatter()
425 terminal_display_formatter or self._get_terminal_display_formatter()
423
426
427 self.recursive = recursive
428
424 def _get_display_formatter(self,
429 def _get_display_formatter(self,
425 dirname_output_format,
430 dirname_output_format,
426 fname_output_format,
431 fname_output_format,
@@ -516,7 +521,10 b' class FileLinks(FileLink):'
516
521
517 def _format_path(self):
522 def _format_path(self):
518 result_lines = []
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 walked_dir.sort()
528 walked_dir.sort()
521 for dirname, subdirs, fnames in walked_dir:
529 for dirname, subdirs, fnames in walked_dir:
522 result_lines += self.notebook_display_formatter(dirname, fnames, self.included_suffixes)
530 result_lines += self.notebook_display_formatter(dirname, fnames, self.included_suffixes)
@@ -526,7 +534,10 b' class FileLinks(FileLink):'
526 """return newline-separated absolute paths
534 """return newline-separated absolute paths
527 """
535 """
528 result_lines = []
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 walked_dir.sort()
541 walked_dir.sort()
531 for dirname, subdirs, fnames in walked_dir:
542 for dirname, subdirs, fnames in walked_dir:
532 result_lines += self.terminal_display_formatter(dirname, fnames, self.included_suffixes)
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 tf1 = NamedTemporaryFile(dir=td)
156 tf1 = NamedTemporaryFile(dir=td)
157 nt.assert_raises(ValueError,display.FileLinks,tf1.name)
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 @skipif_not_numpy
175 @skipif_not_numpy
160 def test_audio_from_file():
176 def test_audio_from_file():
161 path = pjoin(dirname(__file__), 'test.wav')
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