Component() supports 'rank' parameter
authorTimo Savola <tsavola@movial.fi>
Fri, 1 Aug 2008 14:27:48 +0000 (17:27 +0300)
committerTimo Savola <tsavola@movial.fi>
Fri, 1 Aug 2008 14:27:48 +0000 (17:27 +0300)
components in a rank implicitly depend on the components in ranks with
smaller numerical value.  the default rank is 0: to force a component to
be built before others, give it a negative rank etc.

matrix/components.py

index d8d152d..e31165f 100644 (file)
@@ -21,7 +21,7 @@ class Component(object):
        weight = None
        state = None
 
-       def __init__(self, name, branch=None, flags=[]):
+       def __init__(self, name, branch=None, flags=[], rank=0):
                self.name = name
 
                self.source = Repository(
@@ -40,6 +40,8 @@ class Component(object):
                self.packages = {}
                self.depends = set()
 
+               self.rank = rank
+
        def __str__(self):
                return str(self.source)
 
@@ -95,6 +97,7 @@ def init():
                init_packages(c, targets, packages)
 
        init_depends(packages)
+       init_rank_depends()
 
        targets.sort()
        return targets
@@ -195,6 +198,26 @@ def init_depends(packages):
        if fail:
                raise Error('Invalid component tree')
 
+def init_rank_depends():
+       components_by_rank = {}
+       for c in config.components.itervalues():
+               l = components_by_rank.get(c.rank)
+               if l is None:
+                       l = []
+                       components_by_rank[c.rank] = l
+               l.append(c)
+
+       ranks = list(components_by_rank.keys())
+       ranks.sort()
+
+       for i in xrange(1, len(ranks)):
+               curr_rank = ranks[i]
+               for curr_comp in components_by_rank[curr_rank]:
+                       for j in xrange(i):
+                               prev_rank = ranks[j]
+                               for prev_comp in components_by_rank[prev_rank]:
+                                       curr_comp.add_depend(prev_comp)
+
 def fill_in_depends(components):
        depends = True
        while depends: