Skip to content
Permalink
Browse files

Factorize rest markup removal code

* used from man pages creation script
* used in command help
  • Loading branch information...
arnaudveron committed Aug 9, 2019
1 parent 1f133d6 commit f5f270584efb3bd1225630e65b28d9ac11708d64
Showing with 11 additions and 3 deletions.
  1. +3 −2 bin/pkg/make_man
  2. +3 −1 lib/rcOptParser.py
  3. +5 −0 lib/rcUtilities.py
@@ -12,6 +12,8 @@ pathman = os.path.join(pathsvc, "usr", "share", "man", "man1")

sys.path = [pathlib] + sys.path

from rcUtilities import wipe_rest_markup

class ManPageFormatter(optparse.HelpFormatter):
def __init__(self, indent_increment=2, max_help_position=24,
width=None, short_first=1):
@@ -90,8 +92,7 @@ class ManPageFormatter(optparse.HelpFormatter):
commands = re.sub(r'^(\w.+)\n(-+)', lambda pat: "\\fR"+pat.group(1).upper()+"\\fP", commands, flags=re.MULTILINE)

# remove rest markup
commands = re.sub(r':(cmd|kw|opt|c-.*?):`(.*?)`', lambda pat: "'"+pat.group(2)+"'", commands, flags=re.MULTILINE)
commands = re.sub(r'``(.*?)``', lambda pat: "'"+pat.group(1)+"'", commands, flags=re.MULTILINE)
commands = wipe_rest_markup(commands)

if len(commands) > 0:
ret.append('.SH COMMANDS\n%s\n' % commands)
@@ -13,9 +13,10 @@
import optparse
import textwrap
import rcColor
from rcUtilities import term_width, is_string
from rcUtilities import term_width, is_string, wipe_rest_markup
import rcExceptions as ex
import svc
import re

class OsvcHelpFormatter(optparse.TitledHelpFormatter):
def format_option(self, option):
@@ -181,6 +182,7 @@ def format_action(self, section, action, options=True):
if options:
desc += self.format_options(section, action)

desc = wipe_rest_markup(desc)
desc += '\n'
return desc

@@ -1147,6 +1147,11 @@ def daemon_test_lock():
lock.unlock(lockfd)
return False

def wipe_rest_markup(payload):
payload = re.sub(r':(cmd|kw|opt|c-.*?):`(.*?)`', lambda pat: "'"+pat.group(2)+"'", payload, flags=re.MULTILINE)
payload = re.sub(r'``(.*?)``', lambda pat: "'"+pat.group(1)+"'", payload, flags=re.MULTILINE)
return payload

#############################################################################
#
# Namespaces functions

0 comments on commit f5f2705

Please sign in to comment.
You can’t perform that action at this time.