Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions d_rats/dplatform_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import logging
# import mimetypes
import os
import shutil
from shutil import which
import subprocess
import sys
from contextlib import contextmanager
from urllib.request import urlretrieve
from serial.tools.list_ports import comports

# Need all of these packages for sound to work on a generic platform
# The pydub package not currently available on msys2 mingw64.
from contextlib import contextmanager
HAVE_AUDIO = False
if not os.name == "nt":
try:
Expand Down Expand Up @@ -57,9 +59,6 @@ def play(sound):
sound_type = type(sound)
print(f'Unable to play sound {sound_type} is unsupported')


import urllib.request

# This version of D-Rats requires GTK 3.0, but not for doing unit
# tests. This allows the default unit tests to pass on a system with
# out GTK+ installed.
Expand Down Expand Up @@ -134,7 +133,6 @@ def __str__(self):
return os.linesep.join(text)

def set_config_dir(self, basepath):

'''
Set the configuration directory.

Expand Down Expand Up @@ -200,14 +198,14 @@ def get_exe_path(name):
'''
# Make trivial check from the normal paths
# known false positive in pylance
exe_path = shutil.which(name) # type: ignore
exe_path = which(name) # type: ignore
if exe_path:
return exe_path
programfiles = os.getenv("PROGRAMFILES")
if programfiles:
for program in [programfiles, programfiles + " (x86)"]:
test_path=os.path.join(program, name)
exe_path = shutil.which(name, path=test_path) # type: ignore
exe_path = which(name, path=test_path) # type: ignore
if exe_path:
return exe_path
return None
Expand Down Expand Up @@ -285,15 +283,17 @@ def open_html_file(path):
gio_path = Gio.File.parse_name(path)
appinfo.launch([gio_path], None)

def list_serial_ports(self):
@staticmethod
def list_serial_ports():
'''
List Serial Ports.

:returns: empty list
:rtype: list
:returns: The serial ports
:rtype: list of str
'''
self.logger.info("list_serial_ports not available on this platform")
return []
ports = [port.device for port in comports()]
return ports


@staticmethod
def default_dir():
Expand Down Expand Up @@ -491,7 +491,7 @@ def retrieve_url(self, url):
:returns: Data from URL
'''
if self._connected:
return urllib.request.urlretrieve(url)
return urlretrieve(url)

raise NotConnectedError("Not connected")

Expand Down
15 changes: 1 addition & 14 deletions d_rats/dplatform_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copyright 2009 Dan Smith <dsmith@danplanet.com>
# review 2015 Maurizio Andreotti <iz2lxi@yahoo.it>
# Copyright 2021-2023 John. E. Malmberg - Python3 Conversion
# Copyright 2021-2023,2026 John. E. Malmberg - Python3 Conversion
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -18,7 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
import glob
import os
import sys

Expand Down Expand Up @@ -48,18 +47,6 @@ def __init__(self, basepath):

UnixPlatform.__init__(self, basepath)

def list_serial_ports(self):
'''
List Serial Ports.

:returns: serial port names
:rtype: list[str]
'''
keyspan = glob.glob("/dev/cu.KeySerial*")
prolific = glob.glob("/dev/tty.usbserial*")

return sorted(keyspan + prolific)

def os_version_string(self):
'''
OS Version String.
Expand Down
12 changes: 1 addition & 11 deletions d_rats/dplatform_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copyright 2009 Dan Smith <dsmith@danplanet.com>
# review 2015 Maurizio Andreotti <iz2lxi@yahoo.it>
# Copyright 2021-2023 John. E. Malmberg - Python3 Conversion
# Copyright 2021-2023,2026 John. E. Malmberg - Python3 Conversion
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -18,7 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
import glob
import os
import subprocess

Expand Down Expand Up @@ -79,15 +78,6 @@ def filter_filename(filename):
'''
return filename.replace("/", "")

def list_serial_ports(self):
'''
List Serial Ports.

:returns: The serial ports
:rtype: list of str
'''
return sorted(glob.glob("/dev/ttyS*") + glob.glob("/dev/ttyUSB*"))

def os_version_string(self):
'''
OS Version String.
Expand Down
48 changes: 1 addition & 47 deletions d_rats/dplatform_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copyright 2009 Dan Smith <dsmith@danplanet.com>
# review 2015 Maurizio Andreotti <iz2lxi@yahoo.it>
# Copyright 2021-2023 John. E. Malmberg - Python3 Conversion
# Copyright 2021-2023,2026 John. E. Malmberg - Python3 Conversion
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -38,14 +38,6 @@
from win32com.shell import shell # type: ignore
except ImportError:
pass
try:
import win32con # type: ignore
except ImportError:
pass
try:
import win32file # type: ignore
except ImportError:
pass
try:
import win32gui # type: ignore
except ImportError:
Expand Down Expand Up @@ -121,44 +113,6 @@ def filter_filename(filename):

return filename

def list_serial_ports(self):
'''
List Serial Ports.

:returns: List of serial ports
:rtype: list[str]
'''
ports = []
try:
for i in range(1, 257):
try:
portname = "COM%i" % i
mode = win32con.GENERIC_READ # type: ignore
mode |= win32con.GENERIC_WRITE # type: ignore
port = win32file.CreateFile( # type: ignore
portname,
mode,
win32con.FILE_SHARE_READ, # type: ignore
None,
win32con.OPEN_EXISTING, # type: ignore
0,
None)
ports.append(portname)
win32file.CloseHandle(port) # type: ignore
port = None

# On cross platform IDEs pylint may false positive.
# pylint: disable=no-member
except pywintypes.error as err: # type: ignore
# Error code 5 Apparently if the serial port is in use.
# Error code 121 Apparently if timeout in operation.
if err.args[0] not in [2, 5, 121]:
self.logger.info("list_serial_ports", exc_info=True)
except NameError:
self.logger.info("Unable to look up serial ports, "
"win32con or other python package missing!")
return ports

@staticmethod
def _mime_to_filter(mime_types):
'''
Expand Down
Loading