diff --git a/mmgen/globalvars.py b/mmgen/globalvars.py index 00fc9f8c..12eeebff 100755 --- a/mmgen/globalvars.py +++ b/mmgen/globalvars.py @@ -75,7 +75,6 @@ class g(object): debug_addrlist = False quiet = False no_license = False - color = (False,True)[sys.stdout.isatty()] force_256_color = False testnet = False regtest = False @@ -99,12 +98,15 @@ class g(object): traceback = False test_suite = False - for k in ('win','linux'): + for k in ('linux','win','msys'): if sys.platform[:len(k)] == k: - platform = k; break + platform = { 'linux':'linux', 'win':'win', 'msys':'win' }[k] + break else: die(1,"'{}': platform not supported by {}\n".format(sys.platform,proj_name)) + color = sys.stdout.isatty() and platform != 'win' + if os.getenv('HOME'): # Linux or MSYS home_dir = os.getenv('HOME') elif platform == 'win': # Windows native: diff --git a/mmgen/main_autosign.py b/mmgen/main_autosign.py index 73d6d0e2..4c301834 100755 --- a/mmgen/main_autosign.py +++ b/mmgen/main_autosign.py @@ -316,7 +316,7 @@ def setup(): def ev_sleep(secs): ev.wait(secs) - return (False,True)[ev.isSet()] + return ev.isSet() def do_led(on,off): if not on: diff --git a/mmgen/opts.py b/mmgen/opts.py index 22b7bf86..9b541102 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -78,7 +78,7 @@ def opt_postproc_initializations(): from mmgen.color import init_color init_color(enable_color=g.color,num_colors=('auto',256)[bool(g.force_256_color)]) - if g.platform == 'win': start_mscolor() + if g.color and g.platform == 'win': start_mscolor() g.coin = g.coin.upper() # allow user to use lowercase g.dcoin = g.coin diff --git a/mmgen/share/Opts.py b/mmgen/share/Opts.py index cdef1f8a..03142074 100755 --- a/mmgen/share/Opts.py +++ b/mmgen/share/Opts.py @@ -106,7 +106,7 @@ def parse_opts(argv,opts_data,opt_filter=None,skip_help=False): for l in opts_data[k].strip().splitlines(): m = re.match(pat,l) if m: - skip = (False,True)[bool(opt_filter) and m.group(1) not in opt_filter] + skip = bool(opt_filter) and m.group(1) not in opt_filter app = (['',''],[':','='])[m.group(3) == '='] od.append(list(m.groups()) + app + [skip]) else: diff --git a/mmgen/term.py b/mmgen/term.py index b16e4a4c..fa62da7a 100755 --- a/mmgen/term.py +++ b/mmgen/term.py @@ -118,7 +118,7 @@ def _get_keypress_mswin(prompt='',immed_chars='',prehold_protect=True,num_chars= if ord(ch) == 3: raise KeyboardInterrupt - if immed_chars == 'ALL' or ch in immed_chars: + if immed_chars == 'ALL' or ch.decode() in immed_chars: return ch if immed_chars == 'ALL_EXCEPT_ENTER' and not ch in '\n\r': return ch diff --git a/mmgen/util.py b/mmgen/util.py index e349c544..5cd8779f 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -766,7 +766,7 @@ def keypress_confirm(prompt,default_yes=False,verbose=False,no_nl=False,complete if opt.accept_defaults: msg(p) - return (False,True)[default_yes] + return default_yes while True: r = get_char(p).strip(b'\n\r') diff --git a/scripts/traceback_run.py b/scripts/traceback_run.py index e936af07..3d0c7a78 100755 --- a/scripts/traceback_run.py +++ b/scripts/traceback_run.py @@ -4,7 +4,7 @@ # file, as all names will be seen by the exec'ed file. To prevent name collisions, all names # defined here should begin with 'traceback_run_' -import sys +import sys,time def traceback_run_init(): import os @@ -29,13 +29,14 @@ def traceback_run_process_exception(): exc = l.pop() if exc[:11] == 'SystemExit:': l.pop() - def red(s): return '{e}[31;1m{}{e}[0m'.format(s,e='\033') - def yellow(s): return '{e}[33;1m{}{e}[0m'.format(s,e='\033') + red = lambda s: '\033[31;1m{}\033[0m'.format(s) + yellow = lambda s: '\033[33;1m{}\033[0m'.format(s) sys.stdout.write('{}{}'.format(yellow(''.join(l)),red(exc))) open(traceback_run_outfile,'w').write(''.join(l+[exc])) traceback_run_outfile = traceback_run_init() +traceback_run_tstart = time.time() try: sys.argv.pop(0) @@ -48,6 +49,10 @@ except SystemExit as e: except Exception as e: traceback_run_process_exception() sys.exit(e.mmcode if hasattr(e,'mmcode') else e.code if hasattr(e,'code') else 1) + +blue = lambda s: '\033[34;1m{}\033[0m'.format(s) +sys.stdout.write(blue('Runtime: {:0.5f} secs\n'.format(time.time() - traceback_run_tstart))) + # else: # print('else: '+repr(sys.exc_info())) # finally: diff --git a/setup.py b/setup.py index a6b4555f..3b05e104 100755 --- a/setup.py +++ b/setup.py @@ -29,6 +29,7 @@ if ver[0] < min_ver[0] or ver[1] < min_ver[1]: _gvi = subprocess.check_output(['gcc','--version']).decode().splitlines()[0] have_mingw64 = 'x86_64' in _gvi and 'MinGW' in _gvi have_arm = subprocess.check_output(['uname','-m']).strip() == 'aarch64' +have_msys2 = not have_mingw64 and os.getenv('MSYSTEM') == 'MINGW64' # Zipfile module under Windows (MinGW) can't handle UTF-8 filenames. # Move it so that distutils will use the 'zip' utility instead. @@ -108,7 +109,7 @@ setup( platforms = 'Linux, MS Windows, Raspberry Pi/Raspbian, Orange Pi/Armbian', keywords = g.keywords, cmdclass = { 'build_ext': my_build_ext, 'install_data': my_install_data }, - ext_modules = [module1], + ext_modules = [] if have_msys2 else [module1], data_files = [('share/mmgen', [ 'data_files/mmgen.cfg', # source files must have 0644 mode 'data_files/mn_wordlist.c', diff --git a/test/gentest.py b/test/gentest.py index 7a7c3696..1584d799 100755 --- a/test/gentest.py +++ b/test/gentest.py @@ -72,7 +72,7 @@ EXAMPLES: sys.argv = [sys.argv[0]] + ['--skip-cfg-file'] + sys.argv[1:] -cmd_args = opts.init(opts_data,add_opts=['exact_output']) +cmd_args = opts.init(opts_data,add_opts=['exact_output','use_old_ed25519']) if not 1 <= len(cmd_args) <= 2: opts.usage() diff --git a/test/test_py_d/ts_main.py b/test/test_py_d/ts_main.py index ec22f3f5..10d882e4 100755 --- a/test/test_py_d/ts_main.py +++ b/test/test_py_d/ts_main.py @@ -512,7 +512,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared): wf,desc='hidden incognito data',out_fmt='hi',add_args=add_args) def addrgen_seed(self,wf,foo,desc='seed data',in_fmt='seed'): - stdout = (False,True)[desc=='seed data'] #capture output to screen once + stdout = desc == 'seed data' # capture output to screen once add_args = ([],['-S'])[bool(stdout)] + self.segwit_arg t = self.spawn('mmgen-addrgen', add_args + ['-i'+in_fmt,'-d',self.tmpdir,wf,self.addr_idx_list]) diff --git a/test/test_py_d/ts_misc.py b/test/test_py_d/ts_misc.py index 73a4c509..424b253f 100755 --- a/test/test_py_d/ts_misc.py +++ b/test/test_py_d/ts_misc.py @@ -151,10 +151,11 @@ class TestSuiteRefTX(TestSuiteMain,TestSuiteBase): ) def __init__(self,trunner,cfgs,spawn): - for n in self.tmpdir_nums: - cfgs[str(n)].update({ 'addr_idx_list': '1-2', - 'segwit': n in (33,34), - 'dep_generators': { 'addrs':'ref_tx_addrgen'+str(n)[-1] }}) + if cfgs: + for n in self.tmpdir_nums: + cfgs[str(n)].update({ 'addr_idx_list': '1-2', + 'segwit': n in (33,34), + 'dep_generators': { 'addrs':'ref_tx_addrgen'+str(n)[-1] }}) return TestSuiteMain.__init__(self,trunner,cfgs,spawn) def ref_tx_addrgen(self,atype): diff --git a/test/tooltest2.py b/test/tooltest2.py index 7871ced9..9ea58f56 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -718,7 +718,7 @@ if opt.fork: d,f = init_coverage() tool_cmd = ('python3','-m','trace','--count','--coverdir='+d,'--file='+f) + tool_cmd elif g.platform == 'win': - tool_cmd = ('python3') + tool_cmd + tool_cmd = ('python3',) + tool_cmd else: opt.usr_randchars = 0 tc = tool.MMGenToolCmd()