Browse Source

confirm_or_raise() cleanups

The MMGen Project 3 years ago
parent
commit
224b6a70d0
5 changed files with 24 additions and 12 deletions
  1. 9 3
      mmgen/fileutil.py
  2. 4 1
      mmgen/main_addrimport.py
  3. 3 3
      mmgen/tx/online.py
  4. 5 4
      mmgen/util.py
  5. 3 1
      mmgen/wallet/incog_hidden.py

+ 9 - 3
mmgen/fileutil.py

@@ -177,7 +177,9 @@ def write_data_to_file( outfile,data,desc='data',
 			if no_tty:
 				die(2,f'Printing {desc} to screen is not allowed')
 			if (ask_tty and not opt.quiet) or binary:
-				confirm_or_raise('',f'output {desc} to screen')
+				confirm_or_raise(
+					message = '',
+					action  = f'output {desc} to screen' )
 		else:
 			try:    of = os.readlink(f'/proc/{os.getpid()}/fd/1') # Linux
 			except: of = None # Windows
@@ -187,7 +189,9 @@ def write_data_to_file( outfile,data,desc='data',
 					if no_tty:
 						die(2,f'Writing {desc} to pipe is not allowed')
 					if ask_tty and not opt.quiet:
-						confirm_or_raise('',f'output {desc} to pipe')
+						confirm_or_raise(
+							message = '',
+							action  = f'output {desc} to pipe' )
 						msg('')
 				of2,pd = os.path.relpath(of),os.path.pardir
 				msg('Redirecting output to file {!r}'.format(of if of2[:len(pd)] == pd else of2))
@@ -217,7 +221,9 @@ def write_data_to_file( outfile,data,desc='data',
 
 		hush = False
 		if os.path.lexists(outfile) and ask_overwrite:
-			confirm_or_raise('',f'File {outfile!r} already exists\nOverwrite?')
+			confirm_or_raise(
+				message = '',
+				action  = f'File {outfile!r} already exists\nOverwrite?' )
 			msg(f'Overwriting file {outfile!r}')
 			hush = True
 

+ 4 - 1
mmgen/main_addrimport.py

@@ -109,7 +109,10 @@ def check_opts(tw):
 		rescan = False
 
 	if rescan and not opt.quiet:
-		confirm_or_raise(ai_msgs('rescan'),'continue',expect='YES')
+		confirm_or_raise(
+			message = ai_msgs('rescan'),
+			action  = 'continue',
+			expect  = 'YES' )
 
 	if batch and not 'batch' in tw.caps:
 		msg(f"'--batch' ignored: not supported by {type(tw).__name__}")

+ 3 - 3
mmgen/tx/online.py

@@ -25,7 +25,7 @@ class OnlineSigned(Signed):
 
 	def confirm_send(self):
 		confirm_or_raise(
-			('' if opt.quiet else "Once this transaction is sent, there's no taking it back!"),
-			f'broadcast this transaction to the {self.proto.coin} {self.proto.network.upper()} network',
-			('YES' if opt.quiet or opt.yes else 'YES, I REALLY WANT TO DO THIS') )
+			message = '' if opt.quiet else 'Once this transaction is sent, there’s no taking it back!',
+			action  = f'broadcast this transaction to the {self.proto.coin} {self.proto.network.upper()} network',
+			expect  = 'YES' if opt.quiet or opt.yes else 'YES, I REALLY WANT TO DO THIS' )
 		msg('Sending transaction')

+ 5 - 4
mmgen/util.py

@@ -459,12 +459,13 @@ def check_wallet_extension(fn):
 def make_full_path(outdir,outfile):
 	return os.path.normpath(os.path.join(outdir, os.path.basename(outfile)))
 
-def confirm_or_raise(message,q,expect='YES',exit_msg='Exiting at user request'):
+def confirm_or_raise(message,action,expect='YES',exit_msg='Exiting at user request'):
 	if message.strip():
 		msg(message.strip())
-	a = f'{q}  ' if q[0].isupper() else f'Are you sure you want to {q}?\n'
-	b = f'Type uppercase {expect!r} to confirm: '
-	if line_input(a+b).strip() != expect:
+	if line_input(
+			(f'{action}  ' if action[0].isupper() else f'Are you sure you want to {action}?\n') +
+			f'Type uppercase {expect!r} to confirm: '
+		).strip() != expect:
 		die( 'UserNonConfirmation', exit_msg )
 
 def get_words_from_user(prompt):

+ 3 - 1
mmgen/wallet/incog_hidden.py

@@ -136,7 +136,9 @@ class wallet(wallet):
 		if check_offset:
 			self._check_valid_offset(f,'write')
 			if not opt.quiet:
-				confirm_or_raise( '', f'alter file {f.name!r}' )
+				confirm_or_raise(
+					message = '',
+					action  = f'alter file {f.name!r}' )
 
 		flgs = os.O_RDWR|os.O_BINARY if g.platform == 'win' else os.O_RDWR
 		fh = os.open(f.name,flgs)