Skip to content

Commit

Permalink
Merge pull request systemd#4797 from keszybz/pylint
Browse files Browse the repository at this point in the history
Python cleanups based on pylint advice
  • Loading branch information
martinpitt authored Dec 2, 2016
2 parents cd05bb8 + cda3997 commit cd66af2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions hwdb/acpi-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def handle_starttag(self, tag, attrs):
elif self.state == State.AFTER_PNPID:
self.state = State.DATE
else:
raise Error("Unexpected field")
raise ValueError

self.data = ""

Expand All @@ -48,7 +48,7 @@ def handle_endtag(self, tag):
elif self.state == State.DATE:
self.state = State.NOWHERE
else:
raise Error("Unexpected field")
raise ValueError

def handle_data(self, data):
self.data += data
Expand Down
18 changes: 8 additions & 10 deletions hwdb/parse_hwdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +34,7 @@
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)
Expand Down Expand Up @@ -67,7 +66,7 @@
'evdev': ('name', 'atkbd', 'input'),
'touchpad': ('i8042', 'rmi', 'bluetooth', 'usb'),
'keyboard': ('name', ),
}
}

@lru_cache()
def hwdb_grammar():
Expand All @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions src/journal-remote/log-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
DATA={data}
"""

m = 0x198603b12d7
m = 0x198603b12d7
realtime_ts = 1404101101501873
monotonic_ts = 1753961140951
source_realtime_ts = 1404101101483516
Expand Down Expand Up @@ -71,5 +71,5 @@
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)
28 changes: 14 additions & 14 deletions test/networkd-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def do_test(self, coldplug=True, ipv6=False, extra_opts='',
# 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
Expand All @@ -166,30 +166,30 @@ def do_test(self, coldplug=True, ipv6=False, extra_opts='',
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:
Expand Down Expand Up @@ -558,7 +558,7 @@ def create_iface(self, ipv6=False, dhcpserver_opts=None):
'--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
Expand Down
8 changes: 4 additions & 4 deletions test/rule-syntax-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
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 = ''
Expand Down
2 changes: 1 addition & 1 deletion test/sysv-generator-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_provides_escaped(self):
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):
Expand Down

0 comments on commit cd66af2

Please sign in to comment.