Browse Source

switched to python3 and virtualenv

erpalma 6 years ago
parent
commit
6db2b091f2
6 changed files with 46 additions and 20 deletions
  1. 0 12
      Makefile
  2. 1 1
      README.md
  3. 34 0
      install.sh
  4. 5 5
      lenovo_fix.py
  5. 4 0
      requirements.txt
  6. 2 2
      systemd/lenovo_fix.service

+ 0 - 12
Makefile

@@ -1,12 +0,0 @@
-all: install
-
-install:
-	install -d /usr/local/sbin/
-	install -d /etc/systemd/system/
-	install -m 700 lenovo_fix.py /usr/local/sbin/
-	install -m 644 systemd/lenovo_fix.service /etc/systemd/system/
-	@if test -f /etc/lenovo_fix.conf; then \
-    	echo "/etc/lenovo_fix.conf already exists; overwrite manually"; \
-	else \
-    	install -m 644 etc/lenovo_fix.conf /etc/; \
-    fi

+ 1 - 1
README.md

@@ -4,7 +4,7 @@ Workaround for Linux throttling issues on Lenovo T480 / T480s / X1C6 notebooks a
 This script forces the CPU package power limit (PL1/2) to **44 W** (29 W on battery) and the temperature trip point to **97 'C** (85 'C on battery) by overriding default values in MSR and MCHBAR every 5 seconds (30 on battery) to block the Embedded Controller from resetting these values to default.
 
 ## Requirements
-The python module `python-periphery` is used for accessing the MCHBAR register by memory mapped I/O. 
+The python module `python-periphery` is used for accessing the MCHBAR register by memory mapped I/O.
 
 ## Installation
 ```

+ 34 - 0
install.sh

@@ -0,0 +1,34 @@
+#!/bin/sh
+
+INSTALL_DIR="/opt/lenovo_fix"
+
+systemctl stop lenovo_fix.service &>/dev/null
+
+mkdir -p "$INSTALL_DIR" &>/dev/null
+set -e
+
+cd "$(dirname "$0")"
+
+echo "Copying config file..."
+if [ ! -f /etc/lenovo_fix.conf ]; then
+	cp etc/lenovo_fix.conf /etc
+else
+	echo "Config file already exists, skipping."
+fi
+
+echo "Copying systemd service file..."
+cp systemd/lenovo_fix.service /etc/systemd/system
+
+echo "Building virtualenv..."
+cp requirements.txt lenovo_fix.py "$INSTALL_DIR"
+cd "$INSTALL_DIR"
+virtualenv -p /usr/bin/python3 venv
+source venv/bin/activate
+pip install -r requirements.txt
+
+echo "Enabling and starting systemd service..."
+systemctl daemon-reload
+systemctl enable lenovo_fix.service
+systemctl restart lenovo_fix.service
+
+echo "All done."

+ 5 - 5
lenovo_fix.py

@@ -1,6 +1,6 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 
-import ConfigParser
+import configparser
 import dbus
 import glob
 import os
@@ -49,8 +49,8 @@ def is_on_battery():
 
 
 def calc_time_window_vars(t):
-    for Y in xrange(2**5):
-        for Z in xrange(2**2):
+    for Y in range(2**5):
+        for Z in range(2**2):
             if t <= (2**Y) * (1. + Z / 4.) * 0.000977:
                 return (Y, Z)
     raise Exception('Unable to find a good combination!')
@@ -70,7 +70,7 @@ def calc_undervolt_msr(plane, offset):
 
 
 def load_config():
-    config = ConfigParser.ConfigParser()
+    config = configparser.ConfigParser()
     config.read(CONFIG_PATH)
 
     for power_source in ('AC', 'BATTERY'):

+ 4 - 0
requirements.txt

@@ -0,0 +1,4 @@
+configparser==3.5.0
+dbus-python==1.2.4
+PyGObject==3.28.2
+python-periphery==1.1.1

+ 2 - 2
systemd/lenovo_fix.service

@@ -3,7 +3,7 @@ Description=Fix Lenovo T480/T480s/X1C6 throttling on Linux
 
 [Service]
 Type=simple
-ExecStart=/usr/local/sbin/lenovo_fix.py
+ExecStart=/opt/lenovo_fix/venv/bin/python3 /opt/lenovo_fix/lenovo_fix.py
 
 [Install]
-WantedBy=multi-user.target
+WantedBy=multi-user.target