from .repo import Repo
-def diff_to_json(old_url, new_url, style='repo'):
- """Output diffs' json format"""
+def diff_to_json(old_url, new_url, **kwargs):
+ """Output diffs' json format.
+
+ :param old_url: old repo or image url
+ :param new_url: new repo or image url
+ :param style: (optional) repo or image type, default is repo
+ """
if not old_url or not new_url:
return
+ style = kwargs.get('style') or 'repo'
+
if style == 'repo':
old, new = Repo(old_url).packages, Repo(new_url).packages
elif style == 'image':
return json.dumps(obj, indent=4)
-def diff_to_html(old_url, new_url, style='repo'):
- """Output diffs' html format"""
+def diff_to_html(old_url, new_url, **kwargs):
+ """Output diffs' html format.
+
+ :param old_url: old repo or image url
+ :param new_url: new repo or image url
+ :param style: repo or image type, default is repo
+ """
+
+ style = kwargs.get('style') or 'repo'
- json_obj = diff_to_json(old_url, new_url, style)
+ json_obj = diff_to_json(old_url, new_url, style=style)
if json_obj is None:
return
elif style == 'image':
return output_html('image_diff.html', **context) # pylint: disable=W0142
-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"""
+def diff_to_dist(old_url, new_url, dist_path, **kwargs):
+ """Create a dist-dir of diffs, contains html and css.
+
+ :param old_url: old repo or image url
+ :param new_url: new repo or image url
+ :param dist_path: where you put diff
+ :param diff_name: (optional) the diff file name
+ :param style: (optional) repo or image type, default is repo
+ """
static_dir = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'static')
- output = diff_to_html(old_url, new_url, style)
+
+ output = diff_to_html(old_url, new_url, style=kwargs.get('style'))
if not os.path.exists(dist_path):
os.makedirs(dist_path)
shutil.copy(os.path.join(root, filename),
os.path.join(dist_path, 'img', filename))
+ diff_name = kwargs.get('diff_name') or 'diff'
+
with open(os.path.join(dist_path, '%s.html' % diff_name), 'w') as fname:
fname.write(output)
return dist_path