Skip to content

Commit

Permalink
Wrapper method of dynamically determining correct python version
Browse files Browse the repository at this point in the history
  • Loading branch information
boatbod committed Dec 18, 2020
1 parent 1a76322 commit 444f29c
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 16 deletions.
10 changes: 6 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ if [ ${GR_VER} = "3.8" ]; then
sudo apt-get build-dep gnuradio
sudo apt-get install gnuradio gnuradio-dev gr-osmosdr librtlsdr-dev libuhd-dev libhackrf-dev libitpp-dev libpcap-dev cmake git swig build-essential pkg-config doxygen python3-numpy python3-waitress python3-requests gnuplot-x11

if [ ! -x /usr/bin/python ]; then
echo ====== installing python-is-python3
sudo apt-get install python-is-python3
fi
# Tell op25 to use python3
echo "/usr/bin/python3" > op25/op25/gr-op25_repeater/apps/op25_python

else
echo "Installing for GNURadio 3.7"
sudo apt-get build-dep gnuradio
sudo apt-get install gnuradio gnuradio-dev gr-osmosdr librtlsdr-dev libuhd-dev libhackrf-dev libitpp-dev libpcap-dev cmake git swig build-essential pkg-config doxygen python-numpy python-waitress python-requests gnuplot-x11

# Tell op25 to use python2
echo "/usr/bin/python" > op25/op25/gr-op25_repeater/apps/op25_python

fi

if [ ! -f /etc/modprobe.d/blacklist-rtl.conf ]; then
Expand Down
26 changes: 24 additions & 2 deletions op25/gr-op25_repeater/apps/audio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python

#!/bin/sh
# Copyright 2017, 2018 Graham Norbury
#
# Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 Max H. Parke KA1RBI
Expand All @@ -21,6 +20,29 @@
# Software Foundation, Inc., 51 Franklin Street, Boston, MA
# 02110-1301, USA.

"true" '''\'
DEFAULT_PYTHON2=/usr/bin/python
DEFAULT_PYTHON3=/usr/bin/python3
if [ -f op25_python ]; then
OP25_PYTHON=$(cat op25_python)
else
OP25_PYTHON="/usr/bin/python"
fi

if [ -x $OP25_PYTHON ]; then
echo Using Python $OP25_PYTHON >&2
exec $OP25_PYTHON "$0" "$@"
elif [ -x $DEFAULT_PYTHON2 ]; then
echo Using Python $DEFAULT_PYTHON2 >&2
exec $DEFAULT_PYTHON2 "$0" "$@"
elif [ -x $DEFAULT_PYTHON3 ]; then
echo Using Python $DEFAULT_PYTHON3 >&2
exec $DEFAULT_PYTHON3 "$0" "$@"
else
echo Unable to find Python >&2
fi
exit 127
'''
import signal
import sys
import time
Expand Down
26 changes: 24 additions & 2 deletions op25/gr-op25_repeater/apps/cfgtrunk.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python

#!/bin/sh
#
# Copyright 2020 Graham J. Norbury
#
Expand All @@ -23,6 +22,29 @@
#
# Crude tool for editing trunk.tsv files
#
"true" '''\'
DEFAULT_PYTHON2=/usr/bin/python
DEFAULT_PYTHON3=/usr/bin/python3
if [ -f op25_python ]; then
OP25_PYTHON=$(cat op25_python)
else
OP25_PYTHON="/usr/bin/python"
fi

if [ -x $OP25_PYTHON ]; then
echo Using Python $OP25_PYTHON >&2
exec $OP25_PYTHON "$0" "$@"
elif [ -x $DEFAULT_PYTHON2 ]; then
echo Using Python $DEFAULT_PYTHON2 >&2
exec $DEFAULT_PYTHON2 "$0" "$@"
elif [ -x $DEFAULT_PYTHON3 ]; then
echo Using Python $DEFAULT_PYTHON3 >&2
exec $DEFAULT_PYTHON3 "$0" "$@"
else
echo Unable to find Python >&2
fi
exit 127
'''
import sys
import csv
Expand Down
28 changes: 25 additions & 3 deletions op25/gr-op25_repeater/apps/multi_rx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python

#!/bin/sh
# Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 Max H. Parke KA1RBI
# Copyright 2020 Graham J. Norbury - [email protected]
#
Expand All @@ -20,6 +19,29 @@
# Software Foundation, Inc., 51 Franklin Street, Boston, MA
# 02110-1301, USA.

"true" '''\'
DEFAULT_PYTHON2=/usr/bin/python
DEFAULT_PYTHON3=/usr/bin/python3
if [ -f op25_python ]; then
OP25_PYTHON=$(cat op25_python)
else
OP25_PYTHON="/usr/bin/python"
fi

if [ -x $OP25_PYTHON ]; then
echo Using Python $OP25_PYTHON >&2
exec $OP25_PYTHON "$0" "$@"
elif [ -x $DEFAULT_PYTHON2 ]; then
echo Using Python $DEFAULT_PYTHON2 >&2
exec $DEFAULT_PYTHON2 "$0" "$@"
elif [ -x $DEFAULT_PYTHON3 ]; then
echo Using Python $DEFAULT_PYTHON3 >&2
exec $DEFAULT_PYTHON3 "$0" "$@"
else
echo Unable to find Python >&2
fi
exit 127
'''
import io
import os
import sys
Expand Down Expand Up @@ -574,7 +596,7 @@ def configure_metadata(self, config):
sys.stderr.write("Configuring metadata stream #%d [%s]: %s\n" % (idx, stream_name, stream['icecastServerAddress'] + "/" + stream['icecastMountpoint']))
except:
sys.stderr.write("Error configuring metadata stream #%d; %s\n" % (idx, sys.exc_info()[1]))
sys.exc_clear()
#sys.exc_clear()
else:
sys.stderr.write("Ignoring unnamed metadata stream #%d\n" % idx)
idx += 1
Expand Down
26 changes: 24 additions & 2 deletions op25/gr-op25_repeater/apps/rx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python

#!/bin/sh
# Copyright 2008-2011 Steve Glass
#
# Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Max H. Parke KA1RBI
Expand All @@ -26,6 +25,29 @@
# Software Foundation, Inc., 51 Franklin Street, Boston, MA
# 02110-1301, USA.

"true" '''\'
DEFAULT_PYTHON2=/usr/bin/python
DEFAULT_PYTHON3=/usr/bin/python3
if [ -f op25_python ]; then
OP25_PYTHON=$(cat op25_python)
else
OP25_PYTHON="/usr/bin/python"
fi

if [ -x $OP25_PYTHON ]; then
echo Using Python $OP25_PYTHON >&2
exec $OP25_PYTHON "$0" "$@"
elif [ -x $DEFAULT_PYTHON2 ]; then
echo Using Python $DEFAULT_PYTHON2 >&2
exec $DEFAULT_PYTHON2 "$0" "$@"
elif [ -x $DEFAULT_PYTHON3 ]; then
echo Using Python $DEFAULT_PYTHON3 >&2
exec $DEFAULT_PYTHON3 "$0" "$@"
else
echo Unable to find Python >&2
fi
exit 127
'''
import io
import os
import pickle
Expand Down
32 changes: 29 additions & 3 deletions op25/gr-op25_repeater/apps/terminal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python

#!/bin/sh
# Copyright 2008-2011 Steve Glass
#
# Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 Max H. Parke KA1RBI
Expand All @@ -21,6 +20,29 @@
# Software Foundation, Inc., 51 Franklin Street, Boston, MA
# 02110-1301, USA.

"true" '''\'
DEFAULT_PYTHON2=/usr/bin/python
DEFAULT_PYTHON3=/usr/bin/python3
if [ -f op25_python ]; then
OP25_PYTHON=$(cat op25_python)
else
OP25_PYTHON="/usr/bin/python"
fi

if [ -x $OP25_PYTHON ]; then
echo Using Python $OP25_PYTHON >&2
exec $OP25_PYTHON "$0" "$@"
elif [ -x $DEFAULT_PYTHON2 ]; then
echo Using Python $DEFAULT_PYTHON2 >&2
exec $DEFAULT_PYTHON2 "$0" "$@"
elif [ -x $DEFAULT_PYTHON3 ]; then
echo Using Python $DEFAULT_PYTHON3 >&2
exec $DEFAULT_PYTHON3 "$0" "$@"
else
echo Unable to find Python >&2
fi
exit 127
'''
import sys
import curses
import curses.textpad
Expand Down Expand Up @@ -451,7 +473,11 @@ def process_q_events(self):
def send_command(self, command, arg1 = 0, arg2 = 0):
if self.sock:
self.sock.send(json.dumps({'command': command, 'arg1': arg1, 'arg2': arg2}))
js = json.dumps({'command': command, 'arg1': arg1, 'arg2': arg2})
if sys.version[0] > '2':
if type(js) is str:
js = js.encode()
self.sock.send(js)
else:
msg = gr.message().make_from_string(command, -2, arg1, arg2)
self.output_q.insert_tail(msg)
Expand Down

0 comments on commit 444f29c

Please sign in to comment.