backends plugins for a2x

64 views
Skip to first unread message

Lex Trotman

unread,
Oct 4, 2011, 2:46:15 AM10/4/11
to asci...@googlegroups.com
Hi Stuart,

Now we have plugin backends, the question of integration with a2x arises.

I propose the following simple method.

a2x gets a -b --backend option. If it is specified a2x uses "asciidoc
--backend list" to get the directory for the backend and looks for an
a2x.conf in that directory as well as the usual places.

That a2x.conf will be expected to define a to_backendname(self)
function like the others in class A2X.

a2x will also accept a --backend-opts in a similar way to xslt-opts, etc

when --backend is specified the to_backendname() function is called
instead of the to_formatname() function.

This should allow the plugin to re-use as much as possible of a2x's
existing infrastructure.

This executes arbitary code, but a2x already does that from its conf
files anyway so there is no reduction in safety.

If it sounds ok, then I'm happy to provide a patch for this as part of
developing the ODF backend with Dag.

Cheers
Lex

Lex Trotman

unread,
Oct 4, 2011, 7:36:56 AM10/4/11
to asci...@googlegroups.com

See https://github.com/dagwieers/asciidoc-odf/zipped for a first pass
modified a2x and example a2x.conf backend plugin.

Cheers
Lex

Dag Wieers

unread,
Oct 4, 2011, 12:49:54 PM10/4/11
to asci...@googlegroups.com
On Tue, 4 Oct 2011, Lex Trotman wrote:

> On 4 October 2011 17:46, Lex Trotman <ele...@gmail.com> wrote:
>
>> Now we have plugin backends, the question of integration with a2x arises.
>>
>> I propose the following simple method.

-snip-

>> If it sounds ok, then I'm happy to provide a patch for this as part of
>> developing the ODF backend with Dag.
>

> See https://github.com/dagwieers/asciidoc-odf/zipped for a first pass
> modified a2x and example a2x.conf backend plugin.

Unfortunately the sub-directories in the source-tree are listed per
branch, so the correct link is:

https://github.com/dagwieers/asciidoc-odf/tree/master/zipped

This bit me a few times before as well ;-)

--
-- dag wieers, d...@wieers.com, http://dag.wieers.com/
-- dagit linux solutions, in...@dagit.net, http://dagit.net/

[Any errors in spelling, tact or fact are transmission errors]

Lex Trotman

unread,
Oct 16, 2011, 1:27:28 AM10/16/11
to asci...@googlegroups.com

Stuart Rackham

unread,
Nov 6, 2011, 7:50:02 PM11/6/11
to asci...@googlegroups.com
Hi Lex

I've just committed your a2x patch with a couple of minor changes:
http://code.google.com/p/asciidoc/source/detail?r=26f6c1f23c8c8364c252360e49b6e89aefbaa7a6

1. I took the opportunity to simplify the a2x shell() function as the original
return value wasn't being used.

2. I renamed the backend configuration file from a2x.conf to a2x-backend.py to
distinguish it from the built-in config file and to make it clear that it's for
the backend and is executable (the a2x.conf should have been YAML or JSON, I
just took the path of least resistance at the time).

3. Renamed --backend_opts to --backend-opts for consistency.

Not part of this patch, but I stripped the backend option in your a2x.conf else
it throws and error if no --backend-opts are specified:

diff --git a/packaged/a2x.conf b/packaged/a2x.conf
index f9a53c4..1b89a5d 100644
--- a/packaged/a2x.conf
+++ b/packaged/a2x.conf
@@ -75,7 +75,7 @@ class odt_archive:

def to_odt(self):
opts = AttrDict(base_doc=None, temp_dir=None) # TODO default base doc?
- u = [ o.strip().split('=') for o in self.backend_opts.split('--') if o !
+ u = [ o.strip().split('=') for o in self.backend_opts.strip().split('--'
opts.update(u)
if opts.base_doc is None:
die("No base document found")

I can now install asciidoc-odf as a plugin and generate ODT files using
replacements3 (i.e. no line_break.py filter). Well done guys!

I do have a problem with images, this simple document generates .fodt OK but a2x
fails:

8<--------
The Article Title
=================

.Tiger block image
image::tiger.png[Tiger image]
8<--------

$ a2x -b odt -v --backend-opts="--base_doc=t.ott" t.txt
:
:
Traceback (most recent call last):
File "/home/srackham/bin/a2x", line 934, in <module>
a2x.execute()
File "/home/srackham/bin/a2x", line 356, in execute
self.to_backend()
File "/home/srackham/bin/a2x", line 608, in to_backend
eval('to_%s(self)' % self.backend)
File "<string>", line 1, in <module>
File "/home/srackham/.asciidoc/backends/odt/a2x-backend.py", line 84, in to_odt
a.make_archive(opts.base_doc, self.asciidoc_file, odt_file)
File "/home/srackham/.asciidoc/backends/odt/a2x-backend.py", line 57, in
make_archive
shutil.copyfile(mc.group(1), os.path.join(td, mc.group(2)))
File "/usr/lib/python2.6/shutil.py", line 53, in copyfile
fdst = open(dst, 'wb')
IOError: [Errno 2] No such file or directory: '/tmp/tmppTX8PH/Pictures/i_1.png'


Cheers, Stuart

Lex Trotman

unread,
Nov 6, 2011, 11:55:26 PM11/6/11
to asci...@googlegroups.com
On Mon, Nov 7, 2011 at 11:50 AM, Stuart Rackham <srac...@gmail.com> wrote:
> Hi Lex
>
> I've just committed your a2x patch with a couple of minor changes:
> http://code.google.com/p/asciidoc/source/detail?r=26f6c1f23c8c8364c252360e49b6e89aefbaa7a6

Thanks Stuart, will test soon.

>
> 1. I took the opportunity to simplify the a2x shell() function as the
> original return value wasn't being used.
>
> 2. I renamed the backend  configuration file from a2x.conf to a2x-backend.py
> to distinguish it from the built-in config file and to make it clear that
> it's for the backend and is executable (the a2x.conf should have been YAML
> or JSON, I just took the path of least resistance at the time).
>

And I just took the same path, using a file that a2x already imported.
A separate name is a good idea.

> 3. Renamed --backend_opts to --backend-opts for consistency.
>

Ah fine, I'll change the backend to use - not _ too.

> Not part of this patch, but I stripped the backend option in your a2x.conf
> else it throws and error if no --backend-opts are specified:
>
> diff --git a/packaged/a2x.conf b/packaged/a2x.conf
> index f9a53c4..1b89a5d 100644
> --- a/packaged/a2x.conf
> +++ b/packaged/a2x.conf
> @@ -75,7 +75,7 @@ class odt_archive:
>
>  def to_odt(self):
>        opts = AttrDict(base_doc=None, temp_dir=None) # TODO default base
> doc?
> -       u = [ o.strip().split('=') for o in self.backend_opts.split('--') if
> o !
> +       u = [ o.strip().split('=') for o in
> self.backend_opts.strip().split('--'
>        opts.update(u)
>        if opts.base_doc is None:
>                die("No base document found")

Will apply.

Ah, I don't create directory Pictures if it doesn't exist in the ott
file, mine has always had one. Will fix.

Cheers
Lex

Reply all
Reply to author
Forward
0 new messages