1. Add diff type - commits 54/277354/1
authorsk7.park <sk7.park@samsung.com>
Tue, 5 Jul 2022 10:45:28 +0000 (19:45 +0900)
committersk7.park <sk7.park@samsung.com>
Tue, 5 Jul 2022 10:45:28 +0000 (19:45 +0900)
2. Fix variable error in image diff

Change-Id: I91975f5a69f081302404b7411a7a1abae2e540a6

snapdiff/__init__.py
snapdiff/image.py
snapdiff/templates/commit_diff.csv [new file with mode: 0644]
snapdiff/templates/commit_diff.html [new file with mode: 0644]

index f0b28e72c2ca5a341d1accb8df75201361d38d63..b68ee4a2885363dbb0dc58bdc87419808c047dea 100644 (file)
@@ -68,6 +68,8 @@ def diff_to_json(old_url, new_url, **kwargs):
         old, new = Repo(old_url).packages, Repo(new_url).packages
     elif style == 'image':
         old, new = packages(old_url), packages(new_url)
+    elif style == 'commit':
+        old, new = Repo(old_url).packages, Repo(new_url).packages
     else:
         return
 
@@ -104,10 +106,23 @@ def diff_to_json(old_url, new_url, **kwargs):
         data = []
         for idx in range(1, len(sp), 2):
             l = sp[idx].split("<$^=->")
-            data.append({"commit_id": escape_html(l[0]),
-                         "committer": escape_html(l[1]),
-                         "commit_date": escape_html(l[2]),
-                         "commit_log": {'html':escape_html_newline(escape_html(l[3])), 'raw':escape_html(l[3])}})
+            if style != 'commit':
+                data.append({"commit_id": escape_html(l[0]),
+                             "committer": escape_html(l[1]),
+                             "commit_date": escape_html(l[2]),
+                             "commit_log": {'html':escape_html_newline(escape_html(l[3])), 'raw':escape_html(l[3])}})
+            else:
+                committer = escape_html(l[1])
+                found = re.search('&lt;(.+?)&gt;', committer)
+                if found:
+                    committer = found.group(1)
+                committer = committer.split('@')[0]
+                # if (committer.find('&lt;') != -1) and (committer.find('&gt;') != -1):
+                #    committer = committer.split('&lt;')[-1].split('&gt;')[0].replace('@samsung.com','')
+                data.append({"commit_id": escape_html(l[0])[:7],
+                             "committer": committer,
+                             "commit_date": escape_html(l[2]),
+                             "commit_log": {'html':escape_html_newline(escape_html(l[3])), 'raw':escape_html(l[3])}})
         f.close()
         return data
 
@@ -174,6 +189,7 @@ def diff_to_json(old_url, new_url, **kwargs):
               'removed': [],
               'modified': [],
               'rebuilded': [],
+              'count': {'added' : 0, 'removed': 0, 'modified': 0, 'rebuilded': 0},
             }}
     #-----------------------------------------------------------------------------
     added_p = {}
@@ -202,13 +218,13 @@ def diff_to_json(old_url, new_url, **kwargs):
 
             p = {'oldpkg': None,
                  'newpkg': {
-                     'name': ','.join(ps),
+                     'name': ','.join(ps) if style != 'commit' else _pp.name,
                      'version': {
                          'epoch': _p.version.epoch,
                          'rel': _p.version.rel,
                          'ver': _p.version.ver,
                      },
-                 'git_path': _git_path,
+                 'git_path': _git_path.split(':/')[-1],
                  'commit_id': _commit_id
                  },
                  'codediff': _codediff,
@@ -242,13 +258,13 @@ def diff_to_json(old_url, new_url, **kwargs):
 
             obj['diff']['removed'].append(
                     {'oldpkg': {
-                        'name': ','.join(ps),
+                        'name': ','.join(ps) if style != 'commit' else _pp.name,
                         'version': {
                             'epoch': _p.version.epoch,
                             'rel': _p.version.rel,
                             'ver': _p.version.ver,
                             },
-                        'git_path': _git_path,
+                        'git_path': _git_path.split(':/')[-1],
                         'commit_id': _commit_id
                         },
                         'newpkg': None,
@@ -285,7 +301,7 @@ def diff_to_json(old_url, new_url, **kwargs):
             for _old, _new in modified_p[_git_path][_version]:
                 ps.append('.'.join([_old.name,_old.arch]))
 
-            names = ','.join(ps)
+            names = ','.join(ps) if style != 'commit' else _old.name
             obj['diff']['modified'].append(
                     {'oldpkg': {
                         'name': names,
@@ -294,7 +310,7 @@ def diff_to_json(old_url, new_url, **kwargs):
                             'rel': _old.version.rel,
                             'ver': _old.version.ver,
                             },
-                        'git_path': _old_git_path,
+                        'git_path': _old_git_path.split(':/')[-1],
                         'commit_id': _old_commit_id
                         },
                         'newpkg':{
@@ -304,7 +320,7 @@ def diff_to_json(old_url, new_url, **kwargs):
                                 'rel': _new.version.rel,
                                 'ver': _new.version.ver,
                                 },
-                            'git_path': _new_git_path,
+                            'git_path': _new_git_path.split(':/')[-1],
                             'commit_id': _new_commit_id
                             },
                         'codediff': _codediff,
@@ -364,6 +380,13 @@ def diff_to_json(old_url, new_url, **kwargs):
                         'codediff': _codediff,
                         })
 
+
+    idxs = ['added', 'removed', 'modified', 'rebuilded']
+    for idx in idxs:
+        for item in obj['diff'][idx]:
+            if 'commit_log' in item:
+                obj['diff']['count'][idx] += len(item['commit_log'])
+
     #-----------------------------------------------------------------------------
     #obj = {style: {'old': old_url, 'new': new_url},
             #'diff': {
@@ -491,6 +514,8 @@ def diff_to_csv(old_url, new_url, **kwargs):
         return output_html('diff.csv', **context)
     elif style == 'image':
         return output_html('image_diff.csv', **context)
+    elif style == 'commit':
+        return output_html('commit_diff.csv', **context)
 
 def diff_to_html(old_url, new_url, **kwargs):
     """Output diffs' html format.
@@ -519,10 +544,13 @@ def diff_to_html(old_url, new_url, **kwargs):
         'filename': diff_name,
         'gitweb': data['gitweb']
         }
+
     if style == 'repo':
         return output_html('diff.html', **context)
     elif style == 'image':
         return output_html('image_diff.html', **context)
+    elif style == 'commit':
+        return output_html('commit_diff.html', **context)
 
 def diff_to_dist(old_url, new_url, dist_path, **kwargs):
     """Create a dist-dir of diffs, contains html and css.
@@ -559,7 +587,7 @@ def diff_to_dist(old_url, new_url, dist_path, **kwargs):
         fname.write(output)
 
     output = diff_to_csv(old_url, new_url, style=kwargs.get('style'), diff_name=diff_name)
-    with io.open(os.path.join(dist_path, '%s.csv' % diff_name), 'w', encoding='utf-8', errors='ignore') as fname:
+    with io.open(os.path.join(dist_path, '%s.csv' % diff_name), 'w', encoding='utf-8-sig', errors='ignore') as fname:
         fname.write(output)
     return dist_path
 
index 0219e75a783c6b10b021dfe42aefccf7e1232350..ccc8ad75d0644f49f3d9e270bbb8e30b26f8a894 100644 (file)
@@ -19,7 +19,7 @@ def _get_file(url, suffix='.ks'):
             lines = response.content.split('\n')
             for line in lines:
                 if suffix in line:
-                    target = line.split('*')[-1]
+                    target = line.split('*')[-1].split(' ')[-1]
                     f_response = requests.get(url + '/' + target)
                     if f_response.status_code == 200:
                         # use StringIO to keep wrapped lines
@@ -153,9 +153,11 @@ def packages(url):
         if line.strip():
             name_arch, version, vcs = line.strip().split()
             name = name_arch.split('.')[0]
+            arch = name_arch.split('.')[1]
             setattr(packages_info, name, [])
             package_info = JsonDict()
             package_info.name = name
+            package_info.arch = arch
             package_info.version = JsonDict()
             ver, rel = version.split('-')
             package_info.version.epoch = 0 # we can't get epoch, so give 0.
diff --git a/snapdiff/templates/commit_diff.csv b/snapdiff/templates/commit_diff.csv
new file mode 100644 (file)
index 0000000..de65774
--- /dev/null
@@ -0,0 +1,36 @@
+Difference between {{old['name']}} and {{new['name']}}
+
+Added Commits: {{ diff['count']['added'] }}
+Removed Packages: {{ diff['removed']|count }}
+Modified Commits: {{ diff['count']['modified'] }}
+
+Added Packages,{% if diff['added'] %}
+Package,Git Path,CommitId,Committer,CommitDate,CommitLog
+  {%- for item in diff['added'] -%}
+    {%- for commit_item in item['commit_log'] %}
+"{{ item['newpkg']['name'] }}","{{ item['newpkg']['git_path'] }}","{{commit_item['commit_id']}}","{{commit_item['committer']}}","{{commit_item['commit_date']}}","{{commit_item['commit_log']['raw']}}"
+    {%- endfor -%}
+  {%- endfor -%}
+{%- endif %}
+
+Removed Packages,{% if diff['removed'] %}
+Package,Version,Git Path,CommitId
+  {%- for item in diff['removed'] %}
+"{{ item['oldpkg']['name'] }}","{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}","{{ item['oldpkg']['git_path'] }}","{{ item['oldpkg']['commit_id'] }}"
+  {%- endfor -%}
+{%- endif %}
+
+Modified Packages,{% if diff['modified'] %}
+Package,Git Path,CommitId,Committer,CommitDate,CommitLog
+  {%- for item in diff['modified'] -%}
+  {%- if item['oldpkg']['git_path'] != item['newpkg']['git_path'] -%}
+    {%- set git_path = item['oldpkg']['git_path'] + "-" + item['newpkg']['git_path'] -%}
+  {%- else -%}
+    {%- set git_path = item['oldpkg']['git_path'] -%}
+  {%- endif %}
+    {%- for commit_item in item['commit_log'] %}
+"{{ item['oldpkg']['name'] }}","{{ git_path }}","{{commit_item['commit_id']}}","{{commit_item['committer']}}","{{commit_item['commit_date']}}","{{commit_item['commit_log']['raw']}}"
+    {%- endfor -%}
+  {%- endfor -%}
+{%- endif %}
+
diff --git a/snapdiff/templates/commit_diff.html b/snapdiff/templates/commit_diff.html
new file mode 100644 (file)
index 0000000..40d25eb
--- /dev/null
@@ -0,0 +1,124 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+    <link href="./css/html-reset.css" media="screen" rel="stylesheet" type="text/css" />
+    <link href="./css/layout-liquid.css" media="screen" rel="stylesheet" type="text/css" />
+    <link href="./css/tizen.css" media="screen" rel="stylesheet" type="text/css" />
+    <link href="./css/style.css" media="screen" rel="stylesheet" type="text/css" />
+    <link href="./css/shCore.css" rel="stylesheet" type="text/css" />
+    <link href="./css/shThemeDefault.css" rel="stylesheet" type="text/css" />
+    <link href="./css/diff.css" rel="stylesheet" type="text/css" />
+
+<script>
+function toggle_show(table_id, button) {
+  var obj = document.getElementById(table_id);
+  if( obj.style.display == 'none' ) {
+    obj.style.display = "";
+    button.innerHTML="-";
+  } else {
+    obj.style.display = "none";
+    button.innerHTML="+";
+  }
+}
+
+</script>
+</head>
+<body>
+    <div id="page-wrapper">
+      <div id="page">
+        <div id="header">
+          <div class="section clearfix">
+            <h1 id="logo">
+              <a href="http://www.tizen.org"><img alt="Tizen-logo" src="./img/tizen-logo.png" width="180px" height="50px"></a>
+            </h1>
+          </div>
+        </div>
+      </div>
+    </div>
+    <h1>
+        Difference and Changelogs Overview
+    </h1>
+    <a href="index.html">Go back</a>...<br>
+    <a href="{{filename}}.csv">csv format</a>...<br>
+    <p>Difference between
+        <a href="{{old['url']}}">{{ old['name'] }}</a> and <a href="{{new['url']}}">{{ new['name'] }}</a>
+    </p>
+    <h3>Highlights</h3>
+    <ul>
+        <li><a href="#added">Added Commits: {{ diff['count']['added'] }}</a></li>
+        <li><a href="#removed">Removed Packages: {{ diff['removed']|count }}</a></li>
+        <li><a href="#modified">Modified Commits: {{ diff['count']['modified'] }}</a></li>
+    </ul>
+    <table id='data_table'>
+        <tr><td colspan="8" id='added' class="tableTitle"><h3><a>Added Packages</a></h3></td></tr>
+        {% set git_web = gitweb %}
+        {% if diff['added'] %}
+            <tbody>
+            <tr>
+                <th>Package</th><th>Git Path</th><th>CommitId</th><th>Committer</th><th>CommitDate</th><th width='50%'>CommitLog</th>
+            </tr>
+            {% for item in diff['added'] %}
+                {% for commit_item in item['commit_log'] %}
+                <tr>
+                    <td>{{ item['newpkg']['name'] }}</td>
+                    <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git">{{ item['newpkg']['git_path'] }}</a></td>
+                    <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ commit_item['commit_id'] }}">{{ commit_item['commit_id'] }}</a></td>
+                    <td>{{ commit_item['committer'] }}</td>
+                    <td>{{ commit_item['commit_date'] }}</td>
+                    <td>{{ commit_item['commit_log']['html'] }}</td>
+                </tr>
+                {% endfor %}
+            {% endfor %}
+            </tbody>
+        {% endif %}
+        <tr><td colspan="8" id='removed' class="tableTitle"><h3><a>Removed Packages</a></h3></td></tr>
+        {% if diff['removed'] %}
+         <tbody>
+            <tr>
+              <th>Package</th><th colspan="2">Version</th><th>GitPath</th><th colspan="3">CommitId</th>
+            </tr>
+            {% for item in diff['removed'] %}
+                <tr>
+                    <td>{{ item['oldpkg']['name'] }}</td>
+                    <td colspan="2">{{ item['oldpkg']['version']['ver'] }}-{{item['oldpkg']['version']['rel']}}</td>
+                    <td><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></td>
+                    <td colspan="3"><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>
+        {% endif %}
+        <tr><td colspan="8" id='modified' class="tableTitle"><h3><a>Modified Packages</a></h3></td></tr>
+        {% if diff['modified'] %}
+            <tbody>
+            <tr>
+                <th>Package</th><th>Git Path</th><th>CommitId</th><th>Committer</th><th>CommitDate</th><th width='50%'>CommitLog</th>
+            </tr>
+            {% for item in diff['modified'] %}
+                {% for commit_item in item['commit_log'] %}
+                <tr>
+                    <td>{{ item['oldpkg']['name'] }}</td>
+                    <td>
+                        <ul>
+                            {% if item['oldpkg']['git_path'] != item['newpkg']['git_path'] %}
+                                <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><a href="{{ git_web['old'] }}?p={{ item['oldpkg']['git_path'] }}.git">{{ item['oldpkg']['git_path'] }}</a></li>
+                            {% endif %}
+                        </ul>
+                    </td>
+                    <td><a href="{{ git_web['new'] }}?p={{ item['newpkg']['git_path'] }}.git;a=commit;h={{ commit_item['commit_id'] }}">{{ commit_item['commit_id'] }}</a></td>
+                    <td>{{ commit_item['committer'] }}</td>
+                    <td>{{ commit_item['commit_date'] }}</td>
+                    <td>{{ commit_item['commit_log']['html'] }}</td>
+                </tr>
+                {% endfor %}
+            {% endfor %}
+            </tbody>
+        {% endif %}
+    </table>
+</body>
+
+</html>
+