diff --git a/auto_rx/auto_rx.py b/auto_rx/auto_rx.py index 1ddb107..49c598e 100644 --- a/auto_rx/auto_rx.py +++ b/auto_rx/auto_rx.py @@ -17,6 +17,7 @@ import time import traceback import os from dateutil.parser import parse +from queue import Queue if sys.version_info < (3, 6): print("CRITICAL - radiosonde_auto_rx requires Python 3.6 or newer!") @@ -49,13 +50,6 @@ from autorx.web import ( from autorx.gpsd import GPSDAdaptor from autorx.sdr_wrappers import shutdown_sdr -try: - # Python 2 - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue - # Logging level # INFO = Basic status messages diff --git a/auto_rx/autorx/__init__.py b/auto_rx/autorx/__init__.py index 4ef98f1..f2339bf 100644 --- a/auto_rx/autorx/__init__.py +++ b/auto_rx/autorx/__init__.py @@ -5,12 +5,7 @@ # Copyright (C) 2018 Mark Jessop # Released under GNU GPL v3 or later # -try: - # Python 2 - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue +from queue import Queue # Now using Semantic Versioning (https://semver.org/) MAJOR.MINOR.PATCH # MAJOR - Only updated when something huge changes to the project (new decode chain, etc) diff --git a/auto_rx/autorx/aprs.py b/auto_rx/autorx/aprs.py index 9f4dbf9..eb86449 100644 --- a/auto_rx/autorx/aprs.py +++ b/auto_rx/autorx/aprs.py @@ -11,17 +11,11 @@ import random import time import traceback import socket +from queue import Queue from threading import Thread, Lock from . import __version__ as auto_rx_version from .utils import strip_sonde_serial -try: - # Python 2 - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue - def telemetry_to_aprs_position( sonde_data, object_name="", aprs_comment="BOM Balloon", position_report=False diff --git a/auto_rx/autorx/config.py b/auto_rx/autorx/config.py index 0be3d1d..d198406 100644 --- a/auto_rx/autorx/config.py +++ b/auto_rx/autorx/config.py @@ -11,6 +11,7 @@ import logging import os import traceback import json +from configparser import RawConfigParser from .sdr_wrappers import test_sdr # Dummy initial config with some parameters we need to make the web interface happy. @@ -26,13 +27,6 @@ global_config = { # Web interface credentials web_password = "none" -try: - # Python 2 - from ConfigParser import RawConfigParser -except ImportError: - # Python 3 - from configparser import RawConfigParser - # Fixed minimum update rates for APRS & Habitat # These are set to avoid congestion on the APRS-IS network, and on the Habitat server # Please respect other users of these networks and leave these settings as they are. diff --git a/auto_rx/autorx/email_notification.py b/auto_rx/autorx/email_notification.py index 9b50fb3..0b2db5a 100644 --- a/auto_rx/autorx/email_notification.py +++ b/auto_rx/autorx/email_notification.py @@ -11,19 +11,12 @@ import time import smtplib from email.mime.text import MIMEText from email.utils import formatdate +from queue import Queue from threading import Thread from .config import read_auto_rx_config from .utils import position_info, strip_sonde_serial from .geometry import GenericTrack -try: - # Python 2 - from Queue import Queue - -except ImportError: - # Python 3 - from queue import Queue - class EmailNotification(object): """ Radiosonde Email Notification Class. diff --git a/auto_rx/autorx/habitat.py b/auto_rx/autorx/habitat.py index ee453de..ebb4303 100644 --- a/auto_rx/autorx/habitat.py +++ b/auto_rx/autorx/habitat.py @@ -15,16 +15,10 @@ import traceback import json from base64 import b64encode from hashlib import sha256 +from queue import Queue from threading import Thread, Lock from . import __version__ as auto_rx_version -try: - # Python 2 - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue - # These get replaced out after init url_habitat_uuids = "" url_habitat_db = "" diff --git a/auto_rx/autorx/logger.py b/auto_rx/autorx/logger.py index 40697b2..1b0fa29 100644 --- a/auto_rx/autorx/logger.py +++ b/auto_rx/autorx/logger.py @@ -10,15 +10,9 @@ import glob import logging import os import time +from queue import Queue from threading import Thread -try: - # Python 2 - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue - class TelemetryLogger(object): """ Radiosonde Telemetry Logger Class. diff --git a/auto_rx/autorx/ozimux.py b/auto_rx/autorx/ozimux.py index 19630c3..bfceeef 100644 --- a/auto_rx/autorx/ozimux.py +++ b/auto_rx/autorx/ozimux.py @@ -10,15 +10,9 @@ import json import logging import socket import time +from queue import Queue from threading import Thread -try: - # Python 2 - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue - class OziUploader(object): """ Push radiosonde telemetry out via UDP broadcast to the Horus Chase-Car Utilities diff --git a/auto_rx/autorx/rotator.py b/auto_rx/autorx/rotator.py index 8d5a52f..5301cf8 100644 --- a/auto_rx/autorx/rotator.py +++ b/auto_rx/autorx/rotator.py @@ -10,16 +10,10 @@ import socket import time import numpy as np +from queue import Queue from threading import Thread, Lock from autorx.utils import position_info -try: - # Python 2 - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue - def read_rotator(rotctld_host="localhost", rotctld_port=4533, timeout=5): """ Attempt to read a position from a rotctld server. diff --git a/auto_rx/autorx/scan.py b/auto_rx/autorx/scan.py index 3eafeb7..ffba8fa 100644 --- a/auto_rx/autorx/scan.py +++ b/auto_rx/autorx/scan.py @@ -13,6 +13,7 @@ import platform import subprocess import time import traceback +from io import StringIO from threading import Thread, Lock from types import FunctionType, MethodType from .utils import ( @@ -24,12 +25,6 @@ from .utils import ( ) from .sdr_wrappers import * -try: - # Python 2 - from StringIO import StringIO -except ImportError: - # Python 3 - from io import StringIO try: from .web import flask_emit_event diff --git a/auto_rx/autorx/sondehub.py b/auto_rx/autorx/sondehub.py index 86e4d8e..b00e7e3 100644 --- a/auto_rx/autorx/sondehub.py +++ b/auto_rx/autorx/sondehub.py @@ -18,16 +18,10 @@ import logging import os import requests import time +from queue import Queue from threading import Thread from email.utils import formatdate -try: - # Python 2 - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue - class SondehubUploader(object): """ Sondehub Uploader Class. @@ -83,20 +77,10 @@ class SondehubUploader(object): # Record of when we last uploaded a user station position to Sondehub. self.last_user_position_upload = 0 - try: - # Python 2 check. Python 2 doesnt have gzip.compress so this will throw an exception. - gzip.compress(b"\x00\x00") - - # Start queue processing thread. - self.input_processing_running = True - self.input_process_thread = Thread(target=self.process_queue) - self.input_process_thread.start() - - except: - logging.error( - "Detected Python 2.7, which does not support gzip.compress. Sondehub DB uploading will be disabled." - ) - self.input_processing_running = False + # Start queue processing thread. + self.input_processing_running = True + self.input_process_thread = Thread(target=self.process_queue) + self.input_process_thread.start() def update_station_position(self, lat, lon, alt): """ Update the internal station position record. Used when determining the station position by GPSD """ diff --git a/auto_rx/autorx/utils.py b/auto_rx/autorx/utils.py index dca4e55..eb903a2 100644 --- a/auto_rx/autorx/utils.py +++ b/auto_rx/autorx/utils.py @@ -22,15 +22,9 @@ import semver from dateutil.parser import parse from datetime import datetime, timedelta from math import radians, degrees, sin, cos, atan2, sqrt, pi +from queue import Queue from . import __version__ as auto_rx_version -try: - # Python 2 - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue - # List of binaries we check for on startup REQUIRED_RS_UTILS = [ @@ -723,8 +717,7 @@ def is_not_linux(): # Second check for the existence of '-Microsoft' in the uname release field. # This is a good check that we are running in WSL. - # Note the use of indexing instead of the named field, for Python 2 & 3 compatability. - if "Microsoft" in platform.uname()[2]: + if "Microsoft" in platform.uname().release: return True # Else, we're probably in native Linux! diff --git a/auto_rx/autorx/web.py b/auto_rx/autorx/web.py index 6b68e99..6a84a78 100644 --- a/auto_rx/autorx/web.py +++ b/auto_rx/autorx/web.py @@ -21,6 +21,7 @@ import autorx.scan from autorx.geometry import GenericTrack from autorx.utils import check_autorx_versions from autorx.log_files import list_log_files, read_log_by_serial, zip_log_files +from queue import Queue from threading import Thread import flask from flask import request, abort, make_response, send_file @@ -35,13 +36,6 @@ except ImportError: ) sys.exit(1) -try: - # Python 2 - from Queue import Queue -except ImportError: - # Python 3 - from queue import Queue - # Inhibit Flask warning message about running a development server... (we know!) cli = sys.modules["flask.cli"] diff --git a/auto_rx/test/bit_to_samples.py b/auto_rx/test/bit_to_samples.py index 891fab8..972bdaa 100644 --- a/auto_rx/test/bit_to_samples.py +++ b/auto_rx/test/bit_to_samples.py @@ -4,27 +4,17 @@ # import sys -# Check if we are running in Python 2 or 3 -PY3 = sys.version_info[0] == 3 _sample_rate = int(sys.argv[1]) _symbol_rate = int(sys.argv[2]) _bit_length = _sample_rate // _symbol_rate -if PY3: - _zero = b'\x00'*_bit_length - _one = b'\xFF'*_bit_length +_zero = b'\x00'*_bit_length +_one = b'\xFF'*_bit_length - _in = sys.stdin.read - _out = sys.stdout.buffer.write - -else: - _zero = '\x00'*_bit_length - _one = '\xFF'*_bit_length - - _in = sys.stdin.read - _out = sys.stdout.write +_in = sys.stdin.read +_out = sys.stdout.buffer.write while True: _char = _in(1) diff --git a/auto_rx/utils/listener_nmea_crlf.py b/auto_rx/utils/listener_nmea_crlf.py index 7438ab9..7284f6f 100644 --- a/auto_rx/utils/listener_nmea_crlf.py +++ b/auto_rx/utils/listener_nmea_crlf.py @@ -13,12 +13,9 @@ import socket, json, sys, traceback from threading import Thread from dateutil.parser import parse from datetime import datetime, timedelta +from io import StringIO import time -try: - from StringIO import StringIO ## for Python 2 -except ImportError: - from io import StringIO ## for Python 3 MAX_JSON_LEN = 32768