fabric - python string iterpolation on files with % as comment -
this question has answer here:
i use fabric generate custom ejabberd config file , upload server. fabric uses python string interpolation in fabric.contrib.files.upload_template
. unfortunately ejabberd config file uses
%%%
for comments
using python string interpolation throws error on following simplified example:
%%% comment
{resurl, %(resturl)s}
valueerror: unsupported format character 't' (0x74) @ index 4
i replace every non uneven occurence of % > 1 one. or
val = re.sub("%", "??", open("ejabberd.cfg").read()) val = val % {"resturl": "http://localhost:500/"} val.replace("??", "%")
there might better solution treat file's having %, maybe telling python use character mark start of specifier.
thanks helping
you need double each %
:
%%%%%% comment {resurl, %(resturl)s}
this escapes %
; output transforms each %%
%
.
demo:
>>> val = '''\ ... %%%%%% comment ... ... {resurl, %(resturl)s} ... ''' >>> print val % {"resturl": "http://localhost:500/"} %%% comment {resurl, http://localhost:500/}
Comments
Post a Comment