162 self.file_summaries = [] |
162 self.file_summaries = [] |
163 self.all_files_nums = [] |
163 self.all_files_nums = [] |
164 self.incr = IncrementalChecker(self.directory) |
164 self.incr = IncrementalChecker(self.directory) |
165 self.datagen = HtmlDataGeneration(self.coverage) |
165 self.datagen = HtmlDataGeneration(self.coverage) |
166 self.totals = Numbers(precision=self.config.precision) |
166 self.totals = Numbers(precision=self.config.precision) |
|
167 self.directory_was_empty = False |
167 |
168 |
168 self.template_globals = { |
169 self.template_globals = { |
169 # Functions available in the templates. |
170 # Functions available in the templates. |
170 'escape': escape, |
171 'escape': escape, |
171 'pair': pair, |
172 'pair': pair, |
222 """Make local instances of static files for HTML report.""" |
223 """Make local instances of static files for HTML report.""" |
223 # The files we provide must always be copied. |
224 # The files we provide must always be copied. |
224 for static in self.STATIC_FILES: |
225 for static in self.STATIC_FILES: |
225 shutil.copyfile(data_filename(static), os.path.join(self.directory, static)) |
226 shutil.copyfile(data_filename(static), os.path.join(self.directory, static)) |
226 |
227 |
|
228 # Only write the .gitignore file if the directory was originally empty. |
227 # .gitignore can't be copied from the source tree because it would |
229 # .gitignore can't be copied from the source tree because it would |
228 # prevent the static files from being checked in. |
230 # prevent the static files from being checked in. |
229 gitigore_path = os.path.join(self.directory, ".gitignore") |
231 if self.directory_was_empty: |
230 if not os.path.exists(gitigore_path): |
232 with open(os.path.join(self.directory, ".gitignore"), "w") as fgi: |
231 with open(gitigore_path, "w") as fgi: |
|
232 fgi.write("# Created by coverage.py\n*\n") |
233 fgi.write("# Created by coverage.py\n*\n") |
233 |
234 |
234 # The user may have extra CSS they want copied. |
235 # The user may have extra CSS they want copied. |
235 if self.extra_css: |
236 if self.extra_css: |
236 shutil.copyfile(self.config.extra_css, os.path.join(self.directory, self.extra_css)) |
237 shutil.copyfile(self.config.extra_css, os.path.join(self.directory, self.extra_css)) |
238 def html_file(self, fr, analysis): |
239 def html_file(self, fr, analysis): |
239 """Generate an HTML file for one source file.""" |
240 """Generate an HTML file for one source file.""" |
240 rootname = flat_rootname(fr.relative_filename()) |
241 rootname = flat_rootname(fr.relative_filename()) |
241 html_filename = rootname + ".html" |
242 html_filename = rootname + ".html" |
242 ensure_dir(self.directory) |
243 ensure_dir(self.directory) |
|
244 if not os.listdir(self.directory): |
|
245 self.directory_was_empty = True |
243 html_path = os.path.join(self.directory, html_filename) |
246 html_path = os.path.join(self.directory, html_filename) |
244 |
247 |
245 # Get the numbers for this file. |
248 # Get the numbers for this file. |
246 nums = analysis.numbers |
249 nums = analysis.numbers |
247 self.all_files_nums.append(nums) |
250 self.all_files_nums.append(nums) |