Add diff_to_dist into snap-diff tool
authorLingchao Xin <lingchaox.xin@intel.com>
Wed, 18 Dec 2013 03:33:28 +0000 (11:33 +0800)
committerLingchao Xin <lingchaox.xin@intel.com>
Wed, 18 Dec 2013 06:14:27 +0000 (14:14 +0800)
Change-Id: I50da5e4e72fa343ea623274f1fe68ae343888187

snapdiff/__init__.py
tools/snap-diff

index 56367af6c1c5ec31184abbfac4f7f1836a234b5b..84b1c0466f617eb7513456fdc391e9fd66061b79 100644 (file)
@@ -181,11 +181,11 @@ def diff_to_HTML(old_url, new_url, style='repo'):
 
     return output_html('diff.html', **context)
 
-def diff_to_dist(old_url, new_url, dist_path):
+def diff_to_dist(old_url, new_url, dist_path, style='repo'):
     """create a dist-dir of diffs, contains html and css"""
     static_dir = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'static')
-    output_html = diff_to_HTML(old_url, new_url)
+    output_html = diff_to_HTML(old_url, new_url, style)
 
     if not os.path.exists(dist_path):
         os.makedirs(dist_path)
index cbd82ad58f7506a040a9fed9df797cf9e6066aab..a5f4c0b0b35daf98c901d37bb8365ae06f377f01 100755 (executable)
@@ -12,13 +12,21 @@ def main(argv):
     parser.add_argument(dest='old', help='old repo')
     parser.add_argument(dest='new', help='new repo')
     parser.add_argument('--json', help='output json diffs', action='store_true')
-    parser.add_argument('-t', dest='type', help="which diff you want(repo | image, default is repo)")
+    group = parser.add_mutually_exclusive_group()
+    group.add_argument('-t', dest='type', default='repo', help="which diff you want(repo | image, default is repo)")
+    group.add_argument('-d', dest='directory', help="Output html diffs into the directory")
     args = parser.parse_args(argv)
 
-    if args.json:
-        print snapdiff.diff_to_JSON(args.old, args.new, style=args.type or 'repo')
+    if args.directory:
+        snapdiff.diff_to_dist(args.old, args.new, args.directory, style=args.type or 'repo')
+        print "Diff between '%s' and '%s' has been ready in %s" % (args.old, args.new, args.directory)
+    elif args.json:
+        print snapdiff.diff_to_JSON(args.old, args.new, style=args.type)
     else:
-        print snapdiff.diff_to_HTML(args.old, args.new, style=args.type or 'repo')
+        print snapdiff.diff_to_HTML(args.old, args.new, style=args.type)
 
 if __name__ == '__main__':
-    sys.exit(main(sys.argv[1:]))
+    try:
+        sys.exit(main(sys.argv[1:]))
+    except KeyboardInterrupt:
+        pass