Remove Python 2 compatibility hacks

Not used any more ...
pull/665/head
Jiří Pinkava 2022-09-21 00:57:39 +02:00
rodzic 3e061465c8
commit 664352bd77
15 zmienionych plików z 23 dodań i 124 usunięć

Wyświetl plik

@ -17,6 +17,7 @@ import time
import traceback import traceback
import os import os
from dateutil.parser import parse from dateutil.parser import parse
from queue import Queue
if sys.version_info < (3, 6): if sys.version_info < (3, 6):
print("CRITICAL - radiosonde_auto_rx requires Python 3.6 or newer!") 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.gpsd import GPSDAdaptor
from autorx.sdr_wrappers import shutdown_sdr from autorx.sdr_wrappers import shutdown_sdr
try:
# Python 2
from Queue import Queue
except ImportError:
# Python 3
from queue import Queue
# Logging level # Logging level
# INFO = Basic status messages # INFO = Basic status messages

Wyświetl plik

@ -5,12 +5,7 @@
# Copyright (C) 2018 Mark Jessop <vk5qi@rfhead.net> # Copyright (C) 2018 Mark Jessop <vk5qi@rfhead.net>
# Released under GNU GPL v3 or later # Released under GNU GPL v3 or later
# #
try: from queue import Queue
# Python 2
from Queue import Queue
except ImportError:
# Python 3
from queue import Queue
# Now using Semantic Versioning (https://semver.org/) MAJOR.MINOR.PATCH # Now using Semantic Versioning (https://semver.org/) MAJOR.MINOR.PATCH
# MAJOR - Only updated when something huge changes to the project (new decode chain, etc) # MAJOR - Only updated when something huge changes to the project (new decode chain, etc)

Wyświetl plik

@ -11,17 +11,11 @@ import random
import time import time
import traceback import traceback
import socket import socket
from queue import Queue
from threading import Thread, Lock from threading import Thread, Lock
from . import __version__ as auto_rx_version from . import __version__ as auto_rx_version
from .utils import strip_sonde_serial 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( def telemetry_to_aprs_position(
sonde_data, object_name="<id>", aprs_comment="BOM Balloon", position_report=False sonde_data, object_name="<id>", aprs_comment="BOM Balloon", position_report=False

Wyświetl plik

@ -11,6 +11,7 @@ import logging
import os import os
import traceback import traceback
import json import json
from configparser import RawConfigParser
from .sdr_wrappers import test_sdr from .sdr_wrappers import test_sdr
# Dummy initial config with some parameters we need to make the web interface happy. # Dummy initial config with some parameters we need to make the web interface happy.
@ -26,13 +27,6 @@ global_config = {
# Web interface credentials # Web interface credentials
web_password = "none" 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 # Fixed minimum update rates for APRS & Habitat
# These are set to avoid congestion on the APRS-IS network, and on the Habitat server # 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. # Please respect other users of these networks and leave these settings as they are.

Wyświetl plik

@ -11,19 +11,12 @@ import time
import smtplib import smtplib
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.utils import formatdate from email.utils import formatdate
from queue import Queue
from threading import Thread from threading import Thread
from .config import read_auto_rx_config from .config import read_auto_rx_config
from .utils import position_info, strip_sonde_serial from .utils import position_info, strip_sonde_serial
from .geometry import GenericTrack from .geometry import GenericTrack
try:
# Python 2
from Queue import Queue
except ImportError:
# Python 3
from queue import Queue
class EmailNotification(object): class EmailNotification(object):
""" Radiosonde Email Notification Class. """ Radiosonde Email Notification Class.

Wyświetl plik

@ -15,16 +15,10 @@ import traceback
import json import json
from base64 import b64encode from base64 import b64encode
from hashlib import sha256 from hashlib import sha256
from queue import Queue
from threading import Thread, Lock from threading import Thread, Lock
from . import __version__ as auto_rx_version 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 # These get replaced out after init
url_habitat_uuids = "" url_habitat_uuids = ""
url_habitat_db = "" url_habitat_db = ""

Wyświetl plik

@ -10,15 +10,9 @@ import glob
import logging import logging
import os import os
import time import time
from queue import Queue
from threading import Thread from threading import Thread
try:
# Python 2
from Queue import Queue
except ImportError:
# Python 3
from queue import Queue
class TelemetryLogger(object): class TelemetryLogger(object):
""" Radiosonde Telemetry Logger Class. """ Radiosonde Telemetry Logger Class.

Wyświetl plik

@ -10,15 +10,9 @@ import json
import logging import logging
import socket import socket
import time import time
from queue import Queue
from threading import Thread from threading import Thread
try:
# Python 2
from Queue import Queue
except ImportError:
# Python 3
from queue import Queue
class OziUploader(object): class OziUploader(object):
""" Push radiosonde telemetry out via UDP broadcast to the Horus Chase-Car Utilities """ Push radiosonde telemetry out via UDP broadcast to the Horus Chase-Car Utilities

Wyświetl plik

@ -10,16 +10,10 @@ import socket
import time import time
import numpy as np import numpy as np
from queue import Queue
from threading import Thread, Lock from threading import Thread, Lock
from autorx.utils import position_info 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): def read_rotator(rotctld_host="localhost", rotctld_port=4533, timeout=5):
""" Attempt to read a position from a rotctld server. """ Attempt to read a position from a rotctld server.

Wyświetl plik

@ -13,6 +13,7 @@ import platform
import subprocess import subprocess
import time import time
import traceback import traceback
from io import StringIO
from threading import Thread, Lock from threading import Thread, Lock
from types import FunctionType, MethodType from types import FunctionType, MethodType
from .utils import ( from .utils import (
@ -24,12 +25,6 @@ from .utils import (
) )
from .sdr_wrappers import * from .sdr_wrappers import *
try:
# Python 2
from StringIO import StringIO
except ImportError:
# Python 3
from io import StringIO
try: try:
from .web import flask_emit_event from .web import flask_emit_event

Wyświetl plik

@ -18,16 +18,10 @@ import logging
import os import os
import requests import requests
import time import time
from queue import Queue
from threading import Thread from threading import Thread
from email.utils import formatdate from email.utils import formatdate
try:
# Python 2
from Queue import Queue
except ImportError:
# Python 3
from queue import Queue
class SondehubUploader(object): class SondehubUploader(object):
""" Sondehub Uploader Class. """ Sondehub Uploader Class.
@ -83,20 +77,10 @@ class SondehubUploader(object):
# Record of when we last uploaded a user station position to Sondehub. # Record of when we last uploaded a user station position to Sondehub.
self.last_user_position_upload = 0 self.last_user_position_upload = 0
try: # Start queue processing thread.
# Python 2 check. Python 2 doesnt have gzip.compress so this will throw an exception. self.input_processing_running = True
gzip.compress(b"\x00\x00") self.input_process_thread = Thread(target=self.process_queue)
self.input_process_thread.start()
# 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
def update_station_position(self, lat, lon, alt): def update_station_position(self, lat, lon, alt):
""" Update the internal station position record. Used when determining the station position by GPSD """ """ Update the internal station position record. Used when determining the station position by GPSD """

Wyświetl plik

@ -22,15 +22,9 @@ import semver
from dateutil.parser import parse from dateutil.parser import parse
from datetime import datetime, timedelta from datetime import datetime, timedelta
from math import radians, degrees, sin, cos, atan2, sqrt, pi from math import radians, degrees, sin, cos, atan2, sqrt, pi
from queue import Queue
from . import __version__ as auto_rx_version 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 # List of binaries we check for on startup
REQUIRED_RS_UTILS = [ REQUIRED_RS_UTILS = [
@ -723,8 +717,7 @@ def is_not_linux():
# Second check for the existence of '-Microsoft' in the uname release field. # Second check for the existence of '-Microsoft' in the uname release field.
# This is a good check that we are running in WSL. # 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().release:
if "Microsoft" in platform.uname()[2]:
return True return True
# Else, we're probably in native Linux! # Else, we're probably in native Linux!

Wyświetl plik

@ -21,6 +21,7 @@ import autorx.scan
from autorx.geometry import GenericTrack from autorx.geometry import GenericTrack
from autorx.utils import check_autorx_versions from autorx.utils import check_autorx_versions
from autorx.log_files import list_log_files, read_log_by_serial, zip_log_files from autorx.log_files import list_log_files, read_log_by_serial, zip_log_files
from queue import Queue
from threading import Thread from threading import Thread
import flask import flask
from flask import request, abort, make_response, send_file from flask import request, abort, make_response, send_file
@ -35,13 +36,6 @@ except ImportError:
) )
sys.exit(1) 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!) # Inhibit Flask warning message about running a development server... (we know!)
cli = sys.modules["flask.cli"] cli = sys.modules["flask.cli"]

Wyświetl plik

@ -4,27 +4,17 @@
# #
import sys import sys
# Check if we are running in Python 2 or 3
PY3 = sys.version_info[0] == 3
_sample_rate = int(sys.argv[1]) _sample_rate = int(sys.argv[1])
_symbol_rate = int(sys.argv[2]) _symbol_rate = int(sys.argv[2])
_bit_length = _sample_rate // _symbol_rate _bit_length = _sample_rate // _symbol_rate
if PY3: _zero = b'\x00'*_bit_length
_zero = b'\x00'*_bit_length _one = b'\xFF'*_bit_length
_one = b'\xFF'*_bit_length
_in = sys.stdin.read _in = sys.stdin.read
_out = sys.stdout.buffer.write _out = sys.stdout.buffer.write
else:
_zero = '\x00'*_bit_length
_one = '\xFF'*_bit_length
_in = sys.stdin.read
_out = sys.stdout.write
while True: while True:
_char = _in(1) _char = _in(1)

Wyświetl plik

@ -13,12 +13,9 @@ import socket, json, sys, traceback
from threading import Thread from threading import Thread
from dateutil.parser import parse from dateutil.parser import parse
from datetime import datetime, timedelta from datetime import datetime, timedelta
from io import StringIO
import time import time
try:
from StringIO import StringIO ## for Python 2
except ImportError:
from io import StringIO ## for Python 3
MAX_JSON_LEN = 32768 MAX_JSON_LEN = 32768