summaryrefslogtreecommitdiff
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
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
-rw-r--r--morphlib/artifact.py3
-rw-r--r--morphlib/artifactsplitrule.py17
-rw-r--r--morphlib/source.py3
3 files changed, 23 insertions, 0 deletions
diff --git a/morphlib/artifact.py b/morphlib/artifact.py
index da6d3763..1e67643e 100644
--- a/morphlib/artifact.py
+++ b/morphlib/artifact.py
@@ -82,6 +82,9 @@ class Artifact(object):
def __str__(self): # pragma: no cover
return '%s|%s' % (self.source, self.name)
+ def __repr__(self): # pragma: no cover
+ return 'Artifact(%s)' % str(self)
+
def walk(self): # pragma: no cover
'''Return list of an artifact and its build dependencies.
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
diff --git a/morphlib/source.py b/morphlib/source.py
index 2dbabad1..d0f69a28 100644
--- a/morphlib/source.py
+++ b/morphlib/source.py
@@ -56,3 +56,6 @@ class Source(object):
return '%s|%s|%s' % (self.repo_name,
self.original_ref,
self.filename)
+
+ def __repr__(self): # pragma: no cover
+ return 'Source(%s)' % str(self)