summaryrefslogtreecommitdiff
path: root/morphlib/artifactsplitrule.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@gmail.com>2014-09-03 09:45:43 +0000
committerRichard Maw <richard.maw@gmail.com>2014-09-17 15:51:10 +0000
commit776961cdf1890aaed5a64cf5afb067ee86e88a80 (patch)
tree00029c74df587536c41e3a70326cdad2a10b49d0 /morphlib/artifactsplitrule.py
parent4d38f6189114367014794619ef1fcb79e984c484 (diff)
downloadmorph-776961cdf1890aaed5a64cf5afb067ee86e88a80.tar.gz
Add __repr__ method to Source and SplitRules
This helps debugging issues with rule matching, since SplitRules can be print-statemented
Diffstat (limited to 'morphlib/artifactsplitrule.py')
-rw-r--r--morphlib/artifactsplitrule.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/morphlib/artifactsplitrule.py b/morphlib/artifactsplitrule.py
index 125f5b93..cf0d1060 100644
--- a/morphlib/artifactsplitrule.py
+++ b/morphlib/artifactsplitrule.py
@@ -51,6 +51,9 @@ class FileMatch(Rule):
def match(self, path):
return any(r.match(path) for r in self._regexes)
+ def __repr__(self):
+ return 'FileMatch(%s)' % '|'.join(r.pattern for r in self._regexes)
+
class ArtifactMatch(Rule):
'''Match an artifact's name against a list of regular expressions.
@@ -63,6 +66,9 @@ class ArtifactMatch(Rule):
def match(self, (source_name, artifact_name)):
return any(r.match(artifact_name) for r in self._regexes)
+ def __repr__(self):
+ return 'ArtifactMatch(%s)' % '|'.join(r.pattern for r in self._regexes)
+
class ArtifactAssign(Rule):
'''Match only artifacts with the specified source and artifact names.
@@ -80,6 +86,9 @@ class ArtifactAssign(Rule):
def match(self, (source_name, artifact_name)):
return (source_name, artifact_name) == self._key
+ def __repr__(self):
+ return 'ArtifactAssign(%s, %s)' % self._key
+
class SourceAssign(Rule):
'''Match only artifacts which come from the specified source.
@@ -96,6 +105,9 @@ class SourceAssign(Rule):
def match(self, (source_name, artifact_name)):
return source_name == self._source
+ def __repr__(self):
+ return 'SourceAssign(%s, *)' % self._source
+
class SplitRules(collections.Iterable):
'''Rules engine for splitting a source's artifacts.
@@ -172,6 +184,11 @@ class SplitRules(collections.Iterable):
return matches, overlaps, unmatched
+ def __repr__(self):
+ return 'SplitRules(%s)' % ', '.join(
+ '%s=%s' % (artifact, rule)
+ for artifact, rule in self._rules)
+
# TODO: Work out a good way to feed new defaults in. This is good for
# the usual Linux userspace, but we may find issues and need a