minor fixes and cleanups
This commit is contained in:
parent
04add0dfa5
commit
9a888735a6
12 changed files with 44 additions and 72 deletions
|
|
@ -159,10 +159,10 @@ def _get_random_data_from_user(uchars,desc):
|
|||
|
||||
import time
|
||||
from mmgen.term import get_char_raw
|
||||
key_data,time_data = bytes(),[]
|
||||
key_data,time_data = '',[]
|
||||
|
||||
for i in range(uchars):
|
||||
key_data += get_char_raw('\r'+prompt.format(uchars-i))
|
||||
key_data += get_char_raw('\r'+prompt.format(uchars-i)).decode()
|
||||
time_data.append(time.time())
|
||||
|
||||
if opt.quiet: msg_r('\r')
|
||||
|
|
@ -173,7 +173,7 @@ def _get_random_data_from_user(uchars,desc):
|
|||
prompt = 'User random data successfully acquired. Press ENTER to continue'
|
||||
prompt_and_get_char(prompt,'',enter_ok=True)
|
||||
|
||||
return key_data + ''.join(fmt_time_data).encode()
|
||||
return key_data.encode() + ''.join(fmt_time_data).encode()
|
||||
|
||||
def get_random(length):
|
||||
return add_user_random(os.urandom(length),'OS random data')
|
||||
|
|
|
|||
|
|
@ -78,20 +78,12 @@ if os.getenv('MMGEN_DEBUG') or os.getenv('MMGEN_TEST_SUITE') or os.getenv('MMGEN
|
|||
def isScalar(obj):
|
||||
return isinstance(obj,scalars)
|
||||
|
||||
# print type(self)
|
||||
# print dir(self)
|
||||
# print self.__dict__
|
||||
# print self.__dict__.keys()
|
||||
# print self.keys()
|
||||
|
||||
out = ['<{}>{}\n'.format(type(self).__name__,' '+repr(self) if isScalar(self) else '')]
|
||||
if id(self) in id_list:
|
||||
return out[-1].rstrip() + ' [RECURSION]\n'
|
||||
if isList(self) or isDict(self):
|
||||
do_list(out,self,lvl=lvl,is_dict=isDict(self))
|
||||
|
||||
# print repr(self.__dict__.keys())
|
||||
|
||||
for k in self.__dict__:
|
||||
if k in ('_OrderedDict__root','_OrderedDict__map'): continue # excluded because of recursion
|
||||
e = getattr(self,k)
|
||||
|
|
|
|||
|
|
@ -696,7 +696,6 @@ class SeedSourceUnenc(SeedSource):
|
|||
def _choose_seedlen(self,desc,ok_lens,subtype):
|
||||
|
||||
from mmgen.term import get_char
|
||||
|
||||
def choose_len():
|
||||
prompt = self.choose_seedlen_prompt
|
||||
while True:
|
||||
|
|
|
|||
|
|
@ -126,8 +126,6 @@ def _process_args(cmd,cmd_args):
|
|||
max_dlen_spec = '10kB' # limit input to 10KB for now
|
||||
max_dlen = MMGenToolCmdUtil().bytespec(max_dlen_spec)
|
||||
u_args[0] = os.read(0,max_dlen)
|
||||
# try: u_args[0] = u_args[0].decode()
|
||||
# except: pass
|
||||
have_stdin_input = True
|
||||
if len(u_args[0]) >= max_dlen:
|
||||
die(2,'Maximum data input for this command is {}'.format(max_dlen_spec))
|
||||
|
|
|
|||
|
|
@ -1046,9 +1046,9 @@ Selected non-{pnm} inputs: {{}}""".strip().format(pnm=g.proj_name,pnl=g.proj_nam
|
|||
get_char('Press any key to continue: ')
|
||||
msg('')
|
||||
|
||||
# def is_replaceable_from_rpc(self):
|
||||
# dec_tx = g.rpch.decoderawtransaction(self.hex)
|
||||
# return None < dec_tx['vin'][0]['sequence'] <= g.max_int - 2
|
||||
# def is_replaceable_from_rpc(self):
|
||||
# dec_tx = g.rpch.decoderawtransaction(self.hex)
|
||||
# return None < dec_tx['vin'][0]['sequence'] <= g.max_int - 2
|
||||
|
||||
def is_replaceable(self):
|
||||
return self.inputs[0].sequence == g.max_int - 2
|
||||
|
|
|
|||
|
|
@ -750,8 +750,6 @@ def my_raw_input(prompt,echo=True,insert_txt='',use_readline=True):
|
|||
|
||||
def keypress_confirm(prompt,default_yes=False,verbose=False,no_nl=False,complete_prompt=False):
|
||||
|
||||
from mmgen.term import get_char
|
||||
|
||||
q = ('(y/N)','(Y/n)')[bool(default_yes)]
|
||||
p = prompt if complete_prompt else '{} {}: '.format(prompt,q)
|
||||
nl = ('\n','\r{}\r'.format(' '*len(p)))[no_nl]
|
||||
|
|
@ -760,30 +758,27 @@ def keypress_confirm(prompt,default_yes=False,verbose=False,no_nl=False,complete
|
|||
msg(p)
|
||||
return default_yes
|
||||
|
||||
from mmgen.term import get_char
|
||||
while True:
|
||||
r = get_char(p).strip(b'\n\r')
|
||||
if not r:
|
||||
if default_yes: msg_r(nl); return True
|
||||
else: msg_r(nl); return False
|
||||
elif r in b'yY': msg_r(nl); return True
|
||||
elif r in b'nN': msg_r(nl); return False
|
||||
reply = get_char(p).decode().strip('\n\r')
|
||||
if not reply:
|
||||
msg_r(nl)
|
||||
return True if default_yes else False
|
||||
elif reply in 'yYnN':
|
||||
msg_r(nl)
|
||||
return True if reply in 'yY' else False
|
||||
else:
|
||||
if verbose: msg('\nInvalid reply')
|
||||
else: msg_r('\r')
|
||||
msg_r('\nInvalid reply\n' if verbose else '\r')
|
||||
|
||||
def prompt_and_get_char(prompt,chars,enter_ok=False,verbose=False):
|
||||
|
||||
from mmgen.term import get_char
|
||||
|
||||
while True:
|
||||
reply = get_char('{}: '.format(prompt)).strip(b'\n\r')
|
||||
|
||||
if reply in chars.encode() or (enter_ok and not reply):
|
||||
reply = get_char('{}: '.format(prompt)).decode().strip('\n\r')
|
||||
if reply in chars or (enter_ok and not reply):
|
||||
msg('')
|
||||
return reply.decode()
|
||||
|
||||
if verbose: msg('\nInvalid reply')
|
||||
else: msg_r('\r')
|
||||
return reply
|
||||
msg_r('\nInvalid reply\n' if verbose else '\r')
|
||||
|
||||
def do_pager(text):
|
||||
|
||||
|
|
@ -811,22 +806,22 @@ def do_pager(text):
|
|||
|
||||
def do_license_msg(immed=False):
|
||||
|
||||
if opt.quiet or g.no_license or opt.yes or not g.stdin_tty: return
|
||||
|
||||
import mmgen.license as gpl
|
||||
if opt.quiet or g.no_license or opt.yes or not g.stdin_tty:
|
||||
return
|
||||
|
||||
p = "Press 'w' for conditions and warranty info, or 'c' to continue:"
|
||||
import mmgen.license as gpl
|
||||
msg(gpl.warning)
|
||||
prompt = '{} '.format(p.strip())
|
||||
|
||||
from mmgen.term import get_char
|
||||
|
||||
while True:
|
||||
reply = get_char(prompt, immed_chars=('','wc')[bool(immed)])
|
||||
if reply == b'w':
|
||||
reply = get_char(prompt, immed_chars=('','wc')[bool(immed)]).decode()
|
||||
if reply == 'w':
|
||||
do_pager(gpl.conditions)
|
||||
elif reply == b'c':
|
||||
msg(''); break
|
||||
elif reply == 'c':
|
||||
msg('')
|
||||
break
|
||||
else:
|
||||
msg_r('\r')
|
||||
msg('')
|
||||
|
|
|
|||
12
setup.py
12
setup.py
|
|
@ -19,11 +19,13 @@
|
|||
import sys,os,subprocess
|
||||
from shutil import copy2
|
||||
|
||||
ver = sys.version_info[:2]
|
||||
min_ver = (3,6)
|
||||
if ver[0] < min_ver[0] or ver[1] < min_ver[1]:
|
||||
m = '{}.{}: wrong Python version. MMGen requires Python {M}.{m} or greater\n'
|
||||
sys.stderr.write(m.format(*ver,M=min_ver[0],m=min_ver[1]))
|
||||
sys_ver = sys.version_info[:2]
|
||||
req_ver = (3,7)
|
||||
ver2f = lambda t: float('{}.{:03}'.format(*t))
|
||||
|
||||
if ver2f(sys_ver) < ver2f(req_ver):
|
||||
m = '{}.{}: wrong Python version. MMGen requires Python {}.{} or greater\n'
|
||||
sys.stderr.write(m.format(*sys_ver,*req_ver))
|
||||
sys.exit(1)
|
||||
|
||||
have_msys2 = subprocess.check_output(['uname','-s']).strip()[:7] == b'MSYS_NT'
|
||||
|
|
|
|||
|
|
@ -96,21 +96,6 @@ def mk_tmpdir(d):
|
|||
else:
|
||||
vmsg("Created directory '{}'".format(d))
|
||||
|
||||
# def mk_tmpdir_path(path,cfg):
|
||||
# try:
|
||||
# name = os.path.split(cfg['tmpdir'])[-1]
|
||||
# src = os.path.join(path,name)
|
||||
# try:
|
||||
# os.unlink(cfg['tmpdir'])
|
||||
# except OSError as e:
|
||||
# if e.errno != 2: raise
|
||||
# finally:
|
||||
# os.mkdir(src)
|
||||
# os.symlink(src,cfg['tmpdir'])
|
||||
# except OSError as e:
|
||||
# if e.errno != 17: raise
|
||||
# else: msg("Created directory '{}'".format(cfg['tmpdir']))
|
||||
|
||||
def get_tmpfile(cfg,fn):
|
||||
return os.path.join(cfg['tmpdir'],fn)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys,os
|
||||
pn = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||
parpar = os.path.dirname(os.path.dirname(pn))
|
||||
os.chdir(parpar)
|
||||
sys.path[0] = os.curdir
|
||||
|
||||
from mmgen.util import msg
|
||||
from mmgen.common import *
|
||||
|
||||
|
|
@ -9,4 +15,3 @@ p = ('Enter passphrase: ','Enter passphrase (echoed): ')[bool(opt.echo_passphras
|
|||
|
||||
pw = get_words_from_user(p)
|
||||
msg('Entered: {}'.format(' '.join(pw)))
|
||||
#msg(ascii(pw))
|
||||
|
|
|
|||
|
|
@ -815,10 +815,6 @@ class TestSuiteRunner(object):
|
|||
|
||||
def run_test(self,cmd):
|
||||
|
||||
# delete files produced by this cmd
|
||||
# for ext,tmpdir in find_generated_exts(cmd):
|
||||
# print cmd, get_file_with_ext(tmpdir,ext)
|
||||
|
||||
d = [(str(num),ext) for exts,num in self.gm.dpy_data[cmd][2] for ext in exts]
|
||||
|
||||
# delete files depended on by this cmd
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class TestSuiteCfg(TestSuiteBase):
|
|||
u = read_from_file(self.path('usr'))
|
||||
S = read_from_file(self.path('sys'))
|
||||
assert u[-1] == '\n', u
|
||||
assert u == S, 'u != S'
|
||||
assert u.replace('\r\n','\n') == S, 'u != S'
|
||||
self.check_replaced_sample()
|
||||
return t
|
||||
|
||||
|
|
|
|||
|
|
@ -657,9 +657,9 @@ tests = {
|
|||
},
|
||||
},
|
||||
# TODO: compressed address files are missing
|
||||
# 'addrfile_compressed_chk':
|
||||
# 'btc': ('A33C 4FDE F515 F5BC','6C48 AA57 2056 C8C8'),
|
||||
# 'ltc': ('3FC0 8F03 C2D6 BD19','4C0A 49B6 2DD1 1BE0'),
|
||||
# 'addrfile_compressed_chk':
|
||||
# 'btc': ('A33C 4FDE F515 F5BC','6C48 AA57 2056 C8C8'),
|
||||
# 'ltc': ('3FC0 8F03 C2D6 BD19','4C0A 49B6 2DD1 1BE0'),
|
||||
'File': {
|
||||
'addrfile_chksum': {
|
||||
'btc_mainnet': [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue