fohrloop / wakepy

Cross-platform keep-awake with python
MIT License
195 stars 14 forks source link

Improve warnings and errors if platform is not supported #383

Closed fohrloop closed 2 months ago

fohrloop commented 2 months ago

Closes: #378

Add platform information automatically to error/warning texts. When the wakepy CLI command fails, it would now print

❯ python -m wakepy
                  _
                 | |
 __      __ __ _ | | __ ___  _ __   _   _
 \ \ /\ / // _` || |/ // _ \| '_ \ | | | |
  \ V  V /| (_| ||   <|  __/| |_) || |_| |
   \_/\_/  \__,_||_|\_\\___|| .__/  \__, |
  v.0.9.2.dev13+g2aab0eb    | |      __/ |
                            |_|     |___/ 
 [x] System will continue running programs
 [ ] Display is kept on and automatic screenlock disabled.

Wakepy could not activate the "keep.running" mode. This might occur because of a
bug or because your current platform is not yet supported or your system is
missing required software.

Check if there is already a related issue in the issue tracker at
https://github.com/fohrloop/wakepy/issues/ and if not, please create a new one.

Include the following:
- wakepy version: 0.9.2.dev13+g2aab0eb
- Mode: keep.running
- Python version: 3.12.5 (main, Aug 23 2024, 00:00:00) [GCC 14.2.1 20240801 (Red
Hat 14.2.1-1)]
- os.name: posix
- sys.platform: linux
- platform.system(): Linux
- platform.release(): 6.10.9-200.fc40.x86_64
- platform.machine(): x86_64
- sysconfig.get_platform(): linux-x86_64
- DESKTOP_SESSION: gnome
- (/etc/os-release) NAME: "Fedora Linux"
- (/etc/os-release) VERSION: "40 (Workstation Edition)"
- (/etc/os-release) ID: fedora
- (/etc/os-release) VERSION_ID: 40
- (/etc/os-release) VERSION_CODENAME: ""
- (/etc/os-release) PLATFORM_ID: "platform:f40"
- (/etc/os-release) PRETTY_NAME: "Fedora Linux 40 (Workstation Edition)"
- (/etc/os-release) VARIANT: "Workstation Edition"
- (/etc/os-release) VARIANT_ID: workstation
- Additional details: [FILL OR REMOVE THIS LINE]

Thank you!

The parts from os.name until (/etc/os-release) VARIANT_ID are added in this PR. In addition, when determining the current platform with get_current_platform(), if platform (for example linux) could not be determined, would previously get:

/home/fohrloop/code/wakepy/src/wakepy/core/platform.py:28: UserWarning: Could not detect current platform! platform.system() returned Linux
  warnings.warn(

and now:

/home/fohrloop/code/wakepy/src/wakepy/core/platform.py:31: UserWarning: Could not detect current platform! Debug info:
- os.name: posix
- sys.platform: linux
- platform.system(): Linux
- platform.release(): 6.10.9-200.fc40.x86_64
- platform.machine(): x86_64
- sysconfig.get_platform(): linux-x86_64
- DESKTOP_SESSION: gnome
- (/etc/os-release) NAME: "Fedora Linux"
- (/etc/os-release) VERSION: "40 (Workstation Edition)"
- (/etc/os-release) ID: fedora
- (/etc/os-release) VERSION_ID: 40
- (/etc/os-release) VERSION_CODENAME: ""
- (/etc/os-release) PLATFORM_ID: "platform:f40"
- (/etc/os-release) PRETTY_NAME: "Fedora Linux 40 (Workstation Edition)"
- (/etc/os-release) VARIANT: "Workstation Edition"
- (/etc/os-release) VARIANT_ID: workstation