diff options
author | midipix <writeonce@midipix.org> | 2018-12-04 14:36:15 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-12-06 20:58:23 -0500 |
commit | b4ba4d03690069a068f1a7b7852524655ac743af (patch) | |
tree | 9e321384b4567586e253ffc7061a99c47ea22553 | |
parent | 85773dcd2c06f26a7477508625ebea362ed51977 (diff) | |
download | sbpython2-b4ba4d03690069a068f1a7b7852524655ac743af.tar.bz2 sbpython2-b4ba4d03690069a068f1a7b7852524655ac743af.tar.xz |
project: added the pycopy.sh and pycgen.sh build-time utility scripts.
-rwxr-xr-x | project/pycgen.sh | 29 | ||||
-rwxr-xr-x | project/pycopy.sh | 41 |
2 files changed, 70 insertions, 0 deletions
diff --git a/project/pycgen.sh b/project/pycgen.sh new file mode 100755 index 0000000..e9e0a15 --- /dev/null +++ b/project/pycgen.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# pycgen: a build-time utiltiy script +# objective: generate the correcponding python byte-code (.pyc) +# object files for one or more source python (.py) +# scripts. + +if [ -z "$PYCGEN_PYTHON" ]; then + pycompile='python' +else + pycompile="$PYCGEN_PYTHON" +fi + +refdir=$(pwd) + +for pysrc in $@; do + basename=$(basename "$pysrc"); + dstdir=$(dirname "$pysrc") + + if [ -z "$dstdir" ]; then + dstdir='.' + fi + + cd "$dstdir" || exit 2 + "$pycompile" -m py_compile "$basename" || exit 2 + cd "$refdir" +done + +exit 0 diff --git a/project/pycopy.sh b/project/pycopy.sh new file mode 100755 index 0000000..2a55b7a --- /dev/null +++ b/project/pycopy.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# pyccopy: a build-time utiltiy script +# objective: copy one or more source python (.py) scripts +# to the destination directory specified via the +# environment variable PYCOPY_DSTDIR, replacing +# the original shebang line, should the script +# contain one, with a program interpreter based +# on the PYCOPY_PREFIX and PYCOPY_PYTHON +# environment variables. + +if [ -z "$PYCOPY_PYTHON" ]; then + python='python' +else + python="$PYCOPY_PYTHON" +fi + +if [ -z "$PYCOPY_PREFIX" ]; then + prefix='/usr' +else + prefix="$PYCOPY_PREFIX" +fi + +if [ -z "$PYCOPY_DSTDIR" ]; then + dstdir='.' +else + dstdir="$PYCOPY_DSTDIR" +fi + +for pysrc in $@; do + basename=$(basename "$pysrc"); + + sed -e '1s@^#!.*@#!'" $prefix/bin/$python"'@g' \ + "$pysrc" > "$dstdir/$basename" || exit 2 + + if [ "$(head -n1 "$dstdir/$basename")" = "#! $prefix/bin/$python" ]; then + chmod +x "$dstdir/$basename" || exit 2 + fi +done + +exit 0 |