implemented --debug option (#70)

* implemented --debug option
- Added --debug option that shows sys info
- Added inxi as dependency
- Implemented get_sys_info() that returns inxi output
  with injected governnor information
- Fixed bug: delete_file was called but this was deleted in prev PR
- Updated issue template
This commit is contained in:
Vadym Stupakov 2020-08-06 00:49:23 +03:00 committed by GitHub
parent c56c656193
commit e02f7a6881
4 changed files with 35 additions and 19 deletions

View File

@ -6,15 +6,6 @@ Paste here error output
### System information:
```text
Paste here output of inxi -Fz
```
---
How to install inxi:
```shell script
sudo apt install inxi # [On Debian/Ubuntu/Linux Mint]
sudo yum install inxi # [On CentOs/RHEL/Fedora]
sudo dnf install inxi # [On Fedora 22+]
sudo pacman -S inxi # [On Arch]
Paste here output of the auto-cpufreq --debug
```
---

View File

@ -52,7 +52,7 @@ then
echo -e "\nDetected Debian based distribution"
separator
echo -e "\nSetting up Python environment\n"
apt install python3-dev python3-pip -y
apt install python3-dev python3-pip inxi -y
separator
echo -e "\nInstalling necessary Python packages\n"
pip_pkg_install
@ -71,9 +71,9 @@ then
# CentOS exception
if [ -f /etc/centos-release ];
then
yum install platform-python-devel
yum install platform-python-devel inxi
else
yum install python-devel
yum install python-devel inxi
fi
echo -e "\nInstalling necessary Python packages\n"
pip_pkg_install
@ -88,7 +88,7 @@ else
separator
echo -e "\nDidn't detect Debian or RedHat based distro.\n"
echo -e "To complete installation, you need to:"
echo -e "Install: python3 and pip3\n"
echo -e "Install: python3, pip3 and inxi\n"
echo -e "Install necessary Python packages:"
echo -e "pip3 install psutil click distro power"
echo -e "\nRun following sequence of lines:"

View File

@ -22,8 +22,8 @@ import click
@click.option("--install/--remove", default=True, help="Install/remove daemon for automatic CPU optimizations")
@click.option("--log", is_flag=True, help="View live CPU optimization log made by daemon")
@click.option("--daemon", is_flag=True, hidden=True)
def main(monitor, live, daemon, install, log):
# print --help by default if no argument is provided when auto-cpufreq is run
@click.option("--debug", is_flag=True, help="Show debug info (include when submitting bugs)")
def main(monitor, live, daemon, install, log, debug):
if len(sys.argv) == 1:
print("\n" + "-" * 32 + " auto-cpufreq " + "-" * 33 + "\n")
print("Automatic CPU speed & power optimizer for Linux")
@ -31,8 +31,9 @@ def main(monitor, live, daemon, install, log):
print("\n-----\n")
s.call(["auto-cpufreq", "--help"])
footer(79)
footer()
else:
# Important: order does matter
if daemon:
if os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled":
while True:
@ -55,7 +56,7 @@ def main(monitor, live, daemon, install, log):
else:
print("\n" + "-" * 32 + " Daemon check " + "-" * 33 + "\n")
print("ERROR:\n\nDaemon not enabled, must run install first, i.e: \nsudo auto-cpufreq --install")
footer(79)
footer()
exit(1)
elif monitor:
while True:
@ -80,6 +81,10 @@ def main(monitor, live, daemon, install, log):
elif log:
# ToDo: fail if log is missing or empty (on)
read_log()
elif debug:
footer()
print(get_sys_info())
footer()
elif install:
if os.getenv('PKG_MARKER') == "SNAP":
root_check()
@ -99,7 +104,7 @@ def main(monitor, live, daemon, install, log):
root_check()
s.run("snapctl set daemon=disabled", shell=True)
s.run("snapctl stop --disable auto-cpufreq", shell=True)
delete_file(auto_cpufreq_log_file)
auto_cpufreq_log_file.unlink(missing_ok=True)
remove_complete_msg()
else:
root_check()

View File

@ -4,11 +4,13 @@
import os
import platform as pl
import re
import shutil
import subprocess as s
import sys
import time
from pathlib import Path
from subprocess import getoutput
import psutil as p
@ -53,6 +55,24 @@ def turbo(value: bool = None):
return value
def get_sys_info():
"""
Return sys info of inxi command with injected governors information
"""
govs = " ".join(get_avail_gov())
govs = f"Governors: {govs}"
if shutil.which("inxi") is not None:
sys_info = getoutput("inxi -Fz")
p = re.compile(pattern=r".*(CPU:\s+).+", flags=re.MULTILINE)
indent = " " * len(p.search(sys_info).group(1))
sys_info = p.sub(f"CPU:{indent[4:]}{govs}", sys_info)
else:
sys_info = ("Warning: inxi is not installed.\n"
f"{govs}")
return sys_info
def charging():
"""
get charge state: is battery charging or discharging