Show More
@@ -130,9 +130,16 b' class FileLinks(FileLink):' | |||||
130 | See the FileLink (baseclass of LocalDirectory) docstring for |
|
130 | See the FileLink (baseclass of LocalDirectory) docstring for | |
131 | information on additional parameters. |
|
131 | information on additional parameters. | |
132 |
|
132 | |||
|
133 | notebook_display_formatter : func passed to os.path.walk when | |||
|
134 | formatting links for display in the notebook | |||
|
135 | ||||
|
136 | terminal_display_formatter : func passed to os.path.walk when | |||
|
137 | formatting links for display in the terminal | |||
|
138 | ||||
133 | """ |
|
139 | """ | |
134 | self.included_suffixes = included_suffixes |
|
140 | self.included_suffixes = included_suffixes | |
135 |
|
141 | # remove trailing slashs for more consistent output formatting | ||
|
142 | path = path.rstrip('/') | |||
136 | FileLink.__init__(self, |
|
143 | FileLink.__init__(self, | |
137 | path, |
|
144 | path, | |
138 | url_prefix, |
|
145 | url_prefix, | |
@@ -148,11 +155,25 b' class FileLinks(FileLink):' | |||||
148 | dirname_output_format, |
|
155 | dirname_output_format, | |
149 | fname_output_format, |
|
156 | fname_output_format, | |
150 | fp_format): |
|
157 | fp_format): | |
|
158 | """ generate func to pass to os.path.walk | |||
|
159 | ||||
|
160 | dirname_output_format: string to use for formatting directory | |||
|
161 | names, dirname will be substituted for a single "%s" which | |||
|
162 | must appear in this string | |||
|
163 | fname_output_format: string to use for formatting file names, | |||
|
164 | if a single "%s" appears in the string, fname will be substituted | |||
|
165 | if two "%s" appear in the string, the path to fname will be | |||
|
166 | substituted for the first and fname will be substituted for the | |||
|
167 | second | |||
|
168 | fp_format: string to use for formatting filepaths, must contain | |||
|
169 | exactly two "%s" and the dirname will be subsituted for the first | |||
|
170 | and fname will be substituted for the second | |||
|
171 | """ | |||
151 |
|
172 | |||
152 | included_suffixes = self.included_suffixes |
|
173 | included_suffixes = self.included_suffixes | |
153 |
|
174 | |||
154 | def f(output_lines, dirname, fnames): |
|
175 | def f(output_lines, dirname, fnames): | |
155 | """ """ |
|
176 | """ func to be passed to os.path.walk """ | |
156 | # begin by figuring out which filenames, if any, |
|
177 | # begin by figuring out which filenames, if any, | |
157 | # are going to be displayed |
|
178 | # are going to be displayed | |
158 | display_fnames = [] |
|
179 | display_fnames = [] | |
@@ -163,8 +184,12 b' class FileLinks(FileLink):' | |||||
163 | display_fnames.append(fname) |
|
184 | display_fnames.append(fname) | |
164 |
|
185 | |||
165 | if len(display_fnames) == 0: |
|
186 | if len(display_fnames) == 0: | |
|
187 | # if there are no filenames to display, don't print anything | |||
|
188 | # (not even the directory name) | |||
166 | pass |
|
189 | pass | |
167 | else: |
|
190 | else: | |
|
191 | # otherwise print the formatted directory name followed by | |||
|
192 | # the formatted filenames | |||
168 | dirname_output_line = dirname_output_format % dirname |
|
193 | dirname_output_line = dirname_output_format % dirname | |
169 | output_lines.append(dirname_output_line) |
|
194 | output_lines.append(dirname_output_line) | |
170 | for fname in display_fnames: |
|
195 | for fname in display_fnames: | |
@@ -181,9 +206,10 b' class FileLinks(FileLink):' | |||||
181 |
|
206 | |||
182 | def _get_notebook_display_formatter(self, |
|
207 | def _get_notebook_display_formatter(self, | |
183 | spacer=" "): |
|
208 | spacer=" "): | |
184 | """ """ |
|
209 | """ generate func to pass to os.path.walk for notebook formatting | |
|
210 | """ | |||
185 | dirname_output_format = \ |
|
211 | dirname_output_format = \ | |
186 | self.result_html_prefix + "%s" + self.result_html_suffix |
|
212 | self.result_html_prefix + "%s/" + self.result_html_suffix | |
187 | fname_output_format = \ |
|
213 | fname_output_format = \ | |
188 | self.result_html_prefix + spacer + self.html_link_str + self.result_html_suffix |
|
214 | self.result_html_prefix + spacer + self.html_link_str + self.result_html_suffix | |
189 | fp_format = self.url_prefix + '%s/%s' |
|
215 | fp_format = self.url_prefix + '%s/%s' | |
@@ -194,8 +220,9 b' class FileLinks(FileLink):' | |||||
194 |
|
220 | |||
195 | def _get_terminal_display_formatter(self, |
|
221 | def _get_terminal_display_formatter(self, | |
196 | spacer=" "): |
|
222 | spacer=" "): | |
197 | """ """ |
|
223 | """ generate func to pass to os.path.walk for terminal formatting | |
198 | dirname_output_format = "%s" |
|
224 | """ | |
|
225 | dirname_output_format = "%s/" | |||
199 | fname_output_format = spacer + "%s" |
|
226 | fname_output_format = spacer + "%s" | |
200 | fp_format = '%s/%s' |
|
227 | fp_format = '%s/%s' | |
201 |
|
228 |
@@ -77,7 +77,7 b' def test_existing_path_FileLinks():' | |||||
77 | actual = fl._repr_html_() |
|
77 | actual = fl._repr_html_() | |
78 | actual = actual.split('\n') |
|
78 | actual = actual.split('\n') | |
79 | actual.sort() |
|
79 | actual.sort() | |
80 | expected = ["%s<br>" % td, |
|
80 | expected = ["%s/<br>" % td, | |
81 | " <a href='files/%s' target='_blank'>%s</a><br>" % (tf2.name,split(tf2.name)[1]), |
|
81 | " <a href='files/%s' target='_blank'>%s</a><br>" % (tf2.name,split(tf2.name)[1]), | |
82 | " <a href='files/%s' target='_blank'>%s</a><br>" % (tf1.name,split(tf1.name)[1])] |
|
82 | " <a href='files/%s' target='_blank'>%s</a><br>" % (tf1.name,split(tf1.name)[1])] | |
83 | expected.sort() |
|
83 | expected.sort() | |
@@ -93,7 +93,7 b' def test_existing_path_FileLinks_repr():' | |||||
93 | actual = repr(fl) |
|
93 | actual = repr(fl) | |
94 | actual = actual.split('\n') |
|
94 | actual = actual.split('\n') | |
95 | actual.sort() |
|
95 | actual.sort() | |
96 | expected = [td, ' %s' % split(tf1.name)[1],' %s' % split(tf2.name)[1]] |
|
96 | expected = ['%s/' % td, ' %s' % split(tf1.name)[1],' %s' % split(tf2.name)[1]] | |
97 | expected.sort() |
|
97 | expected.sort() | |
98 | # We compare the sorted list of links here as that's more reliable |
|
98 | # We compare the sorted list of links here as that's more reliable | |
99 | nt.assert_equal(actual,expected) |
|
99 | nt.assert_equal(actual,expected) |
General Comments 0
You need to be logged in to leave comments.
Login now