##// END OF EJS Templates
added included_suffixes as an option to display formatters - previously it wasn't possible to pass these in if defining custom display formatters
Greg Caporaso -
Show More
@@ -149,10 +149,24 b' class FileLinks(FileLink):'
149 149 information on additional parameters.
150 150
151 151 notebook_display_formatter : func passed to os.path.walk when
152 formatting links for display in the notebook
152 formatting links for display in the notebook. This function
153 should be of the form: f(dirname, fnames) where dirname is the
154 name of a directory (a string) and fnames is a list of the
155 files in that directory (not including subdirectories) and
156 returns a list of lines that should be used to print that text
157 in the notebook. This function is iterated over for each
158 directory in self.path. A default formatter is in place, but
159 a function can be passed to support alternative formatting.
153 160
154 161 terminal_display_formatter : func passed to os.path.walk when
155 formatting links for display in the terminal
162 formatting links for display in the terminal. This function
163 should be of the form: f(dirname, fnames) where dirname is the
164 name of a directory (a string) and fnames is a list of the
165 files in that directory (not including subdirectories) and
166 returns a list of lines that should be used to print that text
167 in the terminal. This function is iterated over for each
168 directory in self.path. A default formatter is in place, but
169 a function can be passed to support alternative formatting.
156 170
157 171 """
158 172 self.included_suffixes = included_suffixes
@@ -188,10 +202,7 b' class FileLinks(FileLink):'
188 202 exactly two "%s" and the dirname will be subsituted for the first
189 203 and fname will be substituted for the second
190 204 """
191
192 included_suffixes = self.included_suffixes
193
194 def f(dirname, fnames):
205 def f(dirname, fnames, included_suffixes=None):
195 206 result = []
196 207 # begin by figuring out which filenames, if any,
197 208 # are going to be displayed
@@ -225,7 +236,7 b' class FileLinks(FileLink):'
225 236
226 237 def _get_notebook_display_formatter(self,
227 238 spacer="  "):
228 """ generate func to pass to os.path.walk for notebook formatting
239 """ generate function to use for notebook formatting
229 240 """
230 241 dirname_output_format = \
231 242 self.result_html_prefix + "%s/" + self.result_html_suffix
@@ -239,7 +250,7 b' class FileLinks(FileLink):'
239 250
240 251 def _get_terminal_display_formatter(self,
241 252 spacer=" "):
242 """ generate func to pass to os.path.walk for terminal formatting
253 """ generate function to use for terminal formatting
243 254 """
244 255 dirname_output_format = "%s/"
245 256 fname_output_format = spacer + "%s"
@@ -254,7 +265,7 b' class FileLinks(FileLink):'
254 265 walked_dir = list(walk(self.path))
255 266 walked_dir.sort()
256 267 for dirname, subdirs, fnames in walked_dir:
257 result_lines += self.notebook_display_formatter(dirname, fnames)
268 result_lines += self.notebook_display_formatter(dirname, fnames, self.included_suffixes)
258 269 return '\n'.join(result_lines)
259 270
260 271 def __repr__(self):
@@ -264,5 +275,5 b' class FileLinks(FileLink):'
264 275 walked_dir = list(walk(self.path))
265 276 walked_dir.sort()
266 277 for dirname, subdirs, fnames in walked_dir:
267 result_lines += self.terminal_display_formatter(dirname, fnames)
278 result_lines += self.terminal_display_formatter(dirname, fnames, self.included_suffixes)
268 279 return '\n'.join(result_lines)
@@ -90,7 +90,7 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(dirname,fnames):
93 def fake_formatter(dirname,fnames,included_suffixes):
94 94 return ["hello","world"]
95 95 fl = display.FileLinks(td,notebook_display_formatter=fake_formatter)
96 96 actual = fl._repr_html_()
@@ -121,7 +121,7 b' def test_existing_path_FileLinks_repr_alt_formatter():'
121 121 td = mkdtemp()
122 122 tf1 = NamedTemporaryFile(dir=td)
123 123 tf2 = NamedTemporaryFile(dir=td)
124 def fake_formatter(dirname,fnames):
124 def fake_formatter(dirname,fnames,included_suffixes):
125 125 return ["hello","world"]
126 126 fl = display.FileLinks(td,terminal_display_formatter=fake_formatter)
127 127 actual = repr(fl)
General Comments 0
You need to be logged in to leave comments. Login now