Prettify error messages for invalid component names
authorKalle Vahlman <kalle.vahlman@movial.com>
Tue, 9 Dec 2008 11:30:58 +0000 (13:30 +0200)
committerKalle Vahlman <kalle.vahlman@movial.com>
Tue, 9 Dec 2008 11:30:58 +0000 (13:30 +0200)
matrix/build.py
matrix/matrix.py

index 51e23cf..4817d65 100644 (file)
@@ -15,7 +15,10 @@ Error = RuntimeError
 InternalError = Exception
 
 def build(targets):
 InternalError = Exception
 
 def build(targets):
-       selected = set([components.by_name[i] for i in targets])
+       try:
+               selected = set([components.by_name[i] for i in targets])
+       except KeyError, e:
+               raise Error("Component " + i + " not found")
        components.fill_in_depends(selected)
        components.init_rdepends(selected)
 
        components.fill_in_depends(selected)
        components.init_rdepends(selected)
 
@@ -53,7 +56,10 @@ def build(targets):
                print 'Nothing to build'
 
 def build_only(targets):
                print 'Nothing to build'
 
 def build_only(targets):
-       all = [components.by_name[i] for i in targets]
+       try:
+               all = [components.by_name[i] for i in targets]
+       except KeyError:
+               raise Error('Component ' + i + ' not found')
        count = len(all)
 
        # Set weights based on user-specified order.  Weight recalculation
        count = len(all)
 
        # Set weights based on user-specified order.  Weight recalculation
index 0be3379..4bf796a 100644 (file)
@@ -198,15 +198,21 @@ def execute(args):
 def remove_tree(path):
        execute(['rm', '-rf', path])
 
 def remove_tree(path):
        execute(['rm', '-rf', path])
 
+def find_component(name):
+       try:
+               return components.by_name[name]
+       except KeyError:
+               raise Error("Component " + name + " not found");
+
 def meta(targets):
        for name in targets:
 def meta(targets):
        for name in targets:
-               c = components.by_name[name]
+               c = find_component(name)
                if not c.meta.exists():
                        c.meta.clone()
        
 def clone(targets):
        for name in targets:
                if not c.meta.exists():
                        c.meta.clone()
        
 def clone(targets):
        for name in targets:
-               c = components.by_name[name]
+               c = find_component(name)
                clone_component(c)
 
 def clone_component(c, overwrite=False):
                clone_component(c)
 
 def clone_component(c, overwrite=False):
@@ -232,7 +238,7 @@ def clean(targets):
        changed = False
 
        for name in targets:
        changed = False
 
        for name in targets:
-               c = components.by_name[name]
+               c = find_component(name)
                c.source.clean()
                cache.remove(c)
 
                c.source.clean()
                cache.remove(c)
 
@@ -246,7 +252,7 @@ def for_each_repository(func, targets=None):
        ret = None
 
        for name in targets:
        ret = None
 
        for name in targets:
-               c = components.by_name[name]
+               c = find_component(name)
                if c.source.exists():
                        value = func(c.source)
                        if value:
                if c.source.exists():
                        value = func(c.source)
                        if value:
@@ -277,7 +283,7 @@ def changes(targets):
        changed = False
 
        for name in targets:
        changed = False
 
        for name in targets:
-               c = components.by_name[name]
+               c = find_component(name)
 
                if c.source.exists():
                        if check_changes(c.source):
 
                if c.source.exists():
                        if check_changes(c.source):
@@ -310,7 +316,7 @@ def source_dist(targets):
                os.makedirs(location)
 
        for name in targets:
                os.makedirs(location)
 
        for name in targets:
-               c = components.by_name[name]
+               c = find_component(name)
                dist_changes(c, location)
                dist_sources(c, location)
 
                dist_changes(c, location)
                dist_sources(c, location)