From d298f9af8c29771b86205876d7256ec704510c58 Mon Sep 17 00:00:00 2001 From: Lingchao Xin Date: Fri, 3 Jan 2014 11:24:01 +0800 Subject: [PATCH] Allow named a new name to diff html Now you can give a new name to your local diff html, default is diff.html. Change-Id: I479de7c701fa564828c98e925a6ddffb72af4aea --- snapdiff/__init__.py | 4 ++-- tools/snap-diff | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/snapdiff/__init__.py b/snapdiff/__init__.py index aeb85cb..03ceb65 100644 --- a/snapdiff/__init__.py +++ b/snapdiff/__init__.py @@ -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 diff --git a/tools/snap-diff b/tools/snap-diff index 5dd6013..6409e79 100755 --- a/tools/snap-diff +++ b/tools/snap-diff @@ -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: -- 2.34.1