Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgillij committed Feb 16, 2021
1 parent 8adfd7a commit 5933086
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = E501
48 changes: 20 additions & 28 deletions amdfan/amdfan.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
from rich.table import Table
from rich.live import Live
from rich.logging import RichHandler

install() # install traceback formatter

CONFIG_LOCATIONS = [
"/etc/amdgpu-fan.yml",
"/home/j/amdgpu-fan.yml", # remove later
]

DEBUG = bool(os.environ.get('DEBUG', False))
DEBUG = bool(os.environ.get("DEBUG", False))

ROOT_DIR = "/sys/class/drm"
HWMON_DIR = "device/hwmon"
Expand Down Expand Up @@ -59,10 +60,7 @@ def __init__(self, card_id):
def _verify_card(self):
for endpoint in self.AMD_FIELDS:
if endpoint not in self._endpoints:
LOGGER.info(
"skipping card: %s missing endpoint %s",
self._id, endpoint
)
LOGGER.info("skipping card: %s missing endpoint %s", self._id, endpoint)
raise FileNotFoundError

def _load_endpoints(self):
Expand All @@ -82,9 +80,7 @@ def write_endpoint(self, endpoint, data):
with open(self._endpoints[endpoint], "w") as endpoint_file:
return endpoint_file.write(str(data))
except PermissionError:
LOGGER.error(
"Failed writing to devfs file, are you running as root?"
)
LOGGER.error("Failed writing to devfs file, are you running as root?")
sys.exit(1)

@property
Expand Down Expand Up @@ -247,7 +243,7 @@ def __init__(self, points: list):
configuration error ?"
)
if np.min(self.speeds) <= 3:
raise ValueError('Lowest speed value to be set to 4') # Driver BUG
raise ValueError("Lowest speed value to be set to 4") # Driver BUG

def get_speed(self, temp):
"""
Expand All @@ -267,20 +263,20 @@ def load_config(path):

@click.command()
@click.option(
'--daemon',
is_flag=True,
default=False,
help='Run as daemon applying the fan curve')
"--daemon", is_flag=True, default=False, help="Run as daemon applying the fan curve"
)
@click.option(
'--monitor',
is_flag=True,
default=False,
help='Run as a monitor showing temp and fan speed')
"--monitor",
is_flag=True,
default=False,
help="Run as a monitor showing temp and fan speed",
)
@click.option(
'--manual',
is_flag=True,
default=False,
help='Manually set the fan speed value of a card')
"--manual",
is_flag=True,
default=False,
help="Manually set the fan speed value of a card",
)
def cli(daemon, monitor, manual):
if daemon:
run_as_daemon()
Expand Down Expand Up @@ -327,9 +323,7 @@ def run_as_daemon():
break

if config is None:
LOGGER.info(
"No config found, creating one in %s", CONFIG_LOCATIONS[-1]
)
LOGGER.info("No config found, creating one in %s", CONFIG_LOCATIONS[-1])
with open(CONFIG_LOCATIONS[-1], "w") as config_file:
config_file.write(default_fan_config)
config_file.flush()
Expand Down Expand Up @@ -364,9 +358,7 @@ def set_fan_speed():
scanner = Scanner()
card_to_set = Prompt.ask("Which card?", choices=scanner.cards.keys())
while True:
input_fan_speed = Prompt.ask(
"Fan speed, [1..100]% or 'auto'", default="auto"
)
input_fan_speed = Prompt.ask("Fan speed, [1..100]% or 'auto'", default="auto")

if input_fan_speed.isdigit():
if int(input_fan_speed) >= 1 and int(input_fan_speed) <= 100:
Expand All @@ -386,5 +378,5 @@ def set_fan_speed():
c.print(selected_card.set_fan_speed(int(input_fan_speed)))


if __name__ == '__main__':
if __name__ == "__main__":
cli() # pylint: disable=no-value-for-parameter

0 comments on commit 5933086

Please sign in to comment.