gluish icon indicating copy to clipboard operation
gluish copied to clipboard

shellout broken when using json-strings and .format() style because of internal double-format

Open boerni667 opened this issue 5 years ago • 3 comments

e.g. cmd="esbulk -server {server} -purge -mapping '{"mappings":{"{type}":{"properties":{"location":{"type":"geo_point"}}}}}' -index {index} -type {type} -w {workers} -id id -verbose {file}.ldj".format(**self.config) output=shellout(cmd)

leads to:

Traceback (most recent call last): File "/home/metadata/.local/lib/python3.5/site-packages/luigi/worker.py", line 194, in run new_deps = self._run_get_new_deps() File "/home/metadata/.local/lib/python3.5/site-packages/luigi/worker.py", line 131, in _run_get_new_deps task_gen = self.task.run() File "/home/metadata/git/efre-lod-elasticsearch-tools/luigi/update_gn.py", line 91, in run cmd="esbulk -server {server} -purge -mapping '{"mappings":{"{type}":{"properties":{"location":{"type":"geo_point"}}}}}' -index {index} -type {type} -w {workers} -id id -verbose {file}.ldj".format(**self.config) KeyError: '"mappings"'

escaping the braces doesn't work either

boerni667 avatar Nov 28 '18 07:11 boerni667

Thanks @boerni667 for the report. It's ugly, but you can get around that by quoting a curly brace with a curly brace; I created an example. In short:

$ shellout(""" echo "Hello World" | awk '{{ print $0 }}' """)

miku avatar Nov 28 '18 08:11 miku

this still doesn't work with .format()

>>>shellout(""" echo "Hello {w}" | awk '{{ print $0 }}' """.format(w="World")) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.5/dist-packages/gluish/utils.py", line 127, in shellout command = template.format(**kwargs) KeyError: ' print $0 '

boerni667 avatar Nov 28 '18 09:11 boerni667

Yes, this is currently not possible (shellout and format interfere):

>>> shellout(""" echo "Hello {w}" | awk '{{ print $0 }}' """.format(w="World"))
...
KeyError ' print $0 '

However, one could write:

>>> shellout(""" echo "Hello {w}" | awk '{{ print $0 }}' """, w="World")
Hello World

miku avatar Nov 28 '18 09:11 miku