Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace wrapLines() with Python's textwrap.wrap() #1699

Closed
buhtz opened this issue Apr 23, 2024 · 0 comments · Fixed by #1702
Closed

Replace wrapLines() with Python's textwrap.wrap() #1699

buhtz opened this issue Apr 23, 2024 · 0 comments · Fixed by #1702
Assignees
Labels
GOOD FIRST ISSUE Used by 24pullrequests.com to suggest issues HELP-WANTED Used by 24pullrequests.com to suggest issues Logging & diagnostics

Comments

@buhtz
Copy link
Member

buhtz commented Apr 23, 2024

Introduction

Welcome to the project, if you pick up this Issue because of the "GOOD FIRST USE" label. You will be mentored through the process if you want. First the Issue is explained. At the end you will find some guidance for first contributors. Please do not hesitate to ask questions. Your solution don't need to be perfect.

Problem

BIT has it's own function logger.py::wrapLines() but Python offer the same functionality with textwrap.wrap().

Solution

Replace that function with textwrap.wrap(). Check via git grep where it is used in the code. It is not much. Easy to replace.

Argument new_line_indicator is used in logger.py::_do_syslog(). Use textwrap.wrap(..., subsequent_indent='CONTINUE: ') instead.

Your next steps

  1. If this is your first contribution in this project please introduce your self and tell us about your skills, wishes and plans.
  2. Read the existing contributors documentation.
  3. We can develop the next steps in the further discussion. Don't hesitate to ask.

Related code

backintime/common/logger.py

Lines 149 to 184 in 5aa0746

def wrapLine(msg, size=950, delimiters='\t ', new_line_indicator = 'CONTINUE: '):
"""
Wrap line ``msg`` into multiple lines with each shorter than ``size``. Try
to break the line on ``delimiters``. New lines will start with
``new_line_indicator``.
Args:
msg (str): string that should get wrapped
size (int): maximum length of returned strings
delimiters (str): try to break ``msg`` on these characters
new_line_indicator (str): start new lines with this string
Yields:
str: lines with max ``size`` length
"""
# TODO Use "textwrap.wrap" instead (https://docs.python.org/3/library/textwrap.html)
# (which may change the output formatting and may affect unit tests then)
# To avoid duplicated argument values in calls this function could
# act as a wrapper-
if len(new_line_indicator) >= size - 1:
new_line_indicator = ''
while msg:
if len(msg) <= size:
yield(msg)
break
else:
line = ''
for look in range(size-1, size//2, -1):
if msg[look] in delimiters:
line, msg = msg[:look+1], new_line_indicator + msg[look+1:]
break
if not line:
line, msg = msg[:size], new_line_indicator + msg[size:]
yield(line)

@buhtz buhtz added this to the Upcoming release (1.5.0) milestone Apr 23, 2024
@buhtz buhtz added Logging & diagnostics GOOD FIRST ISSUE Used by 24pullrequests.com to suggest issues HELP-WANTED Used by 24pullrequests.com to suggest issues labels Apr 23, 2024
@buhtz buhtz self-assigned this Apr 23, 2024
cornpaffies added a commit to cornpaffies/backintime that referenced this issue Apr 23, 2024
buhtz pushed a commit that referenced this issue May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GOOD FIRST ISSUE Used by 24pullrequests.com to suggest issues HELP-WANTED Used by 24pullrequests.com to suggest issues Logging & diagnostics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant