Let's take following shinyproxy yaml as example:
proxy:
title: Open Analytics Shiny Proxy
logo-url: http://www.openanalytics.eu/sites/www.openanalytics.eu/themes/oa/logo.png
landing-page: /
heartbeat-rate: 10000
heartbeat-timeout: 60000
port: 8080
authentication: simple
admin-groups: scientists
# Example: 'simple' authentication configuration
users:
- name: jack
password: password
groups: scientists
- name: jeff
password: password
groups: mathematicians
# Example: 'ldap' authentication configuration
ldap:
url: ldap://ldap.forumsys.com:389/dc=example,dc=com
user-dn-pattern: uid={0}
group-search-base:
group-search-filter: (uniqueMember={0})
manager-dn: cn=read-only-admin,dc=example,dc=com
manager-password: password
# Docker configuration
docker:
cert-path: /home/none
url: http://localhost:2375
port-range-start: 20000
specs:
- id: 01_hello
display-name: Hello Application
description: Application which demonstrates the basics of a Shiny app
container-cmd: ["R", "-e", "shinyproxy::run_01_hello()"]
container-image: openanalytics/shinyproxy-demo
access-groups: [scientists, mathematicians]
- id: 06_tabsets
container-cmd: ["R", "-e", "shinyproxy::run_06_tabsets()"]
container-image: openanalytics/shinyproxy-demo
access-groups: scientists
logging:
file:
shinyproxy.log
How can I parse ["R", "-e", "shinyproxy::run_06_tabsets()"]
to normal exec form or directly run this command without parsing in python
? Is there any lib for that?
EDIT:
I want to run that command in subprocess
and kill it after timeout is reached or error occurred when running Shiny app:
MWE:
from subprocess import Popen, PIPE
from threading import Timer
cmd_from_yaml = ['R', '-e', 'shinyproxy::run_06_tabsets()']
docker_cmd = "docker run -i {0} {1}".format(vol, img)
docker_cmd = docker_cmd.split()
docker_cmd.extend(cmd_from_yaml)
timeout_sec = 10
print("Running command: " + str(" ".join(docker_cmd)))
proc = Popen(docker_cmd, stdout=PIPE, stderr=PIPE, shell=False)
timer = Timer(timeout_sec, proc.kill)
try:
timer.start()
stdout, stderr = proc.communicate()
finally:
timer.cancel()
if stderr:
proc.kill()
raise Exception("Error: " + str(stderr))
Terminal output:
>>> from subprocess import Popen, PIPE
... from threading import Timer
...
... cmd_from_yaml = ['R', '-e', 'shinyproxy::run_06_tabsets()']
... docker_cmd = "docker run -i {0} {1}".format(vol, img)
... docker_cmd = docker_cmd.split()
... docker_cmd.extend(cmd_from_yaml)
... timeout_sec = 10
... print("Running command: " + str(" ".join(docker_cmd)))
... proc = Popen(docker_cmd, stdout=PIPE, stderr=PIPE, shell=False)
...
... timer = Timer(timeout_sec, proc.kill)
... try:
... timer.start()
... stdout, stderr = proc.communicate()
... finally:
... timer.cancel()
...
... if stderr:
... proc.kill()
... raise Exception("Error: " + str(stderr))
...
Running command: docker run -i openanalytics/shinyproxy-demo R -e shinyproxy::run_06_tabsets()
Traceback (most recent call last):
File "<input>", line 21, in <module>
Exception: Error: b'Loading required package: shiny\n\nListening on http://0.0.0.0:3838\n'
Note command docker run -i openanalytics/shinyproxy-demo R -e "shinyproxy::run_06_tabsets()"
will work because of adding missing quotations - but my point in this question is if there is any way to do this automatically without manually adding missing quotations as it is done in docker compose.