#20 Use textwrap to format package description.
Opened 9 months ago by qulogic. Modified 9 months ago
qulogic/r2spec textwrap  into  master

file modified
+4 -20

@@ -25,28 +25,11 @@ 

  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 @@ 

                  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')

No need for home-grown text wrapping that sometimes gets into a loop.

Fixes #18.

Metadata