0

Here is my code:

   #!/usr/bin/python

    import subprocess

    asciidoc_file_name = '/tmp/redoc_2013-06-25_12:52:19.txt'
    asciidoc_call = ["asciidoc","-b docbook45",asciidoc_file_name]
    print asciidoc_call
    subprocess.call(asciidoc_call)

And here is the output:

    labamba@lambada:~$ ./debug.py
    ['asciidoc', '-b docbook45', '/tmp/redoc_2013-06-25_12:52:19.txt']
    asciidoc: FAILED: missing backend conf file:  docbook45.conf
    labamba@lambada:~$ asciidoc -b docbook45 /tmp/redoc_2013-06-25_12\:52\:19.txt
    labamba@lambada:~$ file /tmp/redoc_2013-06-25_12\:52\:19.xml
    /tmp/redoc_2013-06-25_12:52:19.xml: XML document text
    labamba@lambada:~$ file /etc/asciidoc/docbook45.conf
    /etc/asciidoc/docbook45.conf: HTML document, ASCII text, with very long lines

When called via python subprocess, asciidoc complains about a missing config file. When called on the command line, everything is fine, and the config file is there. Can anyone make sense out of this? I'm lost.

Isaac
  • 810
  • 2
  • 13
  • 31
  • is the config file in the same path as the python program that calls subprocess? – Ionut Hulub Jun 25 '13 at 11:29
  • check if the asciidoc invoked by the command line is the same as that invoked by Python: do `subprocess.check_output(['which' 'asciidoc'])` in python, and `which asciidoc` on the command line. Do you see the same paths? – Dhara Jun 25 '13 at 11:29
  • There is only one asciidoc. The config file is not in the same path, but `/etc/asciidoc/`, where it should be. It turns out the solution is the accepted answer. – Isaac Jun 25 '13 at 12:48

2 Answers2

2

Try this:

asciidoc_call = ["asciidoc","-b", "docbook45", asciidoc_file_name]

the other call would call ascidoc with "-b docbook45" as one single option, which won't work.

mata
  • 67,110
  • 10
  • 163
  • 162
2

The question is old... Anyway, the asciidoc is implemented in Python and it also includes the asciidocapi.py that can be used as a module from your Python program. The module docstring says:

asciidocapi - AsciiDoc API wrapper class.

The AsciiDocAPI class provides an API for executing asciidoc. Minimal example
compiles `mydoc.txt` to `mydoc.html`:

  import asciidocapi
  asciidoc = asciidocapi.AsciiDocAPI()
  asciidoc.execute('mydoc.txt')

- Full documentation in asciidocapi.txt.
- See the doctests below for more examples.

To simplify, it implements the AsciiDocAPI class that--when initialized--searches for the asciidoc script and imports it behind the scene as a module. This way, you can use it more naturally in Python, and you can avoid using the subprocess.call().

pepr
  • 20,112
  • 15
  • 76
  • 139