Skip to content

Commit

Permalink
Update to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HubTou authored Mar 5, 2022
1 parent 2e6ec72 commit 74d094f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ libmanconf — library for handling man(1) and manpath(1) configuration files
## SYNOPSIS
import **libmanconf**

String, String, List *libmanconf*.**read_man_conf_files**(Integer *debug_level* = 0)
String, String, List *libmanconf*.**read_man_conf_files**(Integer *debug_level* = 0, String *manpath_so_far* = '')

## DESCRIPTION
The **read_man_conf_files()** function reads the configuration files located at "/etc/man.conf" and "/usr/local/etc/man.d/\*.conf"
Expand All @@ -18,6 +18,9 @@ to configure the manual search path, locales and utility set used by man(1) and
The function takes an optional argument *debug_level* with an integer value from 0 (default) to 3,
to print increasingly detailed information on standard error output.

It can also take another optional argument *manpath_so_far* with a colon separated string of already added directories to the manual path,
in order to check for duplicate entries.

It returns a triplet consisting of:
* a string containing colon separated existing MANPATH directories
* a string containing colon separated locales (for example, "fr_FR.UTF-8:ja_JP.eucJP")
Expand Down
8 changes: 7 additions & 1 deletion man/libmanconf.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Dd February 28, 2022
.Dd March 5, 2022
.Dt LIBMANCONF 3
.Os
.Sh NAME
Expand All @@ -10,6 +10,7 @@
.Ft String, String, List
.Fo libmanconf.read_man_conf_files
.Fa "Integer debug_level = 0"
.Fa "String manpath_so_far = ''"
.Fc
.Sh DESCRIPTION
The
Expand All @@ -27,6 +28,11 @@ The function takes an optional argument
with an integer value from 0 (default) to 3,
to print increasingly detailed information on standard error output.
.Pp
It can also take another optional argument
.Fa manpath_so_far
with a colon separated string of already added directories to the manual path,
in order to check for duplicate entries.
.Pp
It returns a triplet consisting of:
.Bl -bullet
.It
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = pnu_libmanconf
description = library for handling man(1) and manpath(1) configuration files
long_description = file: README.md
long_description_content_type = text/markdown
version = 1.0.1
version = 1.1.0
license = BSD 3-Clause License
license_files = License
author = Hubert Tournier
Expand Down
48 changes: 34 additions & 14 deletions src/libmanconf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import libpnu

# Version string used by the what(1) and ident(1) commands:
ID = "@(#) $Id: libmanconf - library for handling man(1) and manpath(1) configuration files v1.0.1 (March 5, 2022) by Hubert Tournier $"
ID = "@(#) $Id: libmanconf - library for handling man(1) and manpath(1) configuration files v1.1.0 (March 5, 2022) by Hubert Tournier $"


################################################################################
def _read_configuration_file(filename, debug_level):
def _read_configuration_file(filename, debug_level, manpath_so_far):
"""Read a man(1) and manpath(1) configuration file"""
config = ""
paths = ""
Expand Down Expand Up @@ -46,19 +46,27 @@ def _read_configuration_file(filename, debug_level):
print("-- MANPATH", file=sys.stderr)
if len(parts) == 2:
if os.path.isdir(parts[1]):
if debug_level > 0:
print("-- Adding %s to manpath" % parts[1], file=sys.stderr)
if paths:
paths += ":" + parts[1]
if parts[1] in manpath_so_far.split(os.pathsep):
if debug_level > 0:
print("-- Skipping duplicate manpath entry %s" % parts[1], file=sys.stderr)
else:
paths = parts[1]
if debug_level > 0:
print("-- Adding %s to manpath" % parts[1], file=sys.stderr)
if paths:
paths += os.pathsep + parts[1]
else:
paths = parts[1]
if manpath_so_far:
manpath_so_far += os.pathsep + parts[1]
else:
manpath_so_far = parts[1]

elif parts[0] == "MANLOCALE":
if debug_level > 2:
print("-- MANLOCALE", file=sys.stderr)
if len(parts) == 2:
if locales:
locales += ":" + parts[1]
locales += os.pathsep + parts[1]
else:
locales = parts[1]

Expand All @@ -83,7 +91,7 @@ def _read_configuration_file(filename, debug_level):


################################################################################
def read_man_conf_files(debug_level = 0):
def read_man_conf_files(debug_level=0, manpath_so_far=""):
"""Return man(1) and manpath(1) configuration files data"""
manconfig = ""
manpaths = ""
Expand All @@ -92,14 +100,18 @@ def read_man_conf_files(debug_level = 0):

if os.path.isdir("/etc"):
manconfig, manpaths, manlocales, manprocessors = _read_configuration_file(
"/etc/man.conf", debug_level
"/etc/man.conf",
debug_level,
manpath_so_far,
)
else:
dir_list = libpnu.locate_directory("etc")
for directory in dir_list:
if os.path.isfile(directory + os.sep + "man.conf"):
manconfig, manpaths, manlocales, manprocessors = _read_configuration_file(
directory + os.sep + "man.conf", debug_level
directory + os.sep + "man.conf",
debug_level,
manpath_so_far,
)
break

Expand Down Expand Up @@ -128,17 +140,25 @@ def read_man_conf_files(debug_level = 0):
for root, _, files in os.walk(directory):
for file in files:
if file.endswith(extension):
complete_manpath = manpath_so_far
if complete_manpath:
complete_manpath += os.pathsep + manpaths
else:
complete_manpath = manpaths

_, paths, locales, processors = _read_configuration_file(
root + os.sep + file, debug_level
root + os.sep + file,
debug_level,
complete_manpath,
)
if paths:
if manpaths:
manpaths += ":" + paths
manpaths += os.pathsep + paths
else:
manpaths = paths
if locales:
if manlocales:
manlocales += ":" + locales
manlocales += os.pathsep + locales
else:
manlocales = locales
if processors:
Expand Down

0 comments on commit 74d094f

Please sign in to comment.