#18 Add a add_manpage function
Merged 5 years ago by jhutar. Opened 5 years ago by dshea.
dshea/rpmfluff add_manpage  into  master

file modified
+58 -1
@@ -380,7 +380,10 @@ 

      def _get_dst_file(self, sourcesDir):

          import codecs

          dstFileName = os.path.join(sourcesDir, self.sourceName)

-         dstFile = codecs.open(dstFileName, "wb", self.encoding)

+         if isinstance(self.content, bytes):

+             dstFile = open(dstFileName, "wb")

+         else:

+             dstFile = codecs.open(dstFileName, "wb", self.encoding)

          return dstFile

  

      def write_file(self, sourcesDir):
@@ -473,6 +476,17 @@ 

  - Initial version

  """

  

+ sample_man_page = u""".TH FOO "1" "May 2009" "foo 1.00" "User Commands"

+ .SH NAME

+ foo \\- Frobnicates the doohickey

+ .SH SYNOPSIS

+ .B foo

+ [\\fIOPTION\\fR]...

+ 

+ .SH DESCRIPTION

+ A sample manpage

+ """

+ 

  def get_expected_arch():

      # FIXME: do this by directly querying rpm python bindings:

      evalArch = subprocess.check_output(['rpm', '--eval', '%{_arch}'])
@@ -1209,6 +1223,28 @@ 

          for file in contents:

              sub.section_files += '/%s/%s/%s\n' % (installPath, internalPath, file.sourceName)

  

+     def add_manpage(self,

+                     sourceFileName='foo.1',

+                     sourceFileContent=sample_man_page,

+                     installPath='usr/share/man/man1/foo.1',

+                     createParentDirs=True,

+                     subpackageSuffix=None):

+         sourceIndex = self.add_source(SourceFile(sourceFileName, sourceFileContent))

+         if createParentDirs:

+             self.create_parent_dirs(installPath)

+         self.section_install += 'cp %%{SOURCE%i} $RPM_BUILD_ROOT/%s\n' % (sourceIndex, self.escape_path(installPath))

+ 

+         # brp-compress will compress all man pages. If the man page is already

+         # compressed, it will decompress the page and recompress it.

+         (installBase, installExt) = os.path.splitext(installPath)

+         if installExt in ('.gz', '.Z', '.bz2', '.xz', '.lzma'):

+             finalPath = installBase + '.gz'

+         else:

+             finalPath = installPath + '.gz'

+ 

+         sub = self.get_subpackage(subpackageSuffix)

+         sub.section_files += '/%s\n' % finalPath

+         self.add_payload_check(finalPath, subpackageSuffix)

  

  class YumRepoBuild:

      """Class for easily creating a yum repo from a collection of RpmBuild instances"""
@@ -1839,6 +1875,27 @@ 

          srpmHdr = self.rpmbuild.get_built_srpm_header()

          self.assertEquals(3, srpmHdr[rpm.RPMTAG_EPOCH])

  

+     def test_add_manpage(self):

+         self.rpmbuild.add_manpage()

+         self.rpmbuild.make()

+ 

+     def test_add_compressed_manpage(self):

+         """Ensuring that adding an already compressed manpage works correctly"""

+         import zlib

+         compressedPage = zlib.compress(sample_man_page.encode('ascii'))

+         self.rpmbuild.add_manpage(sourceFileName='foo.1.gz',

+                                   sourceFileContent=compressedPage,

+                                   installPath='usr/share/man/man1/foo.1.gz')

+         self.rpmbuild.make()

+ 

+     def test_add_differently_compressed_manpage(self):

+         """Ensuring that a non-gzip compressed manpage is re-compressed"""

+         import bz2

+         compressedPage = bz2.compress(sample_man_page.encode('ascii'))

+         self.rpmbuild.add_manpage(sourceFileName='foo.1.bz2',

+                                   sourceFileContent=compressedPage,

+                                   installPath='usr/share/man/man1/foo.1.bz2')

+         self.rpmbuild.make()

  

  class YumRepoBuildTests(unittest.TestCase):

      def assert_is_dir(self, dirname):

This also includes a small change to SourceFile to facilitate adding pre-compressed man pages, or just binary data in general. The function itself is roughly based on one originally written by dmalcolm as part of rpmdiff.

The tests work with both python 2.7 and python 3.7.

Pull-Request has been merged by jhutar

5 years ago
Metadata