Browse Source

with open('foo') as f: t = f.read() -> t = open('foo').read()

MMGen 6 years ago
parent
commit
2a68ee8ef4
5 changed files with 15 additions and 20 deletions
  1. 6 7
      mmgen/main_autosign.py
  2. 3 5
      mmgen/opts.py
  3. 2 3
      mmgen/util.py
  4. 3 3
      test/test.py
  5. 1 2
      test/test_py_d/ts_autosign.py

+ 6 - 7
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)

+ 3 - 5
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)

+ 2 - 3
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):

+ 3 - 3
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:

+ 1 - 2
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