minor fixes and cleanups
This commit is contained in:
parent
cf2e308713
commit
03ce2e74f6
5 changed files with 19 additions and 20 deletions
|
|
@ -48,7 +48,7 @@ def check_or_create_dir(path):
|
|||
try:
|
||||
os.makedirs(path,0o700)
|
||||
except:
|
||||
die(2,f'ERROR: unable to read or create path {path!r}')
|
||||
die(2, f'ERROR: unable to read or create path ‘{path}’')
|
||||
|
||||
def check_binary(args):
|
||||
from subprocess import run,DEVNULL
|
||||
|
|
@ -89,17 +89,17 @@ def _check_file_type_and_access(fname,ftype,blkdev_ok=False):
|
|||
try:
|
||||
mode = os.stat(fname).st_mode
|
||||
except:
|
||||
die( 'FileNotFound', f'Requested {ftype} {fname!r} not found' )
|
||||
die('FileNotFound', f'Requested {ftype} ‘{fname}’ not found')
|
||||
|
||||
for t in ok_types:
|
||||
if t[0](mode):
|
||||
break
|
||||
else:
|
||||
ok_list = ' or '.join( t[1] for t in ok_types )
|
||||
die(1,f'Requested {ftype} {fname!r} is not a {ok_list}')
|
||||
die(1, f'Requested {ftype} ‘{fname}’ is not a {ok_list}')
|
||||
|
||||
if not os.access(fname,access):
|
||||
die(1,f'Requested {ftype} {fname!r} is not {op_desc}able by you')
|
||||
die(1, f'Requested {ftype} ‘{fname}’ is not {op_desc}able by you')
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -141,11 +141,12 @@ def _open_or_die(filename,mode,silent=False):
|
|||
try:
|
||||
return open(filename,mode)
|
||||
except:
|
||||
die(2,'' if silent else
|
||||
'Unable to open file {!r} for {}'.format(
|
||||
({0:'STDIN',1:'STDOUT',2:'STDERR'}[filename] if isinstance(filename,int) else filename),
|
||||
('reading' if 'r' in mode else 'writing')
|
||||
))
|
||||
if silent:
|
||||
die(2,'')
|
||||
else:
|
||||
fn = {0:'STDIN',1:'STDOUT',2:'STDERR'}[filename] if isinstance(filename,int) else f'‘{filename}’'
|
||||
desc = 'reading' if 'r' in mode else 'writing'
|
||||
die(2, f'Unable to open file {fn} for {desc}')
|
||||
|
||||
def write_data_to_file(
|
||||
cfg,
|
||||
|
|
@ -277,7 +278,7 @@ def write_data_to_file(
|
|||
def get_words_from_file(cfg,infile,desc,quiet=False):
|
||||
|
||||
if not quiet:
|
||||
cfg._util.qmsg(f'Getting {desc} from file {infile!r}')
|
||||
cfg._util.qmsg(f'Getting {desc} from file ‘{infile}’')
|
||||
|
||||
with _open_or_die(infile, 'rb') as fp:
|
||||
data = fp.read()
|
||||
|
|
@ -301,7 +302,7 @@ def get_data_from_file(
|
|||
quiet = False ):
|
||||
|
||||
if not (cfg.quiet or silent or quiet):
|
||||
cfg._util.qmsg(f'Getting {desc} from file {infile!r}')
|
||||
cfg._util.qmsg(f'Getting {desc} from file ‘{infile}’')
|
||||
|
||||
with _open_or_die(
|
||||
(0 if dash and infile == '-' else infile),
|
||||
|
|
@ -332,12 +333,12 @@ def get_lines_from_file(
|
|||
have_enc_ext = get_extension(fn) == Crypto.mmenc_ext
|
||||
if have_enc_ext or not is_utf8(data):
|
||||
m = ('Attempting to decrypt','Decrypting')[have_enc_ext]
|
||||
cfg._util.qmsg(f'{m} {desc} {fn!r}')
|
||||
cfg._util.qmsg(f'{m} {desc} ‘{fn}’')
|
||||
data = Crypto(cfg).mmgen_decrypt_retry(data,desc)
|
||||
return data
|
||||
|
||||
lines = decrypt_file_maybe().decode().splitlines()
|
||||
if trim_comments:
|
||||
lines = strip_comments(lines)
|
||||
cfg._util.dmsg(f'Got {len(lines)} lines from file {fn!r}')
|
||||
cfg._util.dmsg(f'Got {len(lines)} lines from file ‘{fn}’')
|
||||
return lines
|
||||
|
|
|
|||
|
|
@ -77,9 +77,6 @@ class Unsigned(Completed,TxBase.Unsigned):
|
|||
return new
|
||||
except Exception as e:
|
||||
ymsg(f'\n{e.args[0]}')
|
||||
if self.cfg.exec_wrapper:
|
||||
import sys,traceback
|
||||
ymsg( '\n' + ''.join(traceback.format_exception(*sys.exc_info())) )
|
||||
return False
|
||||
|
||||
class AutomountUnsigned(TxBase.AutomountUnsigned, Unsigned):
|
||||
|
|
|
|||
|
|
@ -70,12 +70,14 @@ class TwCtl(MMGenObject,metaclass=AsyncInit):
|
|||
self.importing = True
|
||||
mode = 'w'
|
||||
|
||||
self.cfg = cfg
|
||||
if not no_rpc:
|
||||
self.rpc = await rpc_init(cfg, proto, ignore_wallet=rpc_ignore_wallet)
|
||||
|
||||
self.cfg = cfg
|
||||
self.proto = proto
|
||||
self.mode = mode
|
||||
self.desc = self.base_desc = f'{self.proto.name} tracking wallet'
|
||||
self.cur_balances = {} # cache balances to prevent repeated lookups per program invocation
|
||||
|
||||
if self.use_tw_file:
|
||||
self.init_from_wallet_file()
|
||||
|
|
@ -87,7 +89,6 @@ class TwCtl(MMGenObject,metaclass=AsyncInit):
|
|||
f'Tracking wallet coin ({self.data["coin"]}) does not match current coin ({self.proto.coin})!')
|
||||
|
||||
self.conv_types(self.data[self.data_key])
|
||||
self.cur_balances = {} # cache balances to prevent repeated lookups per program invocation
|
||||
|
||||
def init_from_wallet_file(self):
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ class CmdTestHelp(CmdTestBase):
|
|||
return t
|
||||
|
||||
def version(self):
|
||||
t = self.spawn('mmgen-tool',['--version'])
|
||||
t = self.spawn('mmgen-tool', ['--version'], exit_val=0)
|
||||
t.expect('MMGEN-TOOL version')
|
||||
return t
|
||||
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ class CmdTestShared:
|
|||
+ ([wf] if wf else []),
|
||||
extra_desc=extra_desc)
|
||||
if wcls.type != 'incog_hidden':
|
||||
t.expect(f"Getting {wcls.desc} from file '")
|
||||
t.expect(f"Getting {wcls.desc} from file ‘")
|
||||
if wcls.enc and wcls.type != 'brain':
|
||||
t.passphrase(wcls.desc,self.wpasswd)
|
||||
t.expect(['Passphrase is OK', 'Passphrase.* are correct'],regex=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue