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')
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
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: