Allow named a new name to diff html
authorLingchao Xin <lingchaox.xin@intel.com>
Fri, 3 Jan 2014 03:24:01 +0000 (11:24 +0800)
committerLingchao Xin <lingchaox.xin@intel.com>
Fri, 3 Jan 2014 03:24:20 +0000 (11:24 +0800)
Now you can give a new name to your local diff html, default
is diff.html.

Change-Id: I479de7c701fa564828c98e925a6ddffb72af4aea

snapdiff/__init__.py
tools/snap-diff

index aeb85cb04d8892f7f26951c762fcf4f373f86c73..03ceb65d04444c9034793dc6a6082ca6450557e3 100644 (file)
@@ -187,7 +187,7 @@ def diff_to_HTML(old_url, new_url, style='repo'):
     elif style == 'image':
         return output_html('image_diff.html', **context)
 
-def diff_to_dist(old_url, new_url, dist_path, style='repo'):
+def diff_to_dist(old_url, new_url, dist_path, style='repo', diff_name='diff'):
     """create a dist-dir of diffs, contains html and css"""
     static_dir = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'static')
@@ -209,6 +209,6 @@ def diff_to_dist(old_url, new_url, dist_path, style='repo'):
                 shutil.copy(os.path.join(root, filename),
                     os.path.join(dist_path, 'img', filename))
 
-    with open(os.path.join(dist_path, 'diff.html'), 'w') as fp:
+    with open(os.path.join(dist_path, '%s.html' % diff_name), 'w') as fp:
         fp.write(output_html)
     return dist_path
index 5dd60135a70c73ffb2a6273ff4d3e48e8a6e67f1..6409e790becbaafe76a1daa02af363d363c3c2a0 100755 (executable)
@@ -11,15 +11,20 @@ def main(argv):
     parser = argparse.ArgumentParser(description=description)
     parser.add_argument(dest='old', help='old repo')
     parser.add_argument(dest='new', help='new repo')
-    parser.add_argument('-t', dest='type', default='repo', help="which diff you want(repo | image, default is repo)")
+    parser.add_argument('-t', dest='type', default='repo', \
+            choices=['repo', 'image'], \
+            help="which diff you want(default is 'repo')")
     group = parser.add_mutually_exclusive_group()
-    group.add_argument('--json', help='output json diffs', action='store_true')
-    group.add_argument('-d', dest='directory', help="Output html diffs into the directory")
+    group.add_argument('--json', help='output json diff', action='store_true')
+    group.add_argument('-d', dest='directory', help="output html diff into the directory")
+    parser.add_argument('-n', dest='name', \
+            help="give a name to diff html(effective to '-d' option only)")
     args = parser.parse_args(argv)
 
-    if args.directory:
+    if args.directory and args.name:
+        snapdiff.diff_to_dist(args.old, args.new, args.directory, style=args.type, diff_name=args.name)
+    elif args.directory:
         snapdiff.diff_to_dist(args.old, args.new, args.directory, style=args.type)
-        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: