confirm_or_exit() -> confirm_or_raise()

This commit is contained in:
The MMGen Project 2018-10-16 16:28:33 +00:00
commit b00c11b578
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
8 changed files with 20 additions and 13 deletions

View file

@ -23,3 +23,4 @@ mmgen.exception: Exception classes for the MMGen suite
class UnrecognizedTokenSymbol(Exception): pass
class TokenNotInBlockchain(Exception): pass
class UserNonConfirmation(Exception): pass

View file

@ -59,5 +59,7 @@ def launch(what):
except:
try: m = e.message.decode('utf8')
except: m = repr(e.message)
from mmgen.util import ydie
ydie(2,u'\nERROR: ' + m)
from mmgen.util import die,ydie
if type(e).__name__ == 'UserNonConfirmation': die(1,m)
else: ydie(2,u'\nERROR: ' + m)

View file

@ -115,7 +115,7 @@ if opt.rescan and not 'rescan' in tw.caps:
opt.rescan = False
if opt.rescan and not opt.quiet:
confirm_or_exit(ai_msgs('rescan'),'continue',expect='YES')
confirm_or_raise(ai_msgs('rescan'),'continue',expect='YES')
if opt.batch and not 'batch' in tw.caps:
msg("'--batch' ignored: not supported by {}".format(type(tw).__name__))

View file

@ -145,7 +145,7 @@ if invoked_as == 'passchg':
if invoked_as == 'passchg' and ss_in.infile.dirname == g.data_dir:
m1 = yellow('Confirmation of default wallet update')
m2 = 'update the default wallet'
confirm_or_exit(m1,m2,exit_msg='Password not changed')
confirm_or_raise(m1,m2,exit_msg='Password not changed')
ss_out.write_to_file(desc='New wallet',outdir=g.data_dir)
msg('Securely deleting old wallet')
from subprocess import check_output,CalledProcessError

View file

@ -1041,7 +1041,7 @@ harder to find, you're advised to choose a much larger file size than this.
if check_offset:
self._check_valid_offset(f,'write')
if not opt.quiet:
confirm_or_exit('',"alter file '{}'".format(f.name))
confirm_or_raise('',"alter file '{}'".format(f.name))
flgs = os.O_RDWR|os.O_BINARY if g.platform == 'win' else os.O_RDWR
fh = os.open(f.name,flgs)

View file

@ -360,8 +360,12 @@ watch-only wallet using '{}-addrimport' and then re-run this program.
of = '{}-{}[{}].out'.format(self.dump_fn_pfx,g.dcoin,
','.join(self.sort_info(include_group=False)).lower())
msg('')
write_data_to_file(of,self.format_for_printing(),desc='{} listing'.format(self.desc))
oneshot_msg = yellow("Data written to '{}'\n\n".format(of))
try:
write_data_to_file(of,self.format_for_printing(),desc='{} listing'.format(self.desc))
except UserNonConfirmation as e:
oneshot_msg = red("File '{}' not overwritten by user request\n\n".format(of))
else:
oneshot_msg = yellow("Data written to '{}'\n\n".format(of))
elif action in ('a_view','a_view_wide'):
do_pager(self.fmt_display if action == 'a_view' else self.format_for_printing(color=True))
if g.platform == 'linux' and oneshot_msg == None:

View file

@ -888,7 +888,7 @@ Selected non-{pnm} inputs: {{}}""".strip().format(pnm=g.proj_name,pnl=g.proj_nam
m1 = ("Once this transaction is sent, there's no taking it back!",'')[bool(opt.quiet)]
m2 = 'broadcast this transaction to the {} network'.format(g.chain.upper())
m3 = ('YES, I REALLY WANT TO DO THIS','YES')[bool(opt.quiet or opt.yes)]
confirm_or_exit(m1,m2,m3)
confirm_or_raise(m1,m2,m3)
msg('Sending transaction')
def send(self,prompt_user=True,exit_on_fail=False):

View file

@ -521,13 +521,13 @@ def get_new_passphrase(desc,passchg=False):
if pw == '': qmsg('WARNING: Empty passphrase')
return pw
def confirm_or_exit(message,q,expect='YES',exit_msg='Exiting at user request'):
def confirm_or_raise(message,q,expect='YES',exit_msg='Exiting at user request'):
m = message.strip()
if m: msg(m)
a = q+' ' if q[0].isupper() else 'Are you sure you want to {}?\n'.format(q)
b = "Type uppercase '{}' to confirm: ".format(expect)
if my_raw_input(a+b).strip() != expect:
die(1,exit_msg)
raise UserNonConfirmation,exit_msg
def write_data_to_file( outfile,data,desc='data',
ask_write=False,
@ -557,7 +557,7 @@ def write_data_to_file( outfile,data,desc='data',
if no_tty:
die(2,'Printing {} to screen is not allowed'.format(desc))
if (ask_tty and not opt.quiet) or binary:
confirm_or_exit('','output {} to screen'.format(desc))
confirm_or_raise('','output {} to screen'.format(desc))
else:
try: of = os.readlink('/proc/{}/fd/1'.format(os.getpid())) # Linux
except: of = None # Windows
@ -567,7 +567,7 @@ def write_data_to_file( outfile,data,desc='data',
if no_tty:
die(2,'Writing {} to pipe is not allowed'.format(desc))
if ask_tty and not opt.quiet:
confirm_or_exit('','output {} to pipe'.format(desc))
confirm_or_raise('','output {} to pipe'.format(desc))
msg('')
of2,pd = os.path.relpath(of),os.path.pardir
msg(u"Redirecting output to file '{}'".format((of2,of)[of2[:len(pd)] == pd]))
@ -593,7 +593,7 @@ def write_data_to_file( outfile,data,desc='data',
hush = False
if file_exists(outfile) and ask_overwrite:
q = u"File '{}' already exists\nOverwrite?".format(outfile)
confirm_or_exit('',q)
confirm_or_raise('',q)
msg(u"Overwriting file '{}'".format(outfile))
hush = True