consolidate to single arguments file

pull/120/head
Dan Joseph 2021-11-11 18:26:07 -05:00
rodzic da96707553
commit fa5e3e1efa
5 zmienionych plików z 1777 dodań i 222 usunięć

Wyświetl plik

@ -1,10 +1,5 @@
..
AUTO-GENERATED by extract_odm_strings.py! DO NOT EDIT!
If you want to add more details to a command, create a
.rst file in arguments_edit/<argument>.rst
.. _$opt:
$ticks
$opt $opt
$ticks $ticks
@ -12,6 +7,12 @@ $parameter
$descr $descr
$include $edit
`Learn to edit <https://github.com/opendronemap/docs#how-to-make-your-first-contribution>`_ and help improve `this page <https://github.com/OpenDroneMap/docs/blob/publish/source/$editfile>`_!
.. raw:: html
<br>
<hr style="border-top: 6px double #8c8b8b">
<br>
<br>

Wyświetl plik

@ -1,13 +1,18 @@
..
AUTO-GENERATED by extract_odm_strings.py! DO NOT EDIT!
If you want to add more details to a command, edit a
.rst file in arguments_edit/<argument>.rst
#################
Options and Flags Options and Flags
----------------- #################
$arguments If you want to add more details to a command, `learn to edit <https://github.com/opendronemap/docs#how-to-make-your-first-contribution>`_ and help improve the matching file in the ``arguments_edit`` `project folder <https://github.com/OpenDroneMap/docs/tree/publish/source/arguments_edit>`_!
.. raw:: html
`Learn to edit <https://github.com/opendronemap/docs#how-to-make-your-first-contribution>`_ and help improve `this page <https://github.com/OpenDroneMap/docs/blob/publish/source/arguments.rst>`_! <br>
<hr style="border-top: 6px double #8c8b8b">
.. toctree:: <br>
:maxdepth: 1 <br>
:glob:
arguments/*

Wyświetl plik

@ -3,6 +3,7 @@
import argparse, os, urllib.request, ast, sys import argparse, os, urllib.request, ast, sys
from io import StringIO from io import StringIO
from string import Template from string import Template
from pathlib import Path
parser = argparse.ArgumentParser(description='Extract ODM strings.') parser = argparse.ArgumentParser(description='Extract ODM strings.')
parser.add_argument('input', type=str, parser.add_argument('input', type=str,
@ -31,13 +32,13 @@ class ArgumentParserStub(argparse.ArgumentParser):
for name, value in kwargs.items(): for name, value in kwargs.items():
options[args[0]][str(name)] = str(value) options[args[0]][str(name)] = str(value)
def add_mutually_exclusive_group(self): def add_mutually_exclusive_group(self):
return ArgumentParserStub() return ArgumentParserStub()
# Voodoo! :) # Voodoo! :)
# ( parse AST, extract "def config()" function, set module to only # ( parse AST, extract "def config()" function, set module to only
# contain that function, execute module in current scope, # contain that function, execute module in current scope,
# run config function) # run config function)
root = ast.parse(config_file) root = ast.parse(config_file)
new_body = [] new_body = []
@ -56,7 +57,7 @@ exec(compile(root, filename="<ast>", mode="exec"))
# Misc variables needed to get config to run # Misc variables needed to get config to run
__version__ = '?' __version__ = '?'
class context: class context:
root_path = '' root_path = ''
num_cores = 4 num_cores = 4
class io: class io:
@ -88,7 +89,7 @@ if len(options) > 0:
keys = list(options.keys()) keys = list(options.keys())
keys.sort(key=lambda a: a.replace("-", "")) keys.sort(key=lambda a: a.replace("-", ""))
with open(argstmplfile) as f: with open(argstmplfile) as f:
argstmpl = Template(f.read()) argstmpl = Template(f.read())
@ -99,14 +100,14 @@ if len(options) > 0:
# Use longest name # Use longest name
opt_name = max(arg_map + (opt_name, ), key=len) opt_name = max(arg_map + (opt_name, ), key=len)
return opt_name.replace("--", "") return opt_name.replace("--", "")
def get_opt_descr(opt): def get_opt_descr(opt):
return options[opt].get('help', '').replace("*", "\*") return options[opt].get('help', '').replace("*", "\*")
def get_opt_choices(opt): def get_opt_choices(opt):
return options[opt].get('choices', options[opt].get('metavar', '')).replace('[', '').replace(']', '').replace(',', ' | ').replace('\'', '') return options[opt].get('choices', options[opt].get('metavar', '')).replace('[', '').replace(']', '').replace(',', ' | ').replace('\'', '')
for opt in keys: for idx,opt in enumerate(keys):
opt_name = get_opt_name(opt) opt_name = get_opt_name(opt)
include_file = os.path.join(argsoutdir + "_edit", "%s.rst" % opt_name) include_file = os.path.join(argsoutdir + "_edit", "%s.rst" % opt_name)
@ -115,37 +116,27 @@ if len(options) > 0:
f.write("\n") f.write("\n")
print("Wrote %s" % include_file) print("Wrote %s" % include_file)
argument_edit = Path(include_file).read_text()
kwargs = { kwargs = {
'opt': opt_name, 'opt': opt_name,
'ticks': '`' * len(opt_name), 'ticks': '*' * len(opt_name),
'descr': get_opt_descr(opt), 'descr': get_opt_descr(opt),
'parameter': "**Options:** *%s*" % get_opt_choices(opt) if get_opt_choices(opt) else "", 'parameter': "**Options:** *%s*" % get_opt_choices(opt) if get_opt_choices(opt) else "",
'include': ".. include:: ../arguments_edit/%s" % os.path.basename(include_file), # 'include': ".. include:: ../arguments_edit/%s" % os.path.basename(include_file),
'editfile': os.path.join("arguments_edit", os.path.basename(include_file)), 'editfile': os.path.join("arguments_edit", os.path.basename(include_file)),
'edit': argument_edit,
} }
argsoutfile = os.path.join(argsoutdir, opt_name + ".rst") arg = argstmpl.substitute(**kwargs)
with open(argsoutfile, "w") as f:
f.write(argstmpl.substitute(**kwargs))
print("Wrote %s" % argsoutfile)
for opt in keys: if idx == 0:
subst += ":ref:`%s<%s>` %s\n %s\n\n" % ( header = Path(tmplfile).read_text()
get_opt_name(opt), with open(outfile, "w") as f:
get_opt_name(opt), f.write(header)
get_opt_choices(opt),
get_opt_descr(opt)
)
with open(tmplfile) as f:
tmpl = Template(f.read())
with open(outfile, "w") as f:
f.write(tmpl.substitute(arguments=subst))
print("Wrote %s" % outfile)
with open(outfile, "a") as f:
f.write(arg)
else: else:
print("No strings found") print("No strings found")

Plik diff jest za duży Load Diff

Wyświetl plik

@ -62,7 +62,7 @@ language = 'en'
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path . # This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'arguments_edit']
# The name of the Pygments (syntax highlighting) style to use. # The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx' pygments_style = 'sphinx'