Show More
@@ -149,10 +149,24 b' class FileLinks(FileLink):' | |||||
149 | information on additional parameters. |
|
149 | information on additional parameters. | |
150 |
|
150 | |||
151 | notebook_display_formatter : func passed to os.path.walk when |
|
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 | terminal_display_formatter : func passed to os.path.walk when |
|
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 | self.included_suffixes = included_suffixes |
|
172 | self.included_suffixes = included_suffixes | |
@@ -188,10 +202,7 b' class FileLinks(FileLink):' | |||||
188 | exactly two "%s" and the dirname will be subsituted for the first |
|
202 | exactly two "%s" and the dirname will be subsituted for the first | |
189 | and fname will be substituted for the second |
|
203 | and fname will be substituted for the second | |
190 | """ |
|
204 | """ | |
191 |
|
205 | def f(dirname, fnames, included_suffixes=None): | ||
192 | included_suffixes = self.included_suffixes |
|
|||
193 |
|
||||
194 | def f(dirname, fnames): |
|
|||
195 | result = [] |
|
206 | result = [] | |
196 | # begin by figuring out which filenames, if any, |
|
207 | # begin by figuring out which filenames, if any, | |
197 | # are going to be displayed |
|
208 | # are going to be displayed | |
@@ -225,7 +236,7 b' class FileLinks(FileLink):' | |||||
225 |
|
236 | |||
226 | def _get_notebook_display_formatter(self, |
|
237 | def _get_notebook_display_formatter(self, | |
227 | spacer=" "): |
|
238 | spacer=" "): | |
228 |
""" generate func |
|
239 | """ generate function to use for notebook formatting | |
229 | """ |
|
240 | """ | |
230 | dirname_output_format = \ |
|
241 | dirname_output_format = \ | |
231 | self.result_html_prefix + "%s/" + self.result_html_suffix |
|
242 | self.result_html_prefix + "%s/" + self.result_html_suffix | |
@@ -239,7 +250,7 b' class FileLinks(FileLink):' | |||||
239 |
|
250 | |||
240 | def _get_terminal_display_formatter(self, |
|
251 | def _get_terminal_display_formatter(self, | |
241 | spacer=" "): |
|
252 | spacer=" "): | |
242 |
""" generate func |
|
253 | """ generate function to use for terminal formatting | |
243 | """ |
|
254 | """ | |
244 | dirname_output_format = "%s/" |
|
255 | dirname_output_format = "%s/" | |
245 | fname_output_format = spacer + "%s" |
|
256 | fname_output_format = spacer + "%s" | |
@@ -254,7 +265,7 b' class FileLinks(FileLink):' | |||||
254 | walked_dir = list(walk(self.path)) |
|
265 | walked_dir = list(walk(self.path)) | |
255 | walked_dir.sort() |
|
266 | walked_dir.sort() | |
256 | for dirname, subdirs, fnames in walked_dir: |
|
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 | return '\n'.join(result_lines) |
|
269 | return '\n'.join(result_lines) | |
259 |
|
270 | |||
260 | def __repr__(self): |
|
271 | def __repr__(self): | |
@@ -264,5 +275,5 b' class FileLinks(FileLink):' | |||||
264 | walked_dir = list(walk(self.path)) |
|
275 | walked_dir = list(walk(self.path)) | |
265 | walked_dir.sort() |
|
276 | walked_dir.sort() | |
266 | for dirname, subdirs, fnames in walked_dir: |
|
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 | return '\n'.join(result_lines) |
|
279 | return '\n'.join(result_lines) |
@@ -90,7 +90,7 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(dirname,fnames): |
|
93 | def fake_formatter(dirname,fnames,included_suffixes): | |
94 | return ["hello","world"] |
|
94 | return ["hello","world"] | |
95 | fl = display.FileLinks(td,notebook_display_formatter=fake_formatter) |
|
95 | fl = display.FileLinks(td,notebook_display_formatter=fake_formatter) | |
96 | actual = fl._repr_html_() |
|
96 | actual = fl._repr_html_() | |
@@ -121,7 +121,7 b' def test_existing_path_FileLinks_repr_alt_formatter():' | |||||
121 | td = mkdtemp() |
|
121 | td = mkdtemp() | |
122 | tf1 = NamedTemporaryFile(dir=td) |
|
122 | tf1 = NamedTemporaryFile(dir=td) | |
123 | tf2 = NamedTemporaryFile(dir=td) |
|
123 | tf2 = NamedTemporaryFile(dir=td) | |
124 | def fake_formatter(dirname,fnames): |
|
124 | def fake_formatter(dirname,fnames,included_suffixes): | |
125 | return ["hello","world"] |
|
125 | return ["hello","world"] | |
126 | fl = display.FileLinks(td,terminal_display_formatter=fake_formatter) |
|
126 | fl = display.FileLinks(td,terminal_display_formatter=fake_formatter) | |
127 | actual = repr(fl) |
|
127 | actual = repr(fl) |
General Comments 0
You need to be logged in to leave comments.
Login now