##// END OF EJS Templates
noew removes trailing slashes if they are provided in input so the output can be formatted consistently by always appending a trailing slash (which previously could result in two trailing slashes if the input path included a trailing slash)
Greg Caporaso -
Show More
@@ -129,10 +129,17 b' class FileLinks(FileLink):'
129 129
130 130 See the FileLink (baseclass of LocalDirectory) docstring for
131 131 information on additional parameters.
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
132 138
133 139 """
134 140 self.included_suffixes = included_suffixes
135
141 # remove trailing slashs for more consistent output formatting
142 path = path.rstrip('/')
136 143 FileLink.__init__(self,
137 144 path,
138 145 url_prefix,
@@ -148,11 +155,25 b' class FileLinks(FileLink):'
148 155 dirname_output_format,
149 156 fname_output_format,
150 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 173 included_suffixes = self.included_suffixes
153 174
154 175 def f(output_lines, dirname, fnames):
155 """ """
176 """ func to be passed to os.path.walk """
156 177 # begin by figuring out which filenames, if any,
157 178 # are going to be displayed
158 179 display_fnames = []
@@ -163,8 +184,12 b' class FileLinks(FileLink):'
163 184 display_fnames.append(fname)
164 185
165 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 189 pass
167 190 else:
191 # otherwise print the formatted directory name followed by
192 # the formatted filenames
168 193 dirname_output_line = dirname_output_format % dirname
169 194 output_lines.append(dirname_output_line)
170 195 for fname in display_fnames:
@@ -181,9 +206,10 b' class FileLinks(FileLink):'
181 206
182 207 def _get_notebook_display_formatter(self,
183 208 spacer="  "):
184 """ """
209 """ generate func to pass to os.path.walk for notebook formatting
210 """
185 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 213 fname_output_format = \
188 214 self.result_html_prefix + spacer + self.html_link_str + self.result_html_suffix
189 215 fp_format = self.url_prefix + '%s/%s'
@@ -194,8 +220,9 b' class FileLinks(FileLink):'
194 220
195 221 def _get_terminal_display_formatter(self,
196 222 spacer=" "):
197 """ """
198 dirname_output_format = "%s"
223 """ generate func to pass to os.path.walk for terminal formatting
224 """
225 dirname_output_format = "%s/"
199 226 fname_output_format = spacer + "%s"
200 227 fp_format = '%s/%s'
201 228
@@ -77,7 +77,7 b' def test_existing_path_FileLinks():'
77 77 actual = fl._repr_html_()
78 78 actual = actual.split('\n')
79 79 actual.sort()
80 expected = ["%s<br>" % td,
80 expected = ["%s/<br>" % td,
81 81 "&nbsp;&nbsp;<a href='files/%s' target='_blank'>%s</a><br>" % (tf2.name,split(tf2.name)[1]),
82 82 "&nbsp;&nbsp;<a href='files/%s' target='_blank'>%s</a><br>" % (tf1.name,split(tf1.name)[1])]
83 83 expected.sort()
@@ -93,7 +93,7 b' def test_existing_path_FileLinks_repr():'
93 93 actual = repr(fl)
94 94 actual = actual.split('\n')
95 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 97 expected.sort()
98 98 # We compare the sorted list of links here as that's more reliable
99 99 nt.assert_equal(actual,expected)
General Comments 0
You need to be logged in to leave comments. Login now