Add links on repo and image diff page
authorShan Jin <shanx.jin@intel.com>
Thu, 23 Jan 2014 03:52:56 +0000 (11:52 +0800)
committerLin A Yang <lin.a.yang@intel.com>
Thu, 23 Jan 2014 09:21:20 +0000 (11:21 +0200)
- 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 [new file with mode: 0644]
packaging/snapdiff.spec
snapdiff/__init__.py
snapdiff/templates/diff.html
snapdiff/templates/image_diff.html

diff --git a/distfiles/profile.yaml b/distfiles/profile.yaml
new file mode 100644 (file)
index 0000000..1f35636
--- /dev/null
@@ -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
index 8d015c1acbb84278915c6852ab8b8c54b3be2bb5..72efe38acf179e1f72b204f688a775e656afaa13 100644 (file)
@@ -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
 
index 69ac8f6831c9b51e76b44fb7babc1f3ad02437fe..3d02bf25142e519bf8ee57fa1fd284eea92c860d 100644 (file)
@@ -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
index de335398a6b5db9b7ab142b8f202867e83c8051f..578e7bea3935d46af037f4ee9f38c4b9088fbcc0 100644 (file)
@@ -38,6 +38,7 @@
     </ul>
     <table>
         <tr><td colspan="6" class="tableTitle"><h3><a>Added Packages</a></h3></td></tr>
+        {% set git_web = gitweb %}
         {% if diff['added'] %}
             <tbody>
             <tr>
@@ -47,8 +48,8 @@
                 <tr>
                     <td>{{ item['newpkg']['name'] }}</td>
                     <td colspan="2">{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
-                    <td>{{ item['newpkg']['git_path'] }}</td>
-                    <td colspan="2">{{ item['newpkg']['commit_id'] }}</td>
+                    <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git">{{ item['newpkg']['git_path'] }}</a></td>
+                    <td colspan="2"><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ item['newpkg']['commit_id'] }}">{{ item['newpkg']['commit_id'] }}</a></td>
                 </tr>
             {% endfor %}
             </tbody>
@@ -63,8 +64,8 @@
                 <tr>
                     <td>{{ item['oldpkg']['name'] }}</td>
                     <td colspan="2">{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
-                    <td>{{ item['oldpkg']['git_path'] }}</td>
-                    <td colspan="2">{{ item['oldpkg']['commit_id'] }}</td>
+                    <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></td>
+                    <td colspan="2"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
                 </tr>
             {% endfor %}
         </tbody>
                     <td>
                         <ul>
                             {% if item['oldpkg']['git_path'] != item['newpkg']['git_path'] %}
-                                <li>{{ item['oldpkg']['git_path'] }}&nbsp;</li>
-                                <li>{{ item['newpkg']['git_path'] }}&nbsp;</li>
+                                <li><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a>&nbsp;</li>
+                                <li><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git">{{ item['newpkg']['git_path'] }}</a>&nbsp;</li>
                             {% else %}
-                                <li>{{ item['oldpkg']['git_path'] }}</li>
+                                <li><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></li>
                             {% endif %}
                         </ul>
                     </td>
-                    <td>{{ item['oldpkg']['commit_id'] }}</td>
-                    <td>{{ item['newpkg']['commit_id'] }}</td>
+                    <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
+                    <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ item['newpkg']['commit_id'] }}">{{ item['newpkg']['commit_id'] }}</a></td>
                     </td>
                 </tr>
             {% endfor %}
                     <td>{{ item['oldpkg']['name'] }}</td>
                     <td>{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
                     <td>{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
-                    <td>{{ item['oldpkg']['git_path'] }}</td>
-                    <td colspan="2">{{ item['oldpkg']['commit_id'] }}</td>
+                    <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></td>
+                    <td colspan="2"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
                 </tr>
             {% endfor %}
         </tbody>
index 93a5d122106f6ea162dfcd5be410fb77aa2cb750..a887500f2d8e2d14d0aeb1b4dd6e913167c1918f 100644 (file)
@@ -82,6 +82,7 @@
     </ul>
     <table>
         <tr><td colspan="6" class="tableTitle"><h3><a>Added Packages</a></h3></td></tr>
+        {% set git_web = gitweb %}
         {% if diff['added'] %}
             <tbody>
             <tr>
@@ -91,8 +92,8 @@
                 <tr>
                     <td>{{ item['newpkg']['name'] }}</td>
                     <td colspan="2">{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
-                    <td>{{ item['newpkg']['git_path'] }}</td>
-                    <td colspan="2">{{ item['newpkg']['commit_id'] }}</td>
+                    <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git">{{ item['newpkg']['git_path'] }}</a></td>
+                    <td colspan="2"><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ item['newpkg']['commit_id'] }}">{{ item['newpkg']['commit_id'] }}</a></td>
                 </tr>
             {% endfor %}
             </tbody>
                 <tr>
                     <td>{{ item['oldpkg']['name'] }}</td>
                     <td colspan="2">{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
-                    <td>{{ item['oldpkg']['git_path'] }}</td>
-                    <td colspan="2">{{ item['oldpkg']['commit_id'] }}</td>
+                    <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></td>
+                    <td colspan="2"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
                 </tr>
             {% endfor %}
             </tbody>
                     <td>
                         <ul>
                             {% if item['oldpkg']['git_path'] != item['newpkg']['git_path'] %}
-                                <li>{{ item['oldpkg']['git_path'] }}&nbsp;</li>
-                                <li>{{ item['newpkg']['git_path'] }}&nbsp;</li>
+                                <li><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a>&nbsp;</li>
+                                <li><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git">{{ item['newpkg']['git_path'] }}</a>&nbsp;</li>
                             {% else %}
-                                <li>{{ item['oldpkg']['git_path'] }}</li>
+                                <li><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></li>
                             {% endif %}
                         </ul>
                     </td>
-                    <td>{{ item['oldpkg']['commit_id'] }}</td>
-                    <td>{{ item['newpkg']['commit_id'] }}</td>
+                    <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
+                    <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ item['newpkg']['commit_id'] }}">{{ item['newpkg']['commit_id'] }}</a></td>
                     </td>
                 </tr>
             {% endfor %}
                     <td>{{ item['oldpkg']['name'] }}</td>
                     <td>{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
                     <td>{{ item['newpkg']['version']['ver'] }}-{{item['newpkg']['version']['rel']}}</td>
-                    <td>{{ item['oldpkg']['git_path'] }}</td>
-                    <td colspan="2">{{ item['oldpkg']['commit_id'] }}</td>
+                    <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></td>
+                    <td colspan="2"><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git;a=commit;h={{ item['oldpkg']['commit_id'] }}">{{ item['oldpkg']['commit_id'] }}</a></td>
                 </tr>
             {% endfor %}
             </tbody>