diff mbox series

[cip-kernel-sec,1/3] report_affected: word-wrap for the 'description'

Message ID 20200925035927.1958987-2-daniel.sangorrin@toshiba.co.jp (mailing list archive)
State Not Applicable
Headers show
Series [cip-kernel-sec,1/3] report_affected: word-wrap for the 'description' | expand

Commit Message

Daniel Sangorrin Sept. 25, 2020, 3:59 a.m. UTC
From: Nguyen Van Hieu <hieu2.nguyenvan@toshiba.co.jp>

Currently some descriptions are quite long, and it is hard to read.
Add line-breaks so every line is at most 80 characters long.

Signed-off-by: Nguyen Van Hieu <hieu2.nguyenvan@toshiba.co.jp>
Signed-off-by: Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
---
 scripts/report_affected.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Chen-Yu Tsai Oct. 8, 2020, 7:58 a.m. UTC | #1
On Fri, Sep 25, 2020 at 12:00 PM Daniel Sangorrin
<daniel.sangorrin@toshiba.co.jp> wrote:
>
> From: Nguyen Van Hieu <hieu2.nguyenvan@toshiba.co.jp>
>
> Currently some descriptions are quite long, and it is hard to read.
> Add line-breaks so every line is at most 80 characters long.
>
> Signed-off-by: Nguyen Van Hieu <hieu2.nguyenvan@toshiba.co.jp>
> Signed-off-by: Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
> ---
>  scripts/report_affected.py | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/report_affected.py b/scripts/report_affected.py
> index a97b700..a181d97 100755
> --- a/scripts/report_affected.py
> +++ b/scripts/report_affected.py
> @@ -19,6 +19,7 @@ import kernel_sec.branch
>  import kernel_sec.issue
>  import kernel_sec.version
>
> +import textwrap
>
>  def main(git_repo, remotes, only_fixed_upstream,
>           include_ignored, show_description, *branch_names):
> @@ -136,8 +137,11 @@ def main(git_repo, remotes, only_fixed_upstream,
>          if show_description:
>              print('%s:' % branch['full_name'])
>              for cve_id in sorted_cve_ids:
> -                print(cve_id, '=>',
> -                      kernel_sec.issue.load(cve_id).get('description', 'None'))
> +                description=kernel_sec.issue.load(cve_id).get('description', 'None')
> +                wrap_description = ''
> +                for line in textwrap.wrap(description, 80, break_long_words=False):
> +                    wrap_description += line + '\n  '

I believe it would be better to include the "CVE => " string in the full text
passed to textwrap. That would make all lines properly wrapped at the given
width.

Also, textwrap can handle indentation for subsequent lines, so you don't have
to handle that yourself. And it might be easier to read if they matched up
with the beginning of the description in the first line.

Last, you could use join() to combine the lines.

So I would rewrite the part as:

    text = cve_id + ' => ' +
kernel_sec.issue.load(cve_id).get('description', 'None')
    print('\n'.join(textwrap.wrap(text, 80, subsequent_indent=' ' *
(len(cve_id) + 4), break_long_words=False)))


ChenYu
Moxa


> +                print(cve_id, '=>',wrap_description)
>          else:
>              print('%s:' % branch['full_name'], *sorted_cve_ids)
>
> --
> 2.25.1
>
>
> 
>
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#5509): https://lists.cip-project.org/g/cip-dev/message/5509
Mute This Topic: https://lists.cip-project.org/mt/77073066/4520428
Group Owner: cip-dev+owner@lists.cip-project.org
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129116/1171672734/xyzzy [patchwork-cip-dev@patchwork.kernel.org]
-=-=-=-=-=-=-=-=-=-=-=-
diff mbox series

Patch

diff --git a/scripts/report_affected.py b/scripts/report_affected.py
index a97b700..a181d97 100755
--- a/scripts/report_affected.py
+++ b/scripts/report_affected.py
@@ -19,6 +19,7 @@  import kernel_sec.branch
 import kernel_sec.issue
 import kernel_sec.version
 
+import textwrap
 
 def main(git_repo, remotes, only_fixed_upstream,
          include_ignored, show_description, *branch_names):
@@ -136,8 +137,11 @@  def main(git_repo, remotes, only_fixed_upstream,
         if show_description:
             print('%s:' % branch['full_name'])
             for cve_id in sorted_cve_ids:
-                print(cve_id, '=>',
-                      kernel_sec.issue.load(cve_id).get('description', 'None'))
+                description=kernel_sec.issue.load(cve_id).get('description', 'None')
+                wrap_description = ''
+                for line in textwrap.wrap(description, 80, break_long_words=False):
+                    wrap_description += line + '\n  '
+                print(cve_id, '=>',wrap_description)
         else:
             print('%s:' % branch['full_name'], *sorted_cve_ids)