Commit 6c6a0f80 authored by Philippe Mallet-Ladeira's avatar Philippe Mallet-Ladeira Committed by Julien Michel

BUG: wrong manpath value

The `man` command expect manpages to be in a `man#` directory where `#` refers
to the section number of the manpaga. But the directory declared in the
`$MANPATH` environment variable has to be its parent directory. In this
commit, we check if the directory is of the `man#` form and create it as a
subdirectory if not.

Note that the parent directory can also contains directory for different
languages:

/usr/share/man
├── ca
│   ├── man1
│   ├── man3
│   ├── man7
│   └── man8
├── fr
│   ├── man1
│   ├── man3
│   ├── man5
│   ├── man6
│   ├── man7
│   └── man8
├── fr.ISO8859-1
│   └── man1
├── fr.UTF-8
│   └── man1
├── man0
├── man1
├── man2
├── man3
├── man4
├── man5
├── man6
├── man7
├── man8
├── mann
└── zh_TW
    ├── man1
    ├── man5
    └── man8

--HG--
branch : manpages
parent 9f45455d
......@@ -334,14 +334,30 @@ class ManpageGenerator(object):
Returns: None
"""
self.output_dir = output_dir
self._output_dir = os.path.normpath(output_dir)
self.setup_output_dir()
self.application_name = application_name
self.exec_name = '_'.join(('otbcli', application_name))
self.basename = '.'.join((self.exec_name, '1', 'gz'))
self.filename = os.path.join(output_dir, self.basename)
self.filename = os.path.join(self.output_dir, self.basename)
self.version = "5.0" # TODO: find it somehow in the code
self.application = otb_create_application(application_name)
def setup_output_dir(self):
""" Assign output_dir member value
Create `man1` subdir if does not exist before
"""
basename = os.path.basename(self._output_dir)
if basename == "man1":
self.output_dir = self._output_dir
else:
man_dir = os.path.join(self._output_dir, "man1")
if not os.path.exists(man_dir):
os.makedirs(man_dir)
self.output_dir = man_dir
def _format(self, string):
""" Replace some caraters to be well processed by troff
......
# encoding: utf-8
import logging
import os
from operator import attrgetter
from collections import namedtuple
......@@ -349,14 +350,17 @@ class TestManpageGenerator:
def test_init(self, tmpdir):
from generateAppliDoc import ManpageGenerator
import otbApplication
output_dir = tmpdir
_output_dir = tmpdir
output_dir = _output_dir.join('man1')
application_name = 'my-app'
exec_name = '_'.join(('otbcli', application_name))
basename = '.'.join((exec_name, '1', 'gz'))
filename = tmpdir.join(basename)
generator = ManpageGenerator(output_dir.strpath, application_name)
filename = output_dir.join(basename)
generator = ManpageGenerator(_output_dir.strpath, application_name)
# FIXME: returns None if application_name not real otb application
otb = otbApplication.Registry.CreateApplication(application_name)
assert generator._output_dir == os.path.normpath(_output_dir.strpath)
assert generator.output_dir == output_dir
assert generator.application_name == application_name
assert generator.exec_name == exec_name
......@@ -365,6 +369,22 @@ class TestManpageGenerator:
assert generator.version == "5.0"
assert generator.application == otb
@pytest.mark.parametrize("output_dir, expected",
[("tmpdir", "tmpdir.join('man1')"),
("tmpdir.ensure_dir('man1')",
"tmpdir.join('man1')")],
ids=["no man1 subdir", "man1 subdir"])
def test_setup_output_dir(self, output_dir, expected, tmpdir):
from generateAppliDoc import ManpageGenerator
output_dir = eval(output_dir)
expected = eval(expected)
application_name = 'my-app'
generator = ManpageGenerator(output_dir.strpath, application_name)
generator._output_dir = output_dir.strpath # Reset value
generator.setup_output_dir()
assert expected.check()
assert generator.output_dir == expected.strpath
@pytest.mark.parametrize("input_string, expected",
[("bla-bla", "bla\-bla"),
("bla\nbla", "bla\n.br\nbla")],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment