Skip to content

Commit

Permalink
1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sezanzeb committed Oct 20, 2021
1 parent 0f21297 commit 2803bb8
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: key-mapper
Version: 1.2.0
Version: 1.2.1
Architecture: all
Maintainer: Sezanzeb <[email protected]>
Depends: build-essential, libpython3-dev, libdbus-1-dev, python3, python3-setuptools, python3-evdev, python3-pydbus, python3-gi, gettext, python3-cairo, libgtk-3-0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions keymapper/ipc/shared_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions readme/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion readme/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 2 additions & 6 deletions readme/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion readme/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
Expand Down
1 change: 1 addition & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 10 additions & 7 deletions tests/testcases/test_ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import unittest
import select
import time

from keymapper.ipc.pipe import Pipe
from keymapper.ipc.shared_dict import SharedDict
Expand All @@ -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):
Expand Down

0 comments on commit 2803bb8

Please sign in to comment.