diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b42097e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/__pycache__/ \ No newline at end of file diff --git a/README.md b/README.md index ef2e0da..eb04e24 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ If you are worried about malicious code, the script is pretty small you can easi ## Dependencies - Linux (tested under Ubuntu 12.04) -- Python (tested under 2.7.3) +- Python (tested under 3.12.2) - SoX (in debian based systems install by typing "sudo apt-get install sox"); ## Future diff --git a/linux_clicky/detect_keyboards.py b/linux_clicky/detect_keyboards.py index 6883db4..4d43765 100644 --- a/linux_clicky/detect_keyboards.py +++ b/linux_clicky/detect_keyboards.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*- # Author: Fábio André Damas @@ -8,7 +8,7 @@ def detect_keyboards(): file_handle = open('/proc/bus/input/devices', 'r') keyboards = [] - regex = regex_compile("event\d{0,3}") + regex = regex_compile("event\\d{0,3}") for line in file_handle.readlines(): if 'Handlers' in line: if 'kbd' in line: @@ -19,4 +19,4 @@ def detect_keyboards(): if __name__ == '__main__': - print detect_keyboards() + print(detect_keyboards()) diff --git a/linux_clicky/play_sound.py b/linux_clicky/play_sound.py index ad2b692..3a7d367 100644 --- a/linux_clicky/play_sound.py +++ b/linux_clicky/play_sound.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*- # Author: Fábio André Damas @@ -13,10 +13,10 @@ def __init__(self, filename, volume): self.volume = volume def run(self): - cmd = 'play -v ' + self.volume + ' ' + self.filename + cmd = 'XDG_RUNTIME_DIR=/run/user/1000 play -v ' + self.volume + ' ' + self.filename p = Popen(cmd, shell=True, stderr=PIPE, close_fds=True) # TODO: Test if limits the number of clicks p.wait() if p.returncode != 0: - print '\033[1;31mWe found a error with SoX, did you install it?\033[1;m' + print('\033[1;31mWe found a error with SoX, did you install it?\033[1;m') p.stderr.read() diff --git a/main.py b/main.py index 45aeb74..a7213c1 100755 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*- # Author: Fábio André Damas @@ -14,8 +14,8 @@ # Handle CTRL+C def signal_handler(signal, frame): - print '\033[1;32mCTRL + C Detected. Exiting ...' - print 'Ignore any errors after this message.\033[1;m' + print('\033[1;32mCTRL + C Detected. Exiting ...') + print('Ignore any errors after this message.\033[1;m') exit(0) signal(SIGINT, signal_handler) diff --git a/third_party/evdev.py b/third_party/evdev.py index fd6b656..c3e75a3 100644 --- a/third_party/evdev.py +++ b/third_party/evdev.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ evdev.py @@ -37,12 +37,12 @@ def demo(): while 1: event = dev.next_event() if event is not None: - print repr(event) + print(repr(event)) if event.type == "EV_KEY" and event.value == 1: if event.code.startswith("KEY"): - print event.scanCode + print(event.scanCode) elif event.code.startswith("BTN"): - print event.code + print(event.code) class BaseDevice: """Base class representing the state of an input device, with axes and buttons. @@ -83,10 +83,10 @@ def __getitem__(self, name): # evdev ioctl constants. The horrible mess here # is to silence silly FutureWarnings -EVIOCGNAME_512 = ~int(~0x82004506L & 0xFFFFFFFFL) -EVIOCGID = ~int(~0x80084502L & 0xFFFFFFFFL) -EVIOCGBIT_512 = ~int(~0x81fe4520L & 0xFFFFFFFFL) -EVIOCGABS_512 = ~int(~0x80144540L & 0xFFFFFFFFL) +EVIOCGNAME_512 = ~int(~0x82004506 & 0xFFFFFFFF) +EVIOCGID = ~int(~0x80084502 & 0xFFFFFFFF) +EVIOCGBIT_512 = ~int(~0x81fe4520 & 0xFFFFFFFF) +EVIOCGABS_512 = ~int(~0x80144540 & 0xFFFFFFFF) class Device(BaseDevice): @@ -145,7 +145,7 @@ def __init__(self, fileNames): for fileName in fileNames: self.devices.append(Device(fileName)) for device in self.devices: - print repr(device) + print(repr(device)) self.fds.append(device.fd) def next_event(self): @@ -167,7 +167,7 @@ def close(self): try: os.close(fd) except: - print "Warning - failed to close on or more device file descriptors" + print("Warning - failed to close on or more device file descriptors") pass @@ -179,7 +179,7 @@ class EnumDict: def __init__(self, numberMap): self.numberMap = numberMap self.nameMap = {} - for key, value in numberMap.iteritems(): + for key, value in numberMap.items(): self.nameMap[value] = key def toNumber(self, name):