deferred error message output
authorTimo Savola <tsavola@movial.fi>
Sat, 5 Apr 2008 21:54:53 +0000 (00:54 +0300)
committerTimo Savola <tsavola@movial.fi>
Sat, 5 Apr 2008 21:54:53 +0000 (00:54 +0300)
bin/matrix
matrix/matrix.py

index b7d0d88b072a62660eece006a226a3579afaf6e8..431fcf06cfb07779ad48f29b1c1b95e798065c68 100755 (executable)
@@ -24,4 +24,5 @@ except RuntimeError, e:
        sys.exit(1)
 
 except KeyboardInterrupt:
+       print >>sys.stderr, 'Interrupted'
        sys.exit(1)
index 4b5f772e5d18233f9722c450995ad675118fedf8..34f924b7645749ce0079b44e67752393ab892dce 100644 (file)
@@ -17,7 +17,26 @@ from rootfs import RootFS
 
 Error = RuntimeError
 
+error_log = []
+
+def log_error(msg):
+       error_log.append(msg)
+
 def main():
+       try:
+               try:
+                       logged_main()
+               except:
+                       if not error_log:
+                               print >>sys.stderr
+                       raise
+       finally:
+               if error_log:
+                       print >>sys.stderr
+                       for msg in error_log:
+                               print >>sys.stderr, msg
+
+def logged_main():
        parse_config('config.local')
 
        command, params, targets = parse_args(sys.argv)
@@ -218,8 +237,9 @@ def update_component_depends(packages):
                        deppkg = packages.get(depname)
 
                        if not deppkg:
-                               print >>sys.stderr, 'Package', pkg.name, \
-                                       'depends on non-existent package', depname
+                               log_error('Package %s depends on ' \
+                                         'non-existent package %s', \
+                                         pkg.name, depname)
                                continue
 
                        if deppkg.component == pkg.component:
@@ -232,14 +252,14 @@ def update_component_depends(packages):
                for spec in pkg.depends.split():
                        if not Depend(spec).check(packages):
                                fail = True
-                               print >>sys.stderr, 'Dependency', spec, \
-                                       'failed for', pkg.name
+                               log_error('Dependency %s failed for %s' % \
+                                         (spec, pkg.name))
 
                for spec in pkg.conflicts.split():
                        if Depend(spec).check(packages):
                                fail = True
-                               print >>sys.stderr, pkg.name, \
-                                       'conflicts with', spec
+                               log_error('Package %s conflicts with %s' % \
+                                         (pkg.name, spec))
 
        if fail:
                raise Error('Invalid component tree')
@@ -607,7 +627,7 @@ def clean_components(targets):
                for repo in (c.repo, c.meta):
                        files = git.ls_files(repo.path, ['-m', '-d'])
                        if files:
-                               print len(files), 'dirty files left in', repo.path
+                               log_error('Dirty files left in %s' % repo.path)
 
 def for_each_repository(func, targets=None):
        if not targets: