From 776961cdf1890aaed5a64cf5afb067ee86e88a80 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 3 Sep 2014 09:45:43 +0000 Subject: Add __repr__ method to Source and SplitRules This helps debugging issues with rule matching, since SplitRules can be print-statemented --- morphlib/artifact.py | 3 +++ morphlib/artifactsplitrule.py | 17 +++++++++++++++++ morphlib/source.py | 3 +++ 3 files changed, 23 insertions(+) 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) -- cgit v1.2.1