From 8ff8f1827ea513ba166f5ea4e24dbdeea983d452 Mon Sep 17 00:00:00 2001 From: Erik Bjorge Date: Mon, 4 Mar 2019 12:20:47 -0800 Subject: [PATCH] Updated processing of options documentation With the switch to argparse a number of small issues were seen in the exported PDF. This script cleans up some of the formatting issues by moving the options output to a preformatted/code section. Signed-off-by: Erik Bjorge --- docs/create_manual.cmd | 2 ++ docs/sphinx/options.py | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 docs/sphinx/options.py diff --git a/docs/create_manual.cmd b/docs/create_manual.cmd index b607679f..85f6e120 100644 --- a/docs/create_manual.cmd +++ b/docs/create_manual.cmd @@ -13,6 +13,8 @@ call python chipsec_main.py -h > %TARGET%\docs\sphinx\options.rst popd pushd %TARGET%\docs\sphinx +:: Update options.rst to make it a preformatted block +call python options.py call sphinx-apidoc -e -f -T -o modules %TARGET% call python removeStrRst.py diff --git a/docs/sphinx/options.py b/docs/sphinx/options.py new file mode 100644 index 00000000..16d67b2d --- /dev/null +++ b/docs/sphinx/options.py @@ -0,0 +1,48 @@ +#CHIPSEC: Platform Security Assessment Framework +#Copyright (c) 2019, Intel Corporation +# +#This program is free software; you can redistribute it and/or +#modify it under the terms of the GNU General Public License +#as published by the Free Software Foundation; Version 2. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program; if not, write to the Free Software +#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#Contact information: +#chipsec@intel.com +# + +import os +import sys + +cwd = os.path.abspath(os.getcwd()) +options_file = os.path.join(cwd, 'options.rst') + +if not os.path.isfile(options_file): + sys.exit(255) + +with open(options_file, 'r') as f: + lines = f.readlines() + +new_lines = [] +new_lines.append('::\n') +new_lines.append('\n') +for line in lines: + if '--' in line and line.lstrip().find('--') != 0: + slice_location = line.find('--') + new_lines.append(' {}\n'.format(line[:slice_location])) + new_lines.append(' {}'.format(line[slice_location:])) + else: + new_lines.append(' {}'.format(line)) +new_lines.append('\n') + +with open(options_file, 'w') as f: + f.writelines(new_lines) + +sys.exit(0)