summaryrefslogtreecommitdiff
path: root/morphlib/artifactsplitrule.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/artifactsplitrule.py')
-rw-r--r--morphlib/artifactsplitrule.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/morphlib/artifactsplitrule.py b/morphlib/artifactsplitrule.py
index f30b05a3..246691d8 100644
--- a/morphlib/artifactsplitrule.py
+++ b/morphlib/artifactsplitrule.py
@@ -31,6 +31,7 @@ class Rule(object):
source it came from.
'''
+
def match(self, *args):
return True
@@ -42,6 +43,7 @@ class FileMatch(Rule):
is counted as a valid match.
'''
+
def __init__(self, regexes):
# Possible optimisation: compile regexes as one pattern
self._regexes = [re.compile(r) for r in regexes]
@@ -53,6 +55,7 @@ class FileMatch(Rule):
class ArtifactMatch(Rule):
'''Match an artifact's name against a list of regular expressions.
'''
+
def __init__(self, regexes):
# Possible optimisation: compile regexes as one pattern
self._regexes = [re.compile(r) for r in regexes]
@@ -70,8 +73,10 @@ class ArtifactAssign(Rule):
bar-runtime.
'''
+
def __init__(self, source_name, artifact_name):
self._key = (source_name, artifact_name)
+
def match(self, (source_name, artifact_name)):
return (source_name, artifact_name) == self._key
@@ -84,8 +89,10 @@ class SourceAssign(Rule):
system baz
'''
+
def __init__(self, source_name):
self._source = source_name
+
def match(self, (source_name, artifact_name)):
return source_name == self._source
@@ -102,6 +109,7 @@ class SplitRules(collections.Iterable):
generic catch-all matches.
'''
+
def __init__(self, *args):
self._rules = list(*args)
@@ -119,6 +127,7 @@ class SplitRules(collections.Iterable):
and not repeating the artifact.
'''
+
seen = set()
result = []
for artifact_name, rule in self._rules:
@@ -135,6 +144,7 @@ class SplitRules(collections.Iterable):
only used entry will be the first.
'''
+
return [a for a, r in self._rules if r.match(*args)]
def partition(self, iterable):
@@ -145,6 +155,7 @@ class SplitRules(collections.Iterable):
logic in multiple places, it's here as a convenience method.
'''
+
matches = collections.defaultdict(list)
overlaps = collections.defaultdict(set)
unmatched = set()
@@ -209,6 +220,7 @@ def unify_chunk_matches(morphology):
by building the chunk to the chunk artifact they should be put in.
'''
+
split_rules = SplitRules()
for ca_name, patterns in ((d['artifact'], d['include'])
@@ -235,6 +247,7 @@ def unify_stratum_matches(morphology):
strata to the stratum artifact they should be put in.
'''
+
assignment_split_rules = SplitRules()
for spec in morphology['chunks']:
source_name = spec['name']
@@ -271,6 +284,7 @@ def unify_system_matches(morphology):
by building the chunk to the chunk artifact they should be put in.
'''
+
name = morphology['name'] + '-rootfs'
split_rules = SplitRules()