hamlib cleanup

This commit is contained in:
dj2ls 2022-01-15 17:06:02 +01:00
parent dd0ce99d7c
commit 6c519c5e8d
2 changed files with 22 additions and 53 deletions

View file

@ -60,42 +60,7 @@ def noalsaerr():
# p = pyaudio.PyAudio() # p = pyaudio.PyAudio()
###################################################### ######################################################
# check if we are running in a pyinstaller environment
try:
app_path = sys._MEIPASS
except:
app_path = os.path.abspath(".")
sys.path.append(app_path)
# try importing hamlib
try:
# installation path for Ubuntu 20.04 LTS python modules
sys.path.append('/usr/local/lib/python'+ python_version +'/site-packages')
# installation path for Ubuntu 20.10 +
sys.path.append('/usr/local/lib/')
# everything else... not nice, but an attempt
sys.path.append('/usr/local/lib/python3.6/site-packages')
sys.path.append('/usr/local/lib/python3.7/site-packages')
sys.path.append('/usr/local/lib/python3.8/site-packages')
sys.path.append('/usr/local/lib/python3.9/site-packages')
sys.path.append('/usr/local/lib/python3.10/site-packages')
import Hamlib
# https://stackoverflow.com/a/4703409
hamlib_version = re.findall(r"[-+]?\d*\.?\d+|\d+", Hamlib.cvar.hamlib_version)
hamlib_version = float(hamlib_version[0])
min_hamlib_version = 4.1
if hamlib_version > min_hamlib_version:
structlog.get_logger("structlog").info("[DMN] Hamlib found", version=hamlib_version)
else:
structlog.get_logger("structlog").warning("[DMN] Hamlib outdated", found=hamlib_version, recommend=min_hamlib_version)
except Exception as e:
structlog.get_logger("structlog").critical("[DMN] Hamlib not found", error=e)
# load crc engine # load crc engine
crc_algorithm = crcengine.new('crc16-ccitt-false') # load crc8 library crc_algorithm = crcengine.new('crc16-ccitt-false') # load crc8 library
@ -265,7 +230,7 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
command.append('./tnc') command.append('./tnc')
elif sys.platform == 'win32' or sys.platform == 'win64': elif sys.platform == 'win32' or sys.platform == 'win64':
command.append('tnc.exe') command.append('tnc.exe')
command += options command += options
p = subprocess.Popen(command) p = subprocess.Popen(command)
structlog.get_logger("structlog").info("[DMN] TNC started", path="binary") structlog.get_logger("structlog").info("[DMN] TNC started", path="binary")
@ -395,12 +360,11 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
self.request.sendall(bytes(jsondata, encoding)) self.request.sendall(bytes(jsondata, encoding))
except Exception as e: except Exception as e:
print(e) structlog.get_logger("structlog").error("[DMN] Hamlib: Can't open rig", e = sys.exc_info()[0], error=e)
structlog.get_logger("structlog").error("[DMN] Hamlib: Can't open rig", e = sys.exc_info()[0])
except Exception as e: except Exception as e:
#socketTimeout = 0 #socketTimeout = 0
structlog.get_logger("structlog").error("[DMN] Network error", e=e) structlog.get_logger("structlog").error("[DMN] Network error", error=e)
structlog.get_logger("structlog").warning("[DMN] Closing client socket", ip=self.client_address[0], port=self.client_address[1]) structlog.get_logger("structlog").warning("[DMN] Closing client socket", ip=self.client_address[0], port=self.client_address[1])
@ -420,12 +384,14 @@ if __name__ == '__main__':
HAMLIB_USE_RIGCTL = True HAMLIB_USE_RIGCTL = True
if HAMLIB_USE_RIGCTL: if HAMLIB_USE_RIGCTL:
structlog.get_logger("structlog").warning("using hamlib rigctl module...") structlog.get_logger("structlog").warning("[DMN] Using Hamlib rigctl module...")
hamlib_version = 0 hamlib_version = 0
import rigctl as rig import rigctl as rig
else: else:
structlog.get_logger("structlog").info("using hamlib rig module...") structlog.get_logger("structlog").info("[DMN] Using Hamlib rig module...")
import rig import rig
hamlib_version = rig.hamlib_version
# --------------------------------------------START CMD SERVER # --------------------------------------------START CMD SERVER
DAEMON_THREAD = threading.Thread(target=start_daemon, name="daemon") DAEMON_THREAD = threading.Thread(target=start_daemon, name="daemon")

View file

@ -7,6 +7,9 @@ import atexit
import subprocess import subprocess
import os import os
# set global hamlib version
hamlib_version = 0
# append local search path # append local search path
# check if we are running in a pyinstaller environment # check if we are running in a pyinstaller environment
try: try:
@ -46,28 +49,28 @@ try:
min_hamlib_version = 4.1 min_hamlib_version = 4.1
if hamlib_version > min_hamlib_version: if hamlib_version > min_hamlib_version:
structlog.get_logger("structlog").info("[TNC] Hamlib found", version=hamlib_version) structlog.get_logger("structlog").info("[RIG] Hamlib found", version=hamlib_version)
else: else:
structlog.get_logger("structlog").warning("[TNC] Hamlib outdated", found=hamlib_version, recommend=min_hamlib_version) structlog.get_logger("structlog").warning("[RIG] Hamlib outdated", found=hamlib_version, recommend=min_hamlib_version)
except Exception as e: except Exception as e:
structlog.get_logger("structlog").warning("[TNC] Python Hamlib binding not found", error=e) structlog.get_logger("structlog").warning("[RIG] Python Hamlib binding not found", error=e)
try: try:
structlog.get_logger("structlog").warning("[TNC] Trying to open rigctl", error=e) structlog.get_logger("structlog").warning("[RIG] Trying to open rigctl")
rigctl = subprocess.Popen("rigctl -V",shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) rigctl = subprocess.Popen("rigctl -V",shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
hamlib_version = rigctl.stdout.readline() hamlib_version = rigctl.stdout.readline()
hamlib_version = hamlib_version.split(' ') hamlib_version = hamlib_version.split(' ')
print(hamlib_version[0])
print(hamlib_version[1])
print(hamlib_version[2])
if hamlib_version[1] == 'Hamlib': if hamlib_version[1] == 'Hamlib':
rigctl = True structlog.get_logger("structlog").warning("[RIG] Rigctl found! Start daemon with parameter --rigctl", version=hamlib_version[2])
print(hamlib_version) sys.exit()
else: else:
rigctl = False
raise Exception raise Exception
except Exception as e: except Exception as e:
structlog.get_logger("structlog").critical("[TNC] HAMLIB NOT INSTALLED", error=e) structlog.get_logger("structlog").critical("[RIG] HAMLIB NOT INSTALLED", error=e)
hamlib_version = 0
sys.exit()
class radio: class radio:
def __init__(self): def __init__(self):