summaryrefslogtreecommitdiff
path: root/contrib/python/examples/run_example.sh
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2018-06-01 09:51:32 -0700
committerAtomic Bot <atomic-devel@projectatomic.io>2018-06-01 21:19:56 +0000
commit4f5e6728b713798dd0fe4d6f3c8b52e438285190 (patch)
tree2a5a127dead51dc4b850302f7955bff17ab66769 /contrib/python/examples/run_example.sh
parentb6753238bcf2e996b1116c6f91e25a6688f835ea (diff)
downloadpodman-4f5e6728b713798dd0fe4d6f3c8b52e438285190.tar.gz
podman-4f5e6728b713798dd0fe4d6f3c8b52e438285190.tar.bz2
podman-4f5e6728b713798dd0fe4d6f3c8b52e438285190.zip
Provide examples for python podman API
Signed-off-by: Jhon Honce <jhonce@redhat.com> Closes: #870 Approved by: rhatdan
Diffstat (limited to 'contrib/python/examples/run_example.sh')
-rwxr-xr-xcontrib/python/examples/run_example.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/contrib/python/examples/run_example.sh b/contrib/python/examples/run_example.sh
new file mode 100755
index 000000000..0f6575073
--- /dev/null
+++ b/contrib/python/examples/run_example.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+export PYTHONPATH=..
+
+function examples {
+ for file in $@; do
+ python3 -c "import ast; f=open('"${file}"'); t=ast.parse(f.read()); print(ast.get_docstring(t) + ' -- "${file}"')"
+ done
+}
+
+while getopts "lh" arg; do
+ case $arg in
+ l ) examples $(ls eg_*.py); exit 0 ;;
+ h ) echo 1>&2 $0 [-l] [-h] filename ; exit 2 ;;
+ esac
+done
+shift $((OPTIND-1))
+
+# podman needs to play some games with resources
+if [[ $(id -u) != 0 ]]; then
+ echo 1>&2 $0 must be run as root.
+ exit 2
+fi
+
+if ! systemctl --quiet is-active io.projectatomic.podman.socket; then
+ echo 1>&2 'podman is not running. systemctl enable --now io.projectatomic.podman.socket'
+ exit 1
+fi
+
+function cleanup {
+ podman rm $1 >/dev/null 2>&1
+}
+
+# Setup storage with an image and container
+podman pull alpine:latest >/tmp/podman.output 2>&1
+CTNR=$(podman create alpine)
+trap "cleanup $CTNR" EXIT
+
+if [[ -f $1 ]]; then
+ python3 $1
+else
+ python3 $1.py
+fi