##// 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)
140
141 self.notebook_display_formatter = \
142 self._get_notebook_display_formatter()
143 self.terminal_display_formatter = \
144 self._get_terminal_display_formatter()
150
145
151 def _get_notebook_display_formatter(self,
146 def _get_display_formatter(self,
152 url_prefix,
147 dirname_output_format,
153 result_html_prefix,
148 fname_output_format,
154 result_html_suffix,
149 fp_format):
155 included_suffixes):
150
156 """ """
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,
@@ -164,48 +160,47 b' class FileLinks(FileLink):'
164 (included_suffixes == None or
160 (included_suffixes == None or
165 splitext(fname)[1] in included_suffixes)):
161 splitext(fname)[1] in included_suffixes)):
166 display_fnames.append(fname)
162 display_fnames.append(fname)
167
163
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 = \
190 """ """
185 self.result_html_prefix + "%s" + self.result_html_suffix
191 # begin by figuring out which filenames, if any,
186 fname_output_format = \
192 # are going to be displayed
187 self.result_html_prefix + spacer + self.html_link_str + self.result_html_suffix
193 display_fnames = []
188 fp_format = self.url_prefix + '%s/%s'
194 for fname in fnames:
189
195 if (isfile(join(dirname,fname)) and
190 return self._get_display_formatter(dirname_output_format,
196 (included_suffixes == None or
191 fname_output_format,
197 splitext(fname)[1] in included_suffixes)):
192 fp_format)
198 display_fnames.append(fname)
199
193
200 if len(display_fnames) == 0:
194 def _get_terminal_display_formatter(self,
201 pass
195 spacer=" "):
202 else:
196 """ """
203 output_lines.append(dirname)
197 dirname_output_format = "%s"
204 for fname in display_fnames:
198 fname_output_format = spacer + "%s"
205 fp = abspath(join(dirname,fname))
199 fp_format = '%s/%s'
206 output_lines.append(' %s' % fp)
200
207 return
201 return self._get_display_formatter(dirname_output_format,
208 return f
202 fname_output_format,
203 fp_format)
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