summaryrefslogtreecommitdiff
path: root/coverage/data.py
diff options
context:
space:
mode:
authorNed Batchelder <nedbat@gmail.com>2015-04-24 20:17:09 -0400
committerNed Batchelder <nedbat@gmail.com>2015-04-24 20:17:09 -0400
commitbb03090a714dc9f9c9a5b0ea3b36af05cfe7bc1a (patch)
tree407ffb056d4e08f0a8238ee766856a17af1ca83d /coverage/data.py
parent5d35a6e0ce6b96b37843a0e8f0fa52f3d015cb10 (diff)
parent22612b88e8cb8c61edaed97827d7910b11130415 (diff)
downloadpython-coveragepy-git-bb03090a714dc9f9c9a5b0ea3b36af05cfe7bc1a.tar.gz
Merged in clytwynec/coverage.py/combine-from-multiple-dirs (pull request #51)
Added ability to combine coverage data files from multiple directories into one file via command line args.
Diffstat (limited to 'coverage/data.py')
-rw-r--r--coverage/data.py38
1 files changed, 23 insertions, 15 deletions
diff --git a/coverage/data.py b/coverage/data.py
index 2c5d3516..8a699b5b 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -1,5 +1,6 @@
"""Coverage data for Coverage."""
+import glob
import os
from coverage.backward import iitems, pickle
@@ -190,7 +191,7 @@ class CoverageData(object):
pass
return lines, arcs, plugins
- def combine_parallel_data(self, aliases=None):
+ def combine_parallel_data(self, aliases=None, data_dirs=None):
"""Combine a number of data files together.
Treat `self.filename` as a file prefix, and combine the data from all
@@ -199,23 +200,30 @@ class CoverageData(object):
If `aliases` is provided, it's a `PathAliases` object that is used to
re-map paths to match the local machine's.
+ If `data_dirs` is provided, then it combines the data files from each
+ directory into a single file.
+
"""
aliases = aliases or PathAliases()
data_dir, local = os.path.split(self.filename)
- localdot = local + '.'
- for f in os.listdir(data_dir or '.'):
- if f.startswith(localdot):
- full_path = os.path.join(data_dir, f)
- new_lines, new_arcs, new_plugins = self._read_file(full_path)
- for filename, file_data in iitems(new_lines):
- filename = aliases.map(filename)
- self.lines.setdefault(filename, {}).update(file_data)
- for filename, file_data in iitems(new_arcs):
- filename = aliases.map(filename)
- self.arcs.setdefault(filename, {}).update(file_data)
- self.plugins.update(new_plugins)
- if f != local:
- os.remove(full_path)
+ localdot = local + '.*'
+
+ data_dirs = data_dirs or [data_dir]
+ files_to_combine = []
+ for d in data_dirs:
+ pattern = os.path.join(os.path.abspath(d), localdot)
+ files_to_combine.extend(glob.glob(pattern))
+
+ for f in files_to_combine:
+ new_lines, new_arcs, new_plugins = self._read_file(f)
+ for filename, file_data in iitems(new_lines):
+ filename = aliases.map(filename)
+ self.lines.setdefault(filename, {}).update(file_data)
+ for filename, file_data in iitems(new_arcs):
+ filename = aliases.map(filename)
+ self.arcs.setdefault(filename, {}).update(file_data)
+ self.plugins.update(new_plugins)
+ os.remove(f)
def add_line_data(self, line_data):
"""Add executed line data.