From 2803bb841e19232ec08c57bdfca66d0535131dab Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Wed, 20 Oct 2021 23:05:50 +0200 Subject: [PATCH] 1.2.1 --- DEBIAN/control | 2 +- README.md | 2 +- keymapper/ipc/shared_dict.py | 14 +++++++++----- readme/coverage.svg | 4 ++-- readme/development.md | 2 +- readme/examples.md | 8 ++------ readme/usage.md | 2 +- scripts/build.sh | 4 ++-- setup.py | 2 +- tests/test.py | 1 + tests/testcases/test_ipc.py | 17 ++++++++++------- 11 files changed, 31 insertions(+), 27 deletions(-) diff --git a/DEBIAN/control b/DEBIAN/control index 4ae353292..9bef29365 100644 --- a/DEBIAN/control +++ b/DEBIAN/control @@ -1,5 +1,5 @@ Package: key-mapper -Version: 1.2.0 +Version: 1.2.1 Architecture: all Maintainer: Sezanzeb Depends: build-essential, libpython3-dev, libdbus-1-dev, python3, python3-setuptools, python3-evdev, python3-pydbus, python3-gi, gettext, python3-cairo, libgtk-3-0 diff --git a/README.md b/README.md index 8ec27c949..65cb313ae 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ or install the latest changes via: sudo apt install git python3-setuptools gettext git clone https://github.com/sezanzeb/key-mapper.git cd key-mapper && ./scripts/build.sh -sudo apt install ./dist/key-mapper-1.2.0.deb +sudo apt install ./dist/key-mapper-1.2.1.deb ``` key-mapper is now part of [Debian Testing](https://packages.debian.org/testing/key-mapper) diff --git a/keymapper/ipc/shared_dict.py b/keymapper/ipc/shared_dict.py index 6e08c8b79..754119c33 100644 --- a/keymapper/ipc/shared_dict.py +++ b/keymapper/ipc/shared_dict.py @@ -37,27 +37,31 @@ class SharedDict: def __init__(self): """Create a shared dictionary.""" super().__init__() - self.pipe = multiprocessing.Pipe() - self.process = None - atexit.register(self._stop) - self._start() # To avoid blocking forever if something goes wrong. The maximum # observed time communication takes was 0.001 for me on a slow pc self._timeout = 0.02 + self.pipe = multiprocessing.Pipe() + self.process = None + atexit.register(self._stop) + self._start() + def _start(self): """Ensure the process to manage the dictionary is running.""" if self.process is not None and self.process.is_alive(): + logger.spam("SharedDict process already running") return # if the manager has already been running in the past but stopped - # for some reason, the dictionary contents are lost + # for some reason, the dictionary contents are lost. + logger.spam("Starting SharedDict process") self.process = multiprocessing.Process(target=self.manage) self.process.start() def manage(self): """Manage the dictionary, handle read and write requests.""" + logger.spam("SharedDict process started") shared_dict = dict() while True: message = self.pipe[0].recv() diff --git a/readme/coverage.svg b/readme/coverage.svg index daeae3602..3f8560087 100644 --- a/readme/coverage.svg +++ b/readme/coverage.svg @@ -17,7 +17,7 @@ coverage - 94% - 94% + 93% + 93% \ No newline at end of file diff --git a/readme/development.md b/readme/development.md index 79a8818a5..4d5c56012 100644 --- a/readme/development.md +++ b/readme/development.md @@ -86,7 +86,7 @@ ssh/login into a debian/ubuntu environment ./scripts/build.sh ``` -This will generate `key-mapper/deb/key-mapper-1.2.0.deb` +This will generate `key-mapper/deb/key-mapper-1.2.1.deb` ## Badges diff --git a/readme/examples.md b/readme/examples.md index 4ff505318..5faa23403 100644 --- a/readme/examples.md +++ b/readme/examples.md @@ -30,12 +30,8 @@ Examples for particular devices and/or use cases: - `if_tap(k(a), k(b), 1000)` writes a if the key is released within a second, otherwise b - `if_single(k(a), k(b))` writes b if another key is pressed, or a if the key is released and no other key was pressed in the meantime. - -## Double Tap - -`if_tap(if_tap(k(a), k(b)), k(c))` - -Will write "a" if tapped twice, "b" if tapped once and "c" if held down long enough +- `if_tap(if_tap(k(a), k(b)), k(c))` "a" if tapped twice, "b" if tapped once and "c" if + held down long enough ## Combinations Spanning Multiple Devices diff --git a/readme/usage.md b/readme/usage.md index 29b39e7a3..57b7b8fa2 100644 --- a/readme/usage.md +++ b/readme/usage.md @@ -107,7 +107,7 @@ configuration files. The default configuration is stored at `~/.config/key-mapper/config.json`, which doesn't include any mappings, but rather other parameters that -are interesting for injections. The current default configuration as of 1.2.0 +are interesting for injections. The current default configuration as of 1.2.1 looks like, with an example autoload entry: ```json diff --git a/scripts/build.sh b/scripts/build.sh index ef0892203..b2780f78e 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -9,8 +9,8 @@ build_deb() { mv build/deb/usr/local/lib/python3.*/ build/deb/usr/lib/python3/ cp ./DEBIAN build/deb/ -r mkdir dist -p - rm dist/key-mapper-1.2.0.deb || true - dpkg -b build/deb dist/key-mapper-1.2.0.deb + rm dist/key-mapper-1.2.1.deb || true + dpkg -b build/deb dist/key-mapper-1.2.1.deb } build_deb & diff --git a/setup.py b/setup.py index b58284c1f..0f2adccd0 100644 --- a/setup.py +++ b/setup.py @@ -96,7 +96,7 @@ def make_lang(): setup( name='key-mapper', - version='1.2.0', + version='1.2.1', description='A tool to change the mapping of your input device buttons', author='Sezanzeb', author_email='proxima@sezanzeb.de', diff --git a/tests/test.py b/tests/test.py index 59198e32c..6f8752205 100644 --- a/tests/test.py +++ b/tests/test.py @@ -574,6 +574,7 @@ def quick_cleanup(log=True): asyncio.set_event_loop(asyncio.new_event_loop()) if not macro_variables.process.is_alive(): + # nothing should stop the process during runtime raise AssertionError("the SharedDict manager is not running anymore") macro_variables._stop() diff --git a/tests/testcases/test_ipc.py b/tests/testcases/test_ipc.py index 52b44b036..81b7a0b97 100644 --- a/tests/testcases/test_ipc.py +++ b/tests/testcases/test_ipc.py @@ -21,6 +21,7 @@ import unittest import select +import time from keymapper.ipc.pipe import Pipe from keymapper.ipc.shared_dict import SharedDict @@ -30,19 +31,21 @@ class TestSharedDict(unittest.TestCase): + def setUp(self): + self.shared_dict = SharedDict() + time.sleep(0.02) + def tearDown(self): quick_cleanup() def test_returns_none(self): - shared_dict = SharedDict() - self.assertIsNone(shared_dict.get("a")) - self.assertIsNone(shared_dict["a"]) + self.assertIsNone(self.shared_dict.get("a")) + self.assertIsNone(self.shared_dict["a"]) def test_set_get(self): - shared_dict = SharedDict() - shared_dict["a"] = 3 - self.assertEqual(shared_dict.get("a"), 3) - self.assertEqual(shared_dict["a"], 3) + self.shared_dict["a"] = 3 + self.assertEqual(self.shared_dict.get("a"), 3) + self.assertEqual(self.shared_dict["a"], 3) class TestSocket(unittest.TestCase):