Skip to content

Commit 645c8e5

Browse files
author
Alec Leamas
committed
lib: pycodestyle fixes
1 parent 76ad965 commit 645c8e5

File tree

6 files changed

+36
-23
lines changed

6 files changed

+36
-23
lines changed

ddupdate-config

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ sys.path.insert(0, os.path.join(HERE, 'lib'))
1414
try:
1515
from lib.ddupdate import config
1616
except (ImportError, ModuleNotFoundError):
17-
from ddupdate import config
17+
from ddupdate import config
1818

1919
config.main()

lib/ddupdate/config.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# address-options = foo bar
2525
"""
2626

27+
2728
class _GoodbyeError(Exception):
2829
"""General error, implies sys.exit()."""
2930

@@ -82,10 +83,12 @@ def _load_addressers(log, paths):
8283
"""Load address plugins from paths into dict keyed by name."""
8384
return _load_plugins(log, paths, AddressPlugin)
8485

86+
8587
def _load_auth_plugins(log, paths):
8688
"""Load auth plugins from paths into dict keyed by name."""
8789
return _load_plugins(log, paths, AuthPlugin)
8890

91+
8992
def get_service_plugin(service_plugins):
9093
"""
9194
Present a menu with all plugins to user, let her select.
@@ -113,6 +116,7 @@ def get_service_plugin(service_plugins):
113116
raise _GoodbyeError("Illegal selection\n", 2)
114117
return services_by_ix[ix]
115118

119+
116120
def get_auth_plugin(plugins):
117121
"""
118122
Present a menu with all auth plugins to user, let her select.
@@ -142,7 +146,6 @@ def get_auth_plugin(plugins):
142146
return plugins_by_ix[ix]
143147

144148

145-
146149
def get_address_plugin(log, paths):
147150
"""
148151
Let user select address plugin.
@@ -206,13 +209,13 @@ def copy_systemd_units():
206209
with open(os.path.join(user_dir, 'ddupdate.service')) as f:
207210
lines = f.readlines()
208211
output = []
209-
for l in lines:
210-
if l.startswith('ExecStart'):
212+
for line in lines:
213+
if line.startswith('ExecStart'):
211214
output.append("ExecStart=" + bindir + "/ddupdate")
212215
else:
213-
output.append(l)
214-
with open(os.path.join(user_dir, 'ddupdate.service'), 'w') as f:
215-
f.write('\n'.join([l.strip() for l in output]))
216+
output.append(line)
217+
with open(os.path.join(user_dir, 'ddupdate.service'), 'w') as f:
218+
f.write(['\n'.join(elem.strip()) for elem in output])
216219

217220

218221
def get_netrc(service):
@@ -295,6 +298,7 @@ def write_config_files(config):
295298
os.unlink(tmp_conf)
296299
print("Patched config file: " + dest)
297300

301+
298302
def write_credentials(auth_plugin, hostname, netrc):
299303
""" Update credentials at auth_plugin with data from netrc. """
300304
username = None
@@ -313,14 +317,15 @@ def write_credentials(auth_plugin, hostname, netrc):
313317
auth_plugin.set_password(hostname, username, password)
314318
print("Updated password for user %s at %s" % (username, hostname))
315319

320+
316321
def try_start_service():
317322
"""Start dduppdate systemd user service and display logs."""
318323
print("Starting service and displaying logs")
319324
cmd = 'systemctl --user daemon-reload'
320325
cmd += ';systemctl --user start ddupdate.service'
321326
cmd += ';journalctl -l --user --since -60s -u ddupdate.service'
322327
cmd = ['sh', '-c', cmd]
323-
subprocess.run(cmd, check = True)
328+
subprocess.run(cmd, check=True)
324329
print('Use "journalctl --user -u ddupdate.service" to display logs.')
325330

326331

@@ -332,12 +337,12 @@ def enable_service():
332337
cmd = 'systemctl --user start ddupdate.timer'
333338
cmd += ';systemctl --user enable ddupdate.timer'
334339
print("\nStarting and enabling ddupdate.timer")
335-
subprocess.run(['sh', '-c', cmd], check = True)
340+
subprocess.run(['sh', '-c', cmd], check=True)
336341
else:
337342
cmd = 'systemctl --user stop ddupdate.timer'
338343
cmd += 'systemctl --user disable ddupdate.timer'
339344
print("Stopping ddupdate.timer")
340-
subprocess.run(['sh', '-c', cmd], check = True)
345+
subprocess.run(['sh', '-c', cmd], check=True)
341346
msg = "systemctl --user start ddupdate.timer"
342347
msg += "; systemctl --user enable ddupdate.timer"
343348
print('\nStart ddupdate using "%s"' % msg)

lib/ddupdate/ddplugin.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def get_auth_plugin():
4343

4444
# pylint: disable=duplicate-code
4545

46+
4647
def http_basic_auth_setup(url, host=None):
4748
"""
4849
Configure urllib to provide basic authentication.
@@ -108,13 +109,13 @@ def get_response(log, url, **kwargs):
108109
log.debug("Posting data: " + data.decode('ascii'))
109110
try:
110111
request = urllib.request.Request(url)
111-
if 'header' in kwargs:
112+
if 'header' in kwargs:
112113
request.add_header(*kwargs['header'])
113114
with urllib.request.urlopen(request, data, timeout=to) as response:
114115
code = response.getcode()
115116
html = response.read().decode('ascii')
116117
except timeoutError:
117-
raise ServiceError("Timeout reading %s" % url) from None
118+
raise ServiceError("Timeout reading %s" % url) from None
118119
except (urllib.error.HTTPError, urllib.error.URLError) as err:
119120
raise ServiceError("Error reading %s :%s" % (url, err)) from err
120121
log.debug("Got response (%d) : %s", code, html)
@@ -179,7 +180,7 @@ def parse_ifconfig_output(self, text):
179180
180181
"""
181182
for line in text.split('\n'):
182-
words = [ word for word in line.split(' ') if word != '' ]
183+
words = [word for word in line.split(' ') if word != '']
183184
if words[0] == 'inet':
184185
# use existing logic
185186
self.v4 = words[1].split('/')[0]
@@ -189,7 +190,7 @@ def parse_ifconfig_output(self, text):
189190
continue
190191
addr = words[1].split('/')[0]
191192
words = set(words[2:])
192-
if ('link' in words) or ('0x20<link>' in words) :
193+
if ('link' in words) or ('0x20<link>' in words):
193194
# don't use a link-local address
194195
continue
195196
if 'deprecated' in words:
@@ -224,6 +225,7 @@ def __str__(self):
224225
class ServiceError(AddressError):
225226
"""General error in ServicePlugin."""
226227

228+
227229
class AuthError(AddressError):
228230
"""General error in AuthPlugin."""
229231

lib/ddupdate/main.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from ddupdate.ddplugin import set_auth_plugin, get_auth_plugin
2323

2424

25-
2625
if 'XDG_CACHE_HOME' in os.environ:
2726
CACHE_DIR = os.environ['XDG_CACHE_HOME']
2827
else:
@@ -139,13 +138,14 @@ def parse_conffile(log):
139138
def parse_config(config, section):
140139
"""Return dict with values from config backed by DEFAULTS"""
141140
results = {}
142-
if not section in config:
141+
if section not in config:
143142
raise _GoodbyeError("No such section: " + section, 2)
144143
items = config[section]
145-
for key, value in DEFAULTS.items():
144+
for key, value in DEFAULTS.items():
146145
results[key] = items[key] if key in items else value
147146
return results
148147

148+
149149
def get_config(log):
150150
""" Parse config file, return a (ConfigParser, list of sections) tuple."""
151151
path = parse_conffile(log)
@@ -229,7 +229,7 @@ def get_parser(conf):
229229
help='List configuration file sections. ',
230230
default=False, action='store_true')
231231
others.add_argument(
232-
"-e", "--execute-section", metavar="section",
232+
"-e", "--execute-section", metavar="section",
233233
help='Update a given configuration file section [all sections]',
234234
dest='execute_section', default='')
235235
others.add_argument(
@@ -387,6 +387,7 @@ def set_password(opts):
387387
auth_plugin = get_auth_plugin()
388388
auth_plugin.set_password(*opts.set_password)
389389

390+
390391
def filter_ip(ip_version, ip):
391392
"""Filter the ip address to match the --ip-version option."""
392393
if ip_version == 'v4':
@@ -472,7 +473,7 @@ def get_ip(ip_plugin, opts, log):
472473
ip = ip_plugin.get_ip(log, opts.address_options)
473474
except AddressError as err:
474475
raise _SectionFailError("Cannot obtain ip address: " + str(err)) \
475-
from err
476+
from err
476477
if not ip or ip.empty():
477478
log.info("Using ip address provided by update service")
478479
ip = None
@@ -516,7 +517,7 @@ def main():
516517
ip = get_ip(ip_plugin, opts, log)
517518
check_ip_cache(ip, service_plugin, opts, log)
518519
service_plugin.register(
519-
log, opts.hostname, ip, opts.service_options)
520+
log, opts.hostname, ip, opts.service_options)
520521
ip_cache_set(opts, ip)
521522
log.info("Update OK")
522523
except _SectionFailError:

lib/ddupdate/netrc_to_keyring.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import keyring
88

9+
910
def main():
1011
""" Indeed: main function. """
1112
_netrc = netrc.netrc()
@@ -15,5 +16,6 @@ def main():
1516
credentials = "{0}\t{1}".format((login or 'api_key'), password)
1617
keyring.set_password('ddupdate', host, credentials)
1718

19+
1820
if __name__ == '__main__':
1921
main()

setup.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""ddupdate install data."""
22

3-
# pylint: disable=bad-option-value, import-outside-toplevel, consider-using-with
3+
# pylint: disable=bad-option-value, import-outside-toplevel
4+
# pylint: disable=consider-using-with
45

56
import shutil
67
import os
@@ -22,7 +23,7 @@ def systemd_unitdir():
2223
try:
2324
return subprocess.check_output(cmd).decode().strip()
2425
except (OSError, subprocess.CalledProcessError):
25-
return "/usr/lib/systemd/user"
26+
return "/usr/lib/systemd/user"
2627

2728

2829
DATA = [
@@ -46,12 +47,13 @@ def run(self):
4647
if os.path.exists(path):
4748
shutil.rmtree(path)
4849

50+
4951
class _ProjectInstall(install):
5052
"""Log used installation paths."""
5153

5254
def run(self):
5355
final_prefix = None
54-
if 'FINAL_PREFIX' in os.environ:
56+
if 'FINAL_PREFIX' in os.environ:
5557
final_prefix = os.environ['FINAL_PREFIX']
5658
if final_prefix:
5759
# Strip leading prefix in paths like /usr/lib/systemd,
@@ -87,6 +89,7 @@ def run(self):
8789
f.write("[install]\n")
8890
f.write(s)
8991

92+
9093
setup(
9194
name='ddupdate',
9295
version='0.7.0',

0 commit comments

Comments
 (0)