Skip to content

Commit

Permalink
#121 dependencies refactored from pip as apt packages for Ubuntu23.04…
Browse files Browse the repository at this point in the history
… + inotify to pyinotify
  • Loading branch information
ldrahnik committed Jun 22, 2023
1 parent c80f5e4 commit 9421498
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
48 changes: 25 additions & 23 deletions asus_touchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import Optional
import numpy as np
from libevdev import EV_ABS, EV_KEY, EV_LED, EV_MSC, EV_SYN, Device, InputEvent, const, device
from inotify import adapters
from pyinotify import WatchManager, IN_CLOSE_WRITE, IN_IGNORED, IN_MOVED_TO, AsyncNotifier
import Xlib.display
import Xlib.X
import Xlib.XK
Expand Down Expand Up @@ -864,9 +864,6 @@ def load_all_config_values():
# because inotify (deadlock)
sleep(0.1)

inotify_adapters = adapters.Inotify()
inotify_adapters.add_watch(config_file_dir)

def set_tracking_id(value):
try:

Expand Down Expand Up @@ -1638,29 +1635,35 @@ def check_numpad_automatical_disable_due_inactivity():


def check_config_values_changes():
global inotify_adapters, config_lock

try:
while not stop_threads:
for event in inotify_adapters.event_gen(yield_nones=False, timeout_s=1):
global config_lock, stop_threads

(_, type_names, path, filename) = event
watch_manager = WatchManager()

if filename != CONFIG_FILE_NAME or path != config_file_dir:
continue
path = os.path.abspath(config_file_dir)
mask = IN_CLOSE_WRITE | IN_IGNORED | IN_MOVED_TO
watch_manager.add_watch(path, mask)

if "IN_CLOSE_WRITE" in type_names or "IN_IGNORED" in type_names or "IN_MOVED_TO" in type_names:
event_notifier = AsyncNotifier(watch_manager)

if not config_lock.locked():
log.info("check_config_values_changes: detected external change of config file -> loading changes")
# because file might be read so fast that changes will not be there yet
sleep(0.1)
load_all_config_values()
else:
log.info("check_config_values_changes: detected internal change of config file -> do nothing -> would be deadlock")
while not stop_threads:
try:
event_notifier.process_events()
if event_notifier.check_events():
event_notifier.read_events()

if not config_lock.locked():
log.info("check_config_values_changes: detected external change of config file -> loading changes")
# because file might be read so fast that changes will not be there yet
sleep(0.1)
load_all_config_values()
else:
log.info("check_config_values_changes: detected internal change of config file -> do nothing -> would be deadlock")

except KeyboardInterrupt:
break

except:
pass
event_notifier.stop()
watch_manager.del_watch(path)

log.info("check_config_values_changes: inotify watching config file ended")

Expand Down Expand Up @@ -1711,7 +1714,6 @@ def check_config_values_changes():

# then clean up
stop_threads=True
inotify_adapters.remove_watch(config_file_dir)
fd_t.close()
for thread in threads:
thread.join()
Expand Down
20 changes: 13 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ session_id=$(loginctl | grep $SUDO_USER | head -1 | awk '{print $1}')
wayland_or_x11=$(loginctl show-session $session_id -p Type --value)

if [[ $(apt install 2>/dev/null) ]]; then
echo 'apt is here' && apt -y install ibus libevdev2 i2c-tools python3-dev python3-pip
echo 'apt is here' && apt -y install ibus libevdev2 i2c-tools python3-dev python3-libevdev python3-numpy python3-xlib python3-pyinotify
if [ "$wayland_or_x11" = "x11" ]; then
apt -y install xinput
fi
Expand All @@ -38,19 +38,25 @@ elif [[ $(pacman -h 2>/dev/null) ]]; then
if [ "$wayland_or_x11" = "x11" ]; then
pacman --noconfirm --needed -S xorg-xinput
fi

runuser -u $RUN_UNDER_USER -- python3 -m pip install -r requirements.txt

if [[ $? != 0 ]]; then
echo "pip dependencies via file requirements.txt cannot be loaded correctly."
exit 1
fi
elif [[ $(dnf install 2>/dev/null) ]]; then
echo 'dnf is here' && dnf -y install ibus libevdev i2c-tools python3-devel python3-pip
if [ "$wayland_or_x11" = "x11" ]; then
dnf -y install xinput
fi
fi

runuser -u $RUN_UNDER_USER -- python3 -m pip install -r requirements.txt
runuser -u $RUN_UNDER_USER -- python3 -m pip install -r requirements.txt

# Checking if the pip dependencies are successfuly loaded
if [[ $? != 0 ]]; then
echo "pip dependencies via file requirements.txt cannot be loaded correctly."
exit 1
if [[ $? != 0 ]]; then
echo "pip dependencies via file requirements.txt cannot be loaded correctly."
exit 1
fi
fi

modprobe i2c-dev
Expand Down

0 comments on commit 9421498

Please sign in to comment.