diff options
author | Matthew Peveler <matt.peveler@gmail.com> | 2021-01-29 13:16:29 +0000 |
---|---|---|
committer | Matthew Peveler <matt.peveler@gmail.com> | 2021-01-29 13:16:29 +0000 |
commit | 8ecac1e77d13417343fe5ce6405c245d96229a18 (patch) | |
tree | 25cd4e63c1d4cbd968bb5d7f75b41697169e04f3 | |
parent | 661d42a0441165cd6b3a19d65d4c38d4ed25fea9 (diff) | |
download | asciidoc-py3-8ecac1e77d13417343fe5ce6405c245d96229a18.tar.gz |
run a2x through cli method of asciidoc
Signed-off-by: Matthew Peveler <matt.peveler@gmail.com>
-rw-r--r-- | asciidoc/a2x.py | 21 | ||||
-rw-r--r-- | asciidoc/asciidoc.py | 9 | ||||
-rwxr-xr-x | tests/testasciidoc.py | 1 |
3 files changed, 20 insertions, 11 deletions
diff --git a/asciidoc/a2x.py b/asciidoc/a2x.py index 756ae96..d55eeda 100644 --- a/asciidoc/a2x.py +++ b/asciidoc/a2x.py @@ -124,6 +124,16 @@ def verbose(msg): infomsg(msg) +def flatten(array): + ret = [] + for x in array: + if isinstance(x, (list, tuple)): + ret += x + else: + ret.append(x) + return ret + + class AttrDict(dict): """ Like a dictionary except values can be accessed as attributes i.e. obj.foo @@ -442,9 +452,8 @@ class A2X(AttrDict): Load a2x configuration file from default locations and --conf-file option. ''' - global ASCIIDOC CONF_FILE = 'a2x.conf' - a2xdir = os.path.dirname(os.path.realpath(__file__)) + a2xdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resources') conf_files = [] # From a2x.py directory. conf_files.append(os.path.join(a2xdir, CONF_FILE)) @@ -546,7 +555,7 @@ class A2X(AttrDict): self.asciidoc_opts.append(('--attribute', attr)) # self.xsltproc_opts += ' --nonet' if self.verbose: - self.asciidoc_opts.append((' --verbose')) + self.asciidoc_opts.append(('--verbose',)) self.dblatex_opts += ' -V' if self.icons or self.icons_dir: params = [ @@ -700,8 +709,7 @@ class A2X(AttrDict): options.append(('--backend', 'docbook')) options.append(('-a', 'a2x-format=%s' % self.format)) options.append(('--out-file', docbook_file)) - asciidoc.reset_asciidoc() - asciidoc.execute('asciidoc', options, [self.asciidoc_file]) + asciidoc.cli(flatten(['asciidoc'] + options + [self.asciidoc_file])) if not self.no_xmllint and XMLLINT: shell('"%s" --nonet --noout --valid "%s"' % (XMLLINT, docbook_file)) @@ -877,8 +885,7 @@ class A2X(AttrDict): options.append(('-b', 'html4')) options.append(('-a', 'a2x-format=%s' % self.format)) options.append(('-o', html_file)) - asciidoc.reset_asciidoc() - asciidoc.execute('asciidoc', options, [self.asciidoc_file]) + asciidoc.cli(flatten(['asciidoc'] + options + [self.asciidoc_file])) cmd = '"%s" %s "%s" > "%s"' % (LYNX, LYNX_OPTS, html_file, text_file) shell(cmd) else: diff --git a/asciidoc/asciidoc.py b/asciidoc/asciidoc.py index ffde005..bcafdcd 100644 --- a/asciidoc/asciidoc.py +++ b/asciidoc/asciidoc.py @@ -6362,6 +6362,7 @@ def execute(cmd, opts, args): >>> """ + reset_asciidoc() config.init() if len(args) > 1: usage('Too many arguments') @@ -6458,11 +6459,13 @@ def execute(cmd, opts, args): sys.stdin, sys.stdout = stdin, stdout -def cli(): +def cli(argv=None): + if argv is None: + argv = sys.argv # Process command line options. try: # DEPRECATED: --unsafe option. - opts, args = getopt.getopt(sys.argv[1:], 'a:b:cd:ef:hno:svw:', + opts, args = getopt.getopt(argv[1:], 'a:b:cd:ef:hno:svw:', ['attribute=', 'backend=', 'conf-file=', 'doctype=', 'dump-conf', 'help', 'no-conf', 'no-header-footer', 'out-file=', 'section-numbers', 'verbose', 'version', 'safe', 'unsafe', @@ -6507,7 +6510,7 @@ def cli(): else: # Execute asciidoc. try: - execute(sys.argv[0], opts, args) + execute(argv[0], opts, args) except KeyboardInterrupt: sys.exit(1) diff --git a/tests/testasciidoc.py b/tests/testasciidoc.py index aec34aa..1379034 100755 --- a/tests/testasciidoc.py +++ b/tests/testasciidoc.py @@ -182,7 +182,6 @@ class AsciiDocTest(object): """ Generate and return test data output for backend. """ - asciidoc.reset_asciidoc() outfile = io.StringIO() options = self.options[:] options.append(('--out-file', outfile)) |