From 2a68ee8ef4513c5fc20d231a5a818147a8d7d520 Mon Sep 17 00:00:00 2001 From: MMGen Date: Sun, 17 Mar 2019 11:56:04 +0000 Subject: [PATCH] with open('foo') as f: t = f.read() -> t = open('foo').read() --- mmgen/main_autosign.py | 13 ++++++------- mmgen/opts.py | 8 +++----- mmgen/util.py | 5 ++--- test/test.py | 6 +++--- test/test_py_d/ts_autosign.py | 3 +-- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/mmgen/main_autosign.py b/mmgen/main_autosign.py index bfefddb3..f91554f0 100755 --- a/mmgen/main_autosign.py +++ b/mmgen/main_autosign.py @@ -325,13 +325,13 @@ def ev_sleep(secs): def do_led(on,off): if not on: - with open(status_ctl,'w') as f: f.write('0\n') + open(status_ctl,'w').write('0\n') while True: if ev_sleep(3600): return while True: for s_time,val in ((on,255),(off,0)): - with open(status_ctl,'w') as f: f.write('{}\n'.format(val)) + open(status_ctl,'w').write('{}\n'.format(val)) if ev_sleep(s_time): return def set_led(cmd): @@ -372,9 +372,8 @@ def do_loop(): def check_access(fn,desc='status LED control',init_val=None): try: - with open(fn) as f: b = f.read().strip() - with open(fn,'w') as f: - f.write('{}\n'.format(init_val or b)) + b = open(fn).read().strip() + open(fn,'w').write('{}\n'.format(init_val or b)) return True except: m1 = "You do not have access to the {} file\n".format(desc) @@ -414,7 +413,7 @@ def init_led(): sys.exit(1) if trigger_ctl: - with open(trigger_ctl,'w') as f: f.write('none\n') + open(trigger_ctl,'w').write('none\n') return status_ctl,trigger_ctl @@ -442,7 +441,7 @@ def at_exit(exit_val,nl=False): ev.set() led_thread.join() if trigger_ctl: - with open(trigger_ctl,'w') as f: f.write('mmc0\n') + open(trigger_ctl,'w').write('mmc0\n') sys.exit(exit_val) def handler(a,b): at_exit(1,nl=True) diff --git a/mmgen/opts.py b/mmgen/opts.py index a7a7a5e9..f2e2ddd1 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -99,8 +99,7 @@ def get_cfg_template_data(): + (['share'],['local','share'])[g.platform=='linux'] + [g.proj_name.lower(),os.path.basename(g.cfg_file)])) try: - with open(cfg_template,'r') as f: - return f.read() + return open(cfg_template).read() except: msg("WARNING: configuration template not found at '{}'".format(cfg_template)) return '' @@ -113,15 +112,14 @@ def get_data_from_cfg_file(): def copy_template_data(fn): try: - with open(fn,'wb') as f: f.write(template_data.encode()) + open(fn,'wb').write(template_data.encode()) os.chmod(fn,0o600) except: die(2,"ERROR: unable to write to datadir '{}'".format(g.data_dir)) for k,suf in (('cfg',''),('sample','.sample')): try: - with open(g.cfg_file+suf,'rb') as f: - data[k] = f.read().decode('utf8') + data[k] = open(g.cfg_file+suf,'rb').read().decode() except: if template_data: copy_template_data(g.cfg_file+suf) diff --git a/mmgen/util.py b/mmgen/util.py index 6dfe0391..f90fda91 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -219,12 +219,11 @@ def capfirst(s): # different from str.capitalize() - doesn't downcase any uc in return s if len(s) == 0 else s[0].upper() + s[1:] def decode_timestamp(s): -# with open('/etc/timezone') as f: -# tz_save = f.read().rstrip() +# tz_save = open('/etc/timezone').read().rstrip() os.environ['TZ'] = 'UTC' ts = time.strptime(s,'%Y%m%d_%H%M%S') t = time.mktime(ts) -# os.environ['TZ'] = tz_save +# os.environ['TZ'] = tz_save return int(t) def make_timestamp(secs=None): diff --git a/test/test.py b/test/test.py index 0bddb48a..38e27195 100755 --- a/test/test.py +++ b/test/test.py @@ -869,9 +869,9 @@ except Exception: print(''.join(traceback.format_exception(*sys.exc_info()))) try: os.stat('my.err') - with open('my.err') as f: - t = f.readlines() - if t: msg_r('\n'+yellow(''.join(t[:-1]))+red(t[-1])) + t = open('my.err').readlines() + if t: + msg_r('\n'+yellow(''.join(t[:-1]))+red(t[-1])) except: pass die(1,blue('Test script exited with error')) else: diff --git a/test/test_py_d/ts_autosign.py b/test/test_py_d/ts_autosign.py index 6e6ba285..996f22b9 100755 --- a/test/test_py_d/ts_autosign.py +++ b/test/test_py_d/ts_autosign.py @@ -116,8 +116,7 @@ class TestSuiteAutosign(TestSuiteBase): # make a bad tx file bad_tx = joinpath(mountpoint,'tx','bad.rawtx') if include_bad_tx and not remove_signed_only: - with open(bad_tx,'w') as f: - f.write('bad tx data') + open(bad_tx,'w').write('bad tx data') if not include_bad_tx: try: os.unlink(bad_tx) except: pass