##// END OF EJS Templates
cleaned up to reduce duplicated code
Greg Caporaso -
Show More
@@ -132,28 +132,24 b' class FileLinks(FileLink):'
132 132 """
133 133 self.included_suffixes = included_suffixes
134 134
135 self.notebook_display_formatter = \
136 self._get_notebook_display_formatter(url_prefix,
137 result_html_prefix,
138 result_html_suffix,
139 included_suffixes)
140 self.terminal_display_formatter = \
141 self._get_terminal_display_formatter(url_prefix,
142 result_html_prefix,
143 result_html_suffix,
144 included_suffixes)
145 135 FileLink.__init__(self,
146 136 path,
147 137 url_prefix,
148 138 result_html_prefix,
149 139 result_html_suffix)
150 140
151 def _get_notebook_display_formatter(self,
152 url_prefix,
153 result_html_prefix,
154 result_html_suffix,
155 included_suffixes):
156 """ """
141 self.notebook_display_formatter = \
142 self._get_notebook_display_formatter()
143 self.terminal_display_formatter = \
144 self._get_terminal_display_formatter()
145
146 def _get_display_formatter(self,
147 dirname_output_format,
148 fname_output_format,
149 fp_format):
150
151 included_suffixes = self.included_suffixes
152
157 153 def f(output_lines, dirname, fnames):
158 154 """ """
159 155 # begin by figuring out which filenames, if any,
@@ -168,44 +164,43 b' class FileLinks(FileLink):'
168 164 if len(display_fnames) == 0:
169 165 pass
170 166 else:
171 output_lines.append(''.join([result_html_prefix,
172 dirname,
173 result_html_suffix]))
167 dirname_output_line = dirname_output_format % dirname
168 output_lines.append(dirname_output_line)
174 169 for fname in display_fnames:
175 fp = ''.join([self.url_prefix,dirname,'/',fname])
176 output_lines.append(''.join([self.result_html_prefix,
177 '  ',
178 self.html_link_str % (fp,fname),
179 self.result_html_suffix]))
170 fp = fp_format % (dirname,fname)
171 try:
172 # output can include both a filepath and a filename...
173 fname_output_line = fname_output_format % (fp, fname)
174 except TypeError:
175 # ... or just a single filepath
176 fname_output_line = fname_output_format % fname
177 output_lines.append(fname_output_line)
180 178 return
181 179 return f
182 180
183 def _get_terminal_display_formatter(self,
184 url_prefix,
185 result_html_prefix,
186 result_html_suffix,
187 included_suffixes):
181 def _get_notebook_display_formatter(self,
182 spacer="  "):
188 183 """ """
189 def f(output_lines, dirname, fnames):
184 dirname_output_format = \
185 self.result_html_prefix + "%s" + self.result_html_suffix
186 fname_output_format = \
187 self.result_html_prefix + spacer + self.html_link_str + self.result_html_suffix
188 fp_format = self.url_prefix + '%s/%s'
189
190 return self._get_display_formatter(dirname_output_format,
191 fname_output_format,
192 fp_format)
193
194 def _get_terminal_display_formatter(self,
195 spacer=" "):
190 196 """ """
191 # begin by figuring out which filenames, if any,
192 # are going to be displayed
193 display_fnames = []
194 for fname in fnames:
195 if (isfile(join(dirname,fname)) and
196 (included_suffixes == None or
197 splitext(fname)[1] in included_suffixes)):
198 display_fnames.append(fname)
197 dirname_output_format = "%s"
198 fname_output_format = spacer + "%s"
199 fp_format = '%s/%s'
199 200
200 if len(display_fnames) == 0:
201 pass
202 else:
203 output_lines.append(dirname)
204 for fname in display_fnames:
205 fp = abspath(join(dirname,fname))
206 output_lines.append(' %s' % fp)
207 return
208 return f
201 return self._get_display_formatter(dirname_output_format,
202 fname_output_format,
203 fp_format)
209 204
210 205 def _format_path(self):
211 206 result_lines = []
General Comments 0
You need to be logged in to leave comments. Login now