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