switched to python3 and virtualenv

This commit is contained in:
erpalma
2018-04-20 10:46:00 +02:00
parent 1d92edf769
commit 6db2b091f2
6 changed files with 46 additions and 20 deletions

View File

@@ -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

34
install.sh Executable file
View File

@@ -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."

View File

@@ -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
requirements.txt Normal file
View File

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

View File

@@ -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