문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top