##// 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 self.included_suffixes = included_suffixes
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 FileLink.__init__(self,
135 FileLink.__init__(self,
146 path,
136 path,
147 url_prefix,
137 url_prefix,
148 result_html_prefix,
138 result_html_prefix,
149 result_html_suffix)
139 result_html_suffix)
150
140
151 def _get_notebook_display_formatter(self,
141 self.notebook_display_formatter = \
152 url_prefix,
142 self._get_notebook_display_formatter()
153 result_html_prefix,
143 self.terminal_display_formatter = \
154 result_html_suffix,
144 self._get_terminal_display_formatter()
155 included_suffixes):
145
156 """ """
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 def f(output_lines, dirname, fnames):
153 def f(output_lines, dirname, fnames):
158 """ """
154 """ """
159 # begin by figuring out which filenames, if any,
155 # begin by figuring out which filenames, if any,
@@ -168,44 +164,43 b' class FileLinks(FileLink):'
168 if len(display_fnames) == 0:
164 if len(display_fnames) == 0:
169 pass
165 pass
170 else:
166 else:
171 output_lines.append(''.join([result_html_prefix,
167 dirname_output_line = dirname_output_format % dirname
172 dirname,
168 output_lines.append(dirname_output_line)
173 result_html_suffix]))
174 for fname in display_fnames:
169 for fname in display_fnames:
175 fp = ''.join([self.url_prefix,dirname,'/',fname])
170 fp = fp_format % (dirname,fname)
176 output_lines.append(''.join([self.result_html_prefix,
171 try:
177 '  ',
172 # output can include both a filepath and a filename...
178 self.html_link_str % (fp,fname),
173 fname_output_line = fname_output_format % (fp, fname)
179 self.result_html_suffix]))
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 return
178 return
181 return f
179 return f
182
180
183 def _get_terminal_display_formatter(self,
181 def _get_notebook_display_formatter(self,
184 url_prefix,
182 spacer="  "):
185 result_html_prefix,
186 result_html_suffix,
187 included_suffixes):
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,
197 dirname_output_format = "%s"
192 # are going to be displayed
198 fname_output_format = spacer + "%s"
193 display_fnames = []
199 fp_format = '%s/%s'
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)
199
200
200 if len(display_fnames) == 0:
201 return self._get_display_formatter(dirname_output_format,
201 pass
202 fname_output_format,
202 else:
203 fp_format)
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
209
204
210 def _format_path(self):
205 def _format_path(self):
211 result_lines = []
206 result_lines = []
General Comments 0
You need to be logged in to leave comments. Login now