diff --git a/REVHubInterface/__main__.py b/REVHubInterface/__main__.py index ee111de..18bb3ed 100644 --- a/REVHubInterface/__main__.py +++ b/REVHubInterface/__main__.py @@ -9,12 +9,15 @@ import os import datetime import traceback - +import REVHubInterface.serialaccess as serialaccess # try: # import ft232 # except Exception as e: # print(platform.system) # tkinter.messagebox.showerror('Drivers Not Detected', 'Please verify the correct drivers are installed. Without the correct dirvers, firmware update functionality will be unavailable.\n\n - Windows 10 and above should automatically install the correct drivers when the Expansion Hub is plugged in.\n\n - Windows 7 requires a manual install. Please see this link for the correct driver (FTDI D2xx): https://www.ftdichip.com/Drivers/CDM/CDM21228_Setup.zip\n\n - On macOS, install libftdi via Homebrew: "brew install libftdi"\n\n - On Linux, install libftdi. On Debian/Ubuntu-based systems, install it via "sudo apt install libftdi1"\n\nException Message:\n' + str(e)) +if not serialaccess.hasAccess(): + tkinter.messagebox.showerror("User does not have serial access", "Your user does not have access to serial. Switch to a user that does, or add your user to a group that has serial access.\nhttps://github.com/unofficial-rev-port/REVHubInterface/blob/main/README.md#access-to-serial-on-linux") + def error(windowName: str, error: Exception) -> None: errName = str(error) print(errName) diff --git a/REVHubInterface/serialaccess.py b/REVHubInterface/serialaccess.py new file mode 100644 index 0000000..0f646aa --- /dev/null +++ b/REVHubInterface/serialaccess.py @@ -0,0 +1,12 @@ +import grp +import os, sys + +def hasAccess(): + if sys.platform == "linux": + try: + groups = [g.gr_name for g in grp.getgrall() if os.getlogin() in g.gr_mem] + if 'dialout' in groups or 'uucp' in groups: return True + return False + except KeyError: + return False + else: return True