[gnome-continuous-yocto/gnomeostree-3.28-rocko: 2789/8267] scripts/buildstats-diff: use exception for internal error handling



commit cbbe51f55f123678219b7a49ca80389d1c7e2a7e
Author: Markus Lehtonen <markus lehtonen linux intel com>
Date:   Thu Sep 29 17:28:06 2016 +0300

    scripts/buildstats-diff: use exception for internal error handling
    
    (From OE-Core rev: 17b27b7a8bfc8b1c9ee274d1ed2d5b57bea13bf5)
    
    Signed-off-by: Markus Lehtonen <markus lehtonen linux intel com>
    Signed-off-by: Ross Burton <ross burton intel com>
    Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>

 scripts/buildstats-diff |   38 +++++++++++++++++++++-----------------
 1 files changed, 21 insertions(+), 17 deletions(-)
---
diff --git a/scripts/buildstats-diff b/scripts/buildstats-diff
index f26a6c1..3c6cb1e 100755
--- a/scripts/buildstats-diff
+++ b/scripts/buildstats-diff
@@ -30,6 +30,11 @@ logging.basicConfig(level=logging.INFO)
 log = logging.getLogger()
 
 
+class ScriptError(Exception):
+    """Exception for internal error handling of this script"""
+    pass
+
+
 class TimeZone(tzinfo):
     """Simple fixed-offset tzinfo"""
     def __init__(self, seconds, name):
@@ -161,8 +166,7 @@ def read_buildstats_dir(bs_dir):
             log.warning("Multiple buildstats found, using the first one")
         top_dir = subdirs[0]
     else:
-        log.error("No such directory: %s", bs_dir)
-        sys.exit(1)
+        raise ScriptError("No such directory: {}".format(bs_dir))
     log.debug("Reading buildstats directory %s", top_dir)
     subdirs = os.listdir(top_dir)
 
@@ -187,9 +191,8 @@ def read_buildstats_dir(bs_dir):
             recipe_bs['tasks'][task] = read_buildstats_file(
                     os.path.join(recipe_dir, task))
         if name in buildstats:
-            log.error("Cannot handle multiple versions of the same package (%s)",
-                      name)
-            sys.exit(1)
+            raise ScriptError("Cannot handle multiple versions of the same "
+                              "package ({})".format(name))
         buildstats[name] = recipe_bs
 
     return buildstats
@@ -202,9 +205,8 @@ def read_buildstats_json(path):
         bs_json = json.load(fobj)
     for recipe_bs in bs_json:
         if recipe_bs['name'] in buildstats:
-            log.error("Cannot handle multiple versions of the same package (%s)",
-                      recipe_bs['name'])
-            sys.exit(1)
+            raise ScriptError("Cannot handle multiple versions of the same "
+                              "package ({})".format(recipe_bs['name']))
 
         if recipe_bs['epoch'] is None:
             recipe_bs['nevr'] = "{}-{}-{}".format(recipe_bs['name'], recipe_bs['version'], 
recipe_bs['revision'])
@@ -497,16 +499,18 @@ def main(argv=None):
             sys.exit(1)
         sort_by.append(field)
 
+    try:
+        bs1 = read_buildstats(args.buildstats1)
+        bs2 = read_buildstats(args.buildstats2)
 
-    bs1 = read_buildstats(args.buildstats1)
-    bs2 = read_buildstats(args.buildstats2)
-
-    if args.ver_diff:
-        print_ver_diff(bs1, bs2)
-    else:
-        print_task_diff(bs1, bs2, args.diff_attr, args.min_val,
-                        args.min_absdiff, sort_by)
-
+        if args.ver_diff:
+            print_ver_diff(bs1, bs2)
+        else:
+            print_task_diff(bs1, bs2, args.diff_attr, args.min_val,
+                            args.min_absdiff, sort_by)
+    except ScriptError as err:
+        log.error(str(err))
+        return 1
     return 0
 
 if __name__ == "__main__":


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]