Ejemplo n.º 1
0
Archivo: test.py Proyecto: onkea/mmgen
def set_environ_for_spawned_scripts():

    from mmgen.term import get_terminal_size
    os.environ['MMGEN_TERMINAL_WIDTH'] = str(get_terminal_size().width)

    if os.getenv('MMGEN_DEBUG_ALL'):
        for name in g.env_opts:
            if name[:11] == 'MMGEN_DEBUG':
                os.environ[name] = '1'

    if not opt.pexpect_spawn:
        os.environ['MMGEN_TEST_SUITE_POPEN_SPAWN'] = '1'

    if not opt.system:
        os.environ['PYTHONPATH'] = repo_root

    if not opt.buf_keypress:
        os.environ['MMGEN_DISABLE_HOLD_PROTECT'] = '1'

    # If test.py itself is running under traceback, the spawned script shouldn't be, so disable this:
    if os.getenv('MMGEN_TRACEBACK') and not opt.traceback:
        os.environ['MMGEN_TRACEBACK'] = ''

    os.environ['MMGEN_NO_LICENSE'] = '1'
    os.environ['MMGEN_MIN_URANDCHARS'] = '3'
    os.environ['MMGEN_BOGUS_SEND'] = '1'
    os.environ['MMGEN_TEST_SUITE_PEXPECT'] = '1'
Ejemplo n.º 2
0
Archivo: test.py Proyecto: mmgen/mmgen
def set_environ_for_spawned_scripts():

	from mmgen.term import get_terminal_size
	os.environ['MMGEN_TERMINAL_WIDTH'] = str(get_terminal_size()[0])

	if os.getenv('MMGEN_DEBUG_ALL'):
		for name in g.env_opts:
			if name[:11] == 'MMGEN_DEBUG':
				os.environ[name] = '1'
	if not opt.pexpect_spawn: os.environ['MMGEN_TEST_SUITE_POPEN_SPAWN'] = '1'
	if not opt.system: os.environ['PYTHONPATH'] = repo_root
	if not opt.buf_keypress:
		os.environ['MMGEN_DISABLE_HOLD_PROTECT'] = '1'

	# If test.py itself is running under traceback, the spawned script shouldn't be, so disable this:
	if os.getenv('MMGEN_TRACEBACK') and not opt.traceback:
		os.environ['MMGEN_TRACEBACK'] = ''

	# Disable color in spawned scripts so pexpect can parse their output
	os.environ['MMGEN_DISABLE_COLOR'] = '1'
	os.environ['MMGEN_NO_LICENSE'] = '1'
	os.environ['MMGEN_MIN_URANDCHARS'] = '3'
	os.environ['MMGEN_BOGUS_SEND'] = '1'
	# Tell spawned programs they're running in the test suite
	os.environ['MMGEN_TEST_SUITE'] = '1'
Ejemplo n.º 3
0
 def set_term_columns(self):
     from mmgen.term import get_terminal_size
     while True:
         self.cols = get_terminal_size()[0]
         if self.cols >= g.min_screen_width: break
         m1 = 'Screen too narrow to display the tracking wallet\n'
         m2 = 'Please resize your screen to at least {} characters and hit ENTER '
         my_raw_input((m1 + m2).format(g.min_screen_width))
Ejemplo n.º 4
0
Archivo: tw.py Proyecto: mmgen/mmgen
	def set_term_columns(self):
		from mmgen.term import get_terminal_size
		while True:
			self.cols = g.terminal_width or get_terminal_size()[0]
			if self.cols >= g.min_screen_width: break
			m1 = 'Screen too narrow to display the tracking wallet\n'
			m2 = 'Please resize your screen to at least {} characters and hit ENTER '
			my_raw_input((m1+m2).format(g.min_screen_width))
Ejemplo n.º 5
0
def Txview(*infiles, **kwargs):
    from mmgen.filename import MMGenFileList
    pager = 'pager' in kwargs and kwargs['pager']
    terse = 'terse' in kwargs and kwargs['terse']
    sort_key = kwargs['sort'] if 'sort' in kwargs else 'mtime'
    flist = MMGenFileList(infiles, ftype=MMGenTX)
    flist.sort_by_age(key=sort_key)  # in-place sort
    from mmgen.term import get_terminal_size
    sep = u'—' * get_terminal_size()[0] + '\n'
    out = sep.join(
        [MMGenTX(fn).format_view(terse=terse) for fn in flist.names()])
    (Msg, do_pager)[pager](out.rstrip())
Ejemplo n.º 6
0
def tt_get_terminal_size():
	cmsg('Testing get_terminal_size():')
	msg('X' * get_terminal_size().width)
	confirm('Do the X’s exactly fill the width of the screen?')
Ejemplo n.º 7
0
def sort_and_view(unspent):

	def s_amt(i):   return i.amount
	def s_txid(i):  return "%s %03s" % (i.txid,i.vout)
	def s_addr(i):  return i.address
	def s_age(i):   return i.confirmations
	def s_mmgen(i):
		if i.mmid:
			return "{}:{:>0{w}}".format(
				*i.mmid.split(":"), w=g.mmgen_idx_max_digits)
		else: return "G" + i.comment

	sort,group,show_days,show_mmaddr,reverse = "age",False,False,True,True
	unspent.sort(key=s_age,reverse=reverse) # Reverse age sort by default

	total = trim_exponent(sum([i.amount for i in unspent]))
	max_acct_len = max([len(i.mmid+" "+i.comment) for i in unspent])

	hdr_fmt   = "UNSPENT OUTPUTS (sort order: %s)  Total BTC: %s"
	options_msg = """
Sort options: [t]xid, [a]mount, a[d]dress, [A]ge, [r]everse, [M]mgen addr
Display options: show [D]ays, [g]roup, show [m]mgen addr, r[e]draw screen
""".strip()
	prompt = \
"('q' = quit sorting, 'p' = print to file, 'v' = pager view, 'w' = wide view): "

	mmid_w = max(len(i.mmid) for i in unspent)
	from copy import deepcopy
	from mmgen.term import get_terminal_size

	written_to_file_msg = ""
	msg("")

	while True:
		cols = get_terminal_size()[0]
		if cols < g.min_screen_width:
			msg(
	"{pnl}-txcreate requires a screen at least {w} characters wide".format(
					pnl=pnm.lower(),w=g.min_screen_width))
			sys.exit(2)

		addr_w = min(34+((1+max_acct_len) if show_mmaddr else 0),cols-46)
		acct_w   = min(max_acct_len, max(24,int(addr_w-10)))
		btaddr_w = addr_w - acct_w - 1
		tx_w = max(11,min(64, cols-addr_w-32))
		txdots = "..." if tx_w < 64 else ""
		fs = " %-4s %-" + str(tx_w) + "s %-2s %-" + str(addr_w) + "s %-13s %-s"
		table_hdr = fs % ("Num","TX id  Vout","","Address","Amount (BTC)",
							"Age(d)" if show_days else "Conf.")

		unsp = deepcopy(unspent)
		for i in unsp: i.skip = ""
		if group and (sort == "address" or sort == "txid"):
			for a,b in [(unsp[i],unsp[i+1]) for i in range(len(unsp)-1)]:
				if sort == "address" and a.address == b.address: b.skip = "addr"
				elif sort == "txid" and a.txid == b.txid:        b.skip = "txid"

		for i in unsp:
			amt = str(trim_exponent(i.amount))
			lfill = 3 - len(amt.split(".")[0]) if "." in amt else 3 - len(amt)
			i.amt = " "*lfill + amt
			i.days = int(i.confirmations * g.mins_per_block / (60*24))
			i.age = i.days if show_days else i.confirmations

			if i.skip == "addr":
				i.addr = "|" + "." * 33
			else:
				if show_mmaddr:
					dots = ".." if btaddr_w < len(i.address) else ""
					i.addr = "%s%s %s" % (
						i.address[:btaddr_w-len(dots)],
						dots, (
						("{:<{w}} ".format(i.mmid,w=mmid_w) if i.mmid else "")
							+ i.comment)[:acct_w]
						)
				else:
					i.addr = i.address

			i.tx = " " * (tx_w-4) + "|..." if i.skip == "txid" \
					else i.txid[:tx_w-len(txdots)]+txdots

		sort_info = ["reverse"] if reverse else []
		sort_info.append(sort if sort else "unsorted")
		if group and (sort == "address" or sort == "txid"):
			sort_info.append("grouped")

		out  = [hdr_fmt % (" ".join(sort_info), total), table_hdr]
		out += [fs % (str(n+1)+")",i.tx,i.vout,i.addr,i.amt,i.age)
					for n,i in enumerate(unsp)]

		msg("\n".join(out) +"\n\n" + written_to_file_msg + options_msg)
		written_to_file_msg = ""

		skip_prompt = False

		while True:
			reply = get_char(prompt, immed_chars="atDdAMrgmeqpvw")

			if   reply == 'a': unspent.sort(key=s_amt);  sort = "amount"
			elif reply == 't': unspent.sort(key=s_txid); sort = "txid"
			elif reply == 'D': show_days = not show_days
			elif reply == 'd': unspent.sort(key=s_addr); sort = "address"
			elif reply == 'A': unspent.sort(key=s_age);  sort = "age"
			elif reply == 'M':
				unspent.sort(key=s_mmgen); sort = "mmgen"
				show_mmaddr = True
			elif reply == 'r':
				unspent.reverse()
				reverse = not reverse
			elif reply == 'g': group = not group
			elif reply == 'm': show_mmaddr = not show_mmaddr
			elif reply == 'e': pass
			elif reply == 'q': pass
			elif reply == 'p':
				d = format_unspent_outputs_for_printing(unsp,sort_info,total)
				of = "listunspent[%s].out" % ",".join(sort_info)
				write_data_to_file(of,d,"unspent outputs listing")
				written_to_file_msg = "Data written to '%s'\n\n" % of
			elif reply == 'v':
				do_pager("\n".join(out))
				continue
			elif reply == 'w':
				data = format_unspent_outputs_for_printing(unsp,sort_info,total)
				do_pager(data)
				continue
			else:
				msg("\nInvalid input")
				continue

			break

		msg("\n")
		if reply == 'q': break

	return tuple(unspent)