From c41e6afcec9385fc0fda3e51f0f95b7041c8a43d Mon Sep 17 00:00:00 2001 From: Shan Jin Date: Thu, 23 Jan 2014 11:52:56 +0800 Subject: [PATCH] Add links on repo and image diff page - make link from "gitpath" to gitweb server. - make link from "commitId" to gitweb server. - add profile.yaml to config mapping between download server and gitweb server. Change-Id: Ia44c508786369a263b512259f8f6bd983cf78013 --- distfiles/profile.yaml | 7 +++++++ packaging/snapdiff.spec | 5 +++++ snapdiff/__init__.py | 22 ++++++++++++++++++++++ snapdiff/templates/diff.html | 23 ++++++++++++----------- snapdiff/templates/image_diff.html | 23 ++++++++++++----------- 5 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 distfiles/profile.yaml diff --git a/distfiles/profile.yaml b/distfiles/profile.yaml new file mode 100644 index 0000000..1f35636 --- /dev/null +++ b/distfiles/profile.yaml @@ -0,0 +1,7 @@ +profile: + - name: https://download.tizendev.org + gitweb: https://review.tizendev.org/gerrit/gitweb + - name: https://download.tz.otcshare.org + gitweb: https://tz.otcshare.org/gerrit/gitweb + - name: http://download.tizen.org + gitweb: https://review.tizen.org/gerrit/gitweb diff --git a/packaging/snapdiff.spec b/packaging/snapdiff.spec index 8d015c1..72efe38 100644 --- a/packaging/snapdiff.spec +++ b/packaging/snapdiff.spec @@ -16,11 +16,13 @@ BuildRequires: python-devel BuildRequires: python-jinja2 BuildRequires: python-requests BuildRequires: python-xml +BuildRequires: python-yaml BuildRequires: python-setuptools Requires: python >= 2.7 Requires: python-jinja2 Requires: python-requests Requires: python-xml +Requires: python-yaml BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArch: noarch %{!?python_sitelib: %define python_sitelib %(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} @@ -36,6 +38,7 @@ CFLAGS="%{optflags}" python setup.py build %install python setup.py install --prefix=%{_prefix} --root=%{buildroot} +install -D -m 644 distfiles/profile.yaml %{buildroot}/etc/%{name}/profile.yaml %clean rm -rf %{buildroot} @@ -44,4 +47,6 @@ rm -rf %{buildroot} %defattr(-,root,root) %{_bindir}/* %{python_sitelib}/* +%dir %{_sysconfdir}/%{name} +%{_sysconfdir}/%{name}/profile.yaml diff --git a/snapdiff/__init__.py b/snapdiff/__init__.py index 69ac8f6..3d02bf2 100644 --- a/snapdiff/__init__.py +++ b/snapdiff/__init__.py @@ -31,6 +31,8 @@ import os import shutil import re +import yaml + from .image import ks_diff, packages from .render import output_html from .repo import Repo @@ -59,6 +61,22 @@ def diff_to_json(old_url, new_url, **kwargs): added, removed, modified, rebuilded = [], [], [], [] package_names = set(old.__dict__.keys() + new.__dict__.keys()) + def _get_git_web(url): + matchdomain = re.match(r"http[s]?://[a-z0-9\.]*", url) + if not matchdomain: + return "#" + srcdomain = matchdomain.group(0) + profile = '/etc/%s/profile.yaml' % __title__ + gitweb_dict = {} + if not os.path.exists(profile): + return "#" + with open(profile, 'r') as pfile: + gitweb_dict = yaml.load(pfile) + for domain in gitweb_dict['profile']: + if domain['name'] == srcdomain: + return domain['gitweb'] + return "#" + def _pair_old_new(): """Generate old and new pkg pair""" for name in package_names: @@ -172,6 +190,9 @@ def diff_to_json(old_url, new_url, **kwargs): if style == 'image': obj['diff']['ks'] = ks_diff(old_url, new_url) + obj['gitweb'] = {'old': _get_git_web(old_url), + 'new': _get_git_web(new_url)} + return json.dumps(obj, indent=4) def diff_to_html(old_url, new_url, **kwargs): @@ -197,6 +218,7 @@ def diff_to_html(old_url, new_url, **kwargs): 'new': {'url': new_url, 'name': re.search(r'\w*_\d{8}\.\d*', new_url).group(0)}, 'diff': data['diff'], + 'gitweb': data['gitweb'] } if style == 'repo': return output_html('diff.html', **context) # pylint: disable=W0142 diff --git a/snapdiff/templates/diff.html b/snapdiff/templates/diff.html index de33539..578e7be 100644 --- a/snapdiff/templates/diff.html +++ b/snapdiff/templates/diff.html @@ -38,6 +38,7 @@ + {% set git_web = gitweb %} {% if diff['added'] %} @@ -47,8 +48,8 @@ - - + + {% endfor %} @@ -63,8 +64,8 @@ - - + + {% endfor %} @@ -83,15 +84,15 @@ - - + + {% endfor %} @@ -108,8 +109,8 @@ - - + + {% endfor %} diff --git a/snapdiff/templates/image_diff.html b/snapdiff/templates/image_diff.html index 93a5d12..a887500 100644 --- a/snapdiff/templates/image_diff.html +++ b/snapdiff/templates/image_diff.html @@ -82,6 +82,7 @@

Added Packages

{{ item['newpkg']['name'] }} {{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}{{ item['newpkg']['git_path'] }}{{ item['newpkg']['commit_id'] }}{{ item['newpkg']['git_path'] }}{{ item['newpkg']['commit_id'] }}
{{ item['oldpkg']['name'] }} {{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}{{ item['oldpkg']['git_path'] }}{{ item['oldpkg']['commit_id'] }}{{ item['oldpkg']['git_path'] }}{{ item['oldpkg']['commit_id'] }}
{{ item['oldpkg']['commit_id'] }}{{ item['newpkg']['commit_id'] }}{{ item['oldpkg']['commit_id'] }}{{ item['newpkg']['commit_id'] }}
{{ item['oldpkg']['name'] }} {{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}} {{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}{{ item['oldpkg']['git_path'] }}{{ item['oldpkg']['commit_id'] }}{{ item['oldpkg']['git_path'] }}{{ item['oldpkg']['commit_id'] }}
+ {% set git_web = gitweb %} {% if diff['added'] %} @@ -91,8 +92,8 @@ - - + + {% endfor %} @@ -107,8 +108,8 @@ - - + + {% endfor %} @@ -127,15 +128,15 @@ - - + + {% endfor %} @@ -152,8 +153,8 @@ - - + + {% endfor %} -- 2.34.1

Added Packages

{{ item['newpkg']['name'] }} {{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}{{ item['newpkg']['git_path'] }}{{ item['newpkg']['commit_id'] }}{{ item['newpkg']['git_path'] }}{{ item['newpkg']['commit_id'] }}
{{ item['oldpkg']['name'] }} {{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}{{ item['oldpkg']['git_path'] }}{{ item['oldpkg']['commit_id'] }}{{ item['oldpkg']['git_path'] }}{{ item['oldpkg']['commit_id'] }}
{{ item['oldpkg']['commit_id'] }}{{ item['newpkg']['commit_id'] }}{{ item['oldpkg']['commit_id'] }}{{ item['newpkg']['commit_id'] }}
{{ item['oldpkg']['name'] }} {{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}} {{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}{{ item['oldpkg']['git_path'] }}{{ item['oldpkg']['commit_id'] }}{{ item['oldpkg']['git_path'] }}{{ item['oldpkg']['commit_id'] }}