From 97cd56d2d7e83f2690aab566773d0cc97ea7048a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Aug 19 2019 18:55:37 +0000 Subject: Use textwrap to format package description. --- diff --git a/r2spec/spec.py b/r2spec/spec.py index 9150770..f8f3283 100644 --- a/r2spec/spec.py +++ b/r2spec/spec.py @@ -25,28 +25,11 @@ import datetime import os import re import sys +import textwrap from jinja2 import Template from r2spec import get_logger, get_rpm_tag, R2specError -def format_description(description): - """ Format the description as required by rpm """ - step = 75 - cnt = 0 - out = [] - char = 0 - while cnt < len(description) and char < description.rfind(" "): - if len(description[cnt:]) >= step: - char = description[cnt: cnt + step].rfind(" ") + cnt - out.append(description[cnt: char]) - cnt = char + 1 - else: - out.append(description[cnt:]) - cnt += len(description[cnt:]) - - return "\n".join(out) - - def format_dependencies(dependencies): """ Format the dependencies cleanning them as much as possible for rpm. """ @@ -166,8 +149,9 @@ class Spec: self.package.get('Suggests')) else: self.__dict['suggests'] = "" - self.__dict['description'] = format_description( - self.package.get('Description')) + self.__dict['description'] = textwrap.fill( + self.package.get('Description'), + width=75) self.__dict['date'] = datetime.datetime.now( ).strftime("%a %b %d %Y") self.__dict['name'] = self.settings.get('packager')