From 644d7e76104dc17241c5a50b4b006f6fa9bf052f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Dec 2016 17:23:53 -0500 Subject: [PATCH 1/4] acpi-update.py: there is no "Error" class Evidently this code path was never hit, because we'd crash with NameError. The exception message also seems bogus. So just replace the whole thing with the standard exception for invalid input. --- hwdb/acpi-update.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hwdb/acpi-update.py b/hwdb/acpi-update.py index 2dc8c7c064..50da531dc6 100755 --- a/hwdb/acpi-update.py +++ b/hwdb/acpi-update.py @@ -31,7 +31,7 @@ class PNPTableParser(HTMLParser): elif self.state == State.AFTER_PNPID: self.state = State.DATE else: - raise Error("Unexpected field") + raise ValueError self.data = "" @@ -48,7 +48,7 @@ class PNPTableParser(HTMLParser): elif self.state == State.DATE: self.state = State.NOWHERE else: - raise Error("Unexpected field") + raise ValueError def handle_data(self, data): self.data += data From 00d5eaafd13338bb2f3cb78a16b8f10f11ddeb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Dec 2016 17:30:31 -0500 Subject: [PATCH 2/4] python: adjust imports, indentation, unused variables following pylint advice --- src/journal-remote/log-generator.py | 4 ++-- test/networkd-test.py | 4 ++-- test/sysv-generator-test.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/journal-remote/log-generator.py b/src/journal-remote/log-generator.py index 24874e960c..7b434b334e 100755 --- a/src/journal-remote/log-generator.py +++ b/src/journal-remote/log-generator.py @@ -29,7 +29,7 @@ _SOURCE_REALTIME_TIMESTAMP={source_realtime_ts} DATA={data} """ -m = 0x198603b12d7 +m = 0x198603b12d7 realtime_ts = 1404101101501873 monotonic_ts = 1753961140951 source_realtime_ts = 1404101101483516 @@ -71,5 +71,5 @@ for i in range(OPTIONS.n): print('.', file=sys.stderr, end='', flush=True) if OPTIONS.dots: - print(file=sys.stderr) + print(file=sys.stderr) print('Wrote {} bytes'.format(bytes), file=sys.stderr) diff --git a/test/networkd-test.py b/test/networkd-test.py index 3023cac97d..f15cc199a5 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -153,7 +153,7 @@ DHCP=%s # check iface state and IP 6 address; FIXME: we need to wait a bit # longer, as the iface is "configured" already with IPv4 *or* # IPv6, but we want to wait for both - for timeout in range(10): + for _ in range(10): out = subprocess.check_output(['ip', 'a', 'show', 'dev', self.iface]) if b'state UP' in out and b'inet6 2600' in out and b'inet 192.168' in out: break @@ -558,7 +558,7 @@ exec $(systemctl cat systemd-networkd.service | sed -n '/^ExecStart=/ { s/^.*=// '--service-type=notify', script]) # wait until devices got created - for timeout in range(50): + for _ in range(50): out = subprocess.check_output(['ip', 'a', 'show', 'dev', self.if_router]) if b'state UP' in out and b'scope global' in out: break diff --git a/test/sysv-generator-test.py b/test/sysv-generator-test.py index 50175485f7..16ea65690a 100755 --- a/test/sysv-generator-test.py +++ b/test/sysv-generator-test.py @@ -308,7 +308,7 @@ class SysvGeneratorTest(unittest.TestCase): err, results = self.run_generator() self.assertEqual(list(results), ['foo.service']) self.assertEqual(os.readlink(os.path.join(self.out_dir, 'foo\\x2b.service')), - 'foo.service') + 'foo.service') self.assertNotIn('Overwriting', err) def test_same_provides_in_multiple_scripts(self): From 8d9d1e3af0d4f67eb9b994291e88eace39fc8b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Dec 2016 19:10:01 -0500 Subject: [PATCH 3/4] hwdb_parse: adjust indentation and imports following pylint advice (This commit is separate to make it easy to export to libinput.) --- hwdb/parse_hwdb.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hwdb/parse_hwdb.py b/hwdb/parse_hwdb.py index 97c796863f..16f74b0777 100755 --- a/hwdb/parse_hwdb.py +++ b/hwdb/parse_hwdb.py @@ -26,7 +26,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -import functools import glob import string import sys @@ -35,7 +34,7 @@ import os try: from pyparsing import (Word, White, Literal, ParserElement, Regex, LineStart, LineEnd, - ZeroOrMore, OneOrMore, Combine, Or, Optional, Suppress, Group, + OneOrMore, Combine, Or, Optional, Suppress, Group, nums, alphanums, printables, stringEnd, pythonStyleComment, QuotedString, ParseBaseException) @@ -67,7 +66,7 @@ TYPES = {'mouse': ('usb', 'bluetooth', 'ps2', '*'), 'evdev': ('name', 'atkbd', 'input'), 'touchpad': ('i8042', 'rmi', 'bluetooth', 'usb'), 'keyboard': ('name', ), - } + } @lru_cache() def hwdb_grammar(): @@ -83,7 +82,7 @@ def hwdb_grammar(): group = (OneOrMore(matchline('MATCHES*') ^ COMMENTLINE.suppress()) - OneOrMore(propertyline('PROPERTIES*') ^ propertycomment.suppress()) - - (EMPTYLINE ^ stringEnd()).suppress() ) + (EMPTYLINE ^ stringEnd()).suppress()) commentgroup = OneOrMore(COMMENTLINE).suppress() - EMPTYLINE.suppress() grammar = OneOrMore(group('GROUPS*') ^ commentgroup) + stringEnd() @@ -105,18 +104,18 @@ def property_grammar(): ('POINTINGSTICK_CONST_ACCEL', REAL), ('ID_INPUT_TOUCHPAD_INTEGRATION', Or(('internal', 'external'))), ('XKB_FIXED_LAYOUT', STRING), - ('XKB_FIXED_VARIANT', STRING) - ) + ('XKB_FIXED_VARIANT', STRING), + ) fixed_props = [Literal(name)('NAME') - Suppress('=') - val('VALUE') for name, val in props] kbd_props = [Regex(r'KEYBOARD_KEY_[0-9a-f]+')('NAME') - Suppress('=') - ('!' ^ (Optional('!') - Word(alphanums + '_')))('VALUE') - ] + ] abs_props = [Regex(r'EVDEV_ABS_[0-9a-f]{2}')('NAME') - Suppress('=') - Word(nums + ':')('VALUE') - ] + ] grammar = Or(fixed_props + kbd_props + abs_props) @@ -189,8 +188,7 @@ def print_summary(fname, groups): .format(fname, len(groups), sum(len(matches) for matches, props in groups), - sum(len(props) for matches, props in groups), - )) + sum(len(props) for matches, props in groups))) if __name__ == '__main__': args = sys.argv[1:] or glob.glob(os.path.dirname(sys.argv[0]) + '/[67]0-*.hwdb') From cda39975dc08a613cd7aad74217cc272aff5cc3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Dec 2016 18:29:54 -0500 Subject: [PATCH 4/4] python: use raw strings for regexp patterns Behaviour is not changed, because "unknown" escapes like \s or \d were not substituted, but it's much nicer to use raw strings to avoid ambiguity. --- test/networkd-test.py | 24 ++++++++++++------------ test/rule-syntax-check.py | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/networkd-test.py b/test/networkd-test.py index f15cc199a5..2461155f8b 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -166,30 +166,30 @@ DHCP=%s else: # should have link-local address on IPv6 only out = subprocess.check_output(['ip', '-6', 'a', 'show', 'dev', self.iface]) - self.assertRegex(out, b'inet6 fe80::.* scope link') + self.assertRegex(out, br'inet6 fe80::.* scope link') self.assertNotIn(b'scope global', out) # should have IPv4 address out = subprocess.check_output(['ip', '-4', 'a', 'show', 'dev', self.iface]) self.assertIn(b'state UP', out) - self.assertRegex(out, b'inet 192.168.5.\d+/.* scope global dynamic') + self.assertRegex(out, br'inet 192.168.5.\d+/.* scope global dynamic') # check networkctl state out = subprocess.check_output(['networkctl']) - self.assertRegex(out, ('%s\s+ether\s+routable\s+unmanaged' % self.if_router).encode()) - self.assertRegex(out, ('%s\s+ether\s+routable\s+configured' % self.iface).encode()) + self.assertRegex(out, (r'%s\s+ether\s+routable\s+unmanaged' % self.if_router).encode()) + self.assertRegex(out, (r'%s\s+ether\s+routable\s+configured' % self.iface).encode()) out = subprocess.check_output(['networkctl', 'status', self.iface]) - self.assertRegex(out, b'Type:\s+ether') - self.assertRegex(out, b'State:\s+routable.*configured') - self.assertRegex(out, b'Address:\s+192.168.5.\d+') + self.assertRegex(out, br'Type:\s+ether') + self.assertRegex(out, br'State:\s+routable.*configured') + self.assertRegex(out, br'Address:\s+192.168.5.\d+') if ipv6: - self.assertRegex(out, b'2600::') + self.assertRegex(out, br'2600::') else: - self.assertNotIn(b'2600::', out) - self.assertRegex(out, b'fe80::') - self.assertRegex(out, b'Gateway:\s+192.168.5.1') - self.assertRegex(out, b'DNS:\s+192.168.5.1') + self.assertNotIn(br'2600::', out) + self.assertRegex(out, br'fe80::') + self.assertRegex(out, br'Gateway:\s+192.168.5.1') + self.assertRegex(out, br'DNS:\s+192.168.5.1') except (AssertionError, subprocess.CalledProcessError): # show networkd status, journal, and DHCP server log on failure with open(self.config) as f: diff --git a/test/rule-syntax-check.py b/test/rule-syntax-check.py index e4185cb0fa..dab01f1d8a 100755 --- a/test/rule-syntax-check.py +++ b/test/rule-syntax-check.py @@ -34,10 +34,10 @@ else: sys.exit(2) rules_files = glob(os.path.join(rules_dir, '*.rules')) -no_args_tests = re.compile('(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$') -args_tests = re.compile('(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$') -no_args_assign = re.compile('(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|PROGRAM|RUN|LABEL|GOTO|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*"([^"]*)"$') -args_assign = re.compile('(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)\s*"([^"]*)"$') +no_args_tests = re.compile(r'(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|RESULT|TEST)\s*(?:=|!)=\s*"([^"]*)"$') +args_tests = re.compile(r'(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"([^"]*)"$') +no_args_assign = re.compile(r'(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|PROGRAM|RUN|LABEL|GOTO|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*"([^"]*)"$') +args_assign = re.compile(r'(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)\s*"([^"]*)"$') result = 0 buffer = ''