diff --git a/mmgen/addr.py b/mmgen/addr.py index 508d04ad..086be6ad 100755 --- a/mmgen/addr.py +++ b/mmgen/addr.py @@ -30,7 +30,7 @@ from mmgen.bitcoin import numtowif from mmgen.util import * from mmgen.tx import * from mmgen.obj import * -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt pnm = g.proj_name diff --git a/mmgen/crypto.py b/mmgen/crypto.py index b246c79b..4f9e3c2d 100755 --- a/mmgen/crypto.py +++ b/mmgen/crypto.py @@ -24,7 +24,7 @@ import sys from binascii import hexlify from hashlib import sha256 -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.util import * from mmgen.term import get_char diff --git a/mmgen/filename.py b/mmgen/filename.py index a535858d..336e5e13 100755 --- a/mmgen/filename.py +++ b/mmgen/filename.py @@ -20,9 +20,10 @@ filename.py: Filename class and methods for the MMGen suite """ import sys,os +import mmgen.opt as opt from mmgen.obj import * -import mmgen.config as g -from mmgen.util import msg +import mmgen.globalvars as g +from mmgen.util import msg,fmt_code_to_sstype class Filename(MMGenObject): @@ -58,7 +59,6 @@ class Filename(MMGenObject): } def __init__(self,fn,ftype=""): - import os self.name = fn self.dirname = os.path.dirname(fn) self.basename = os.path.basename(fn) @@ -66,6 +66,7 @@ class Filename(MMGenObject): def mf1(k): return k == ftype def mf2(k): return '.'+k == fn[-len('.'+k):] + # find file info for ftype or extension e,attr,have_match = (self.ftypes,"ftype",mf1) if ftype else \ (self.exts,"ext",mf2) @@ -75,7 +76,7 @@ class Filename(MMGenObject): if have_match(j): setattr(self,attr,j) self.fclass = k - self.linked_obj = e[k][j] + self.sstype = e[k][j] if not hasattr(self,attr): die(2,"Unrecognized %s for file '%s'" % (attr,fn)) diff --git a/mmgen/config.py b/mmgen/globalvars.py similarity index 89% rename from mmgen/config.py rename to mmgen/globalvars.py index d6cae1ab..a72bacbd 100755 --- a/mmgen/config.py +++ b/mmgen/globalvars.py @@ -120,6 +120,15 @@ max_addr_label_len = 32 max_wallet_label_len = 48 max_tx_comment_len = 72 # Comment is b58 encoded, so can permit all UTF-8 +wallet_fmt_codes = ( + ( "Wallet", "wallet", "w" ), + ( "SeedFile", "mmseed","seed", "s" ), + ( "Mnemonic", "mmwords","words","mnemonic","mnem","m" ), + ( "Brainwallet", "mmbrain","brainwallet","brain","bw","b" ), + ( "IncogWallet", "mmincog","incog","i" ), + ( "IncogWalletHex", "mmincox","incog_hex","ix" ), + ( "IncogWalletHidden", "incog_hidden","ih" ), +) #addr_label_punc = ".","_",",","-"," ","(",")" #addr_label_symbols = tuple(ascii_letters + digits) + addr_label_punc #wallet_label_punc = addr_label_punc diff --git a/mmgen/license.py b/mmgen/license.py index ce4898c9..92713e20 100755 --- a/mmgen/license.py +++ b/mmgen/license.py @@ -19,7 +19,7 @@ """ license.py: Text of GPLv3 """ -import mmgen.config as g +import mmgen.globalvars as g gpl = { 'warning': """ diff --git a/mmgen/main_addrgen.py b/mmgen/main_addrgen.py index ec985d99..b941a7f6 100755 --- a/mmgen/main_addrgen.py +++ b/mmgen/main_addrgen.py @@ -23,7 +23,7 @@ mmgen-addrgen: Generate a series or range of addresses from an MMGen import sys -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.util import * from mmgen.crypto import * diff --git a/mmgen/main_addrimport.py b/mmgen/main_addrimport.py index 247ad723..69a08e57 100755 --- a/mmgen/main_addrimport.py +++ b/mmgen/main_addrimport.py @@ -21,7 +21,7 @@ mmgen-addrimport: Import addresses into a MMGen bitcoind tracking wallet """ import sys, time -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.util import * from mmgen.tx import connect_to_bitcoind diff --git a/mmgen/main_passchg.py b/mmgen/main_passchg.py index 8ce416c5..b9cb6ac9 100755 --- a/mmgen/main_passchg.py +++ b/mmgen/main_passchg.py @@ -24,7 +24,7 @@ mmgen-passchg: Change an MMGen deterministic wallet's passphrase, label or import sys from mmgen.util import * from mmgen.crypto import * -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt opts_data = { diff --git a/mmgen/main_tool.py b/mmgen/main_tool.py index 4828e519..b6ebcd23 100755 --- a/mmgen/main_tool.py +++ b/mmgen/main_tool.py @@ -22,7 +22,7 @@ mmgen-tool: Perform various MMGen- and Bitcoin-related operations. """ import sys -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt import mmgen.tool as tool diff --git a/mmgen/main_txcreate.py b/mmgen/main_txcreate.py index 98725487..9d096476 100755 --- a/mmgen/main_txcreate.py +++ b/mmgen/main_txcreate.py @@ -24,7 +24,7 @@ mmgen-txcreate: Create a Bitcoin transaction to and from MMGen- or non-MMGen import sys from decimal import Decimal -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.tx import * diff --git a/mmgen/main_txsend.py b/mmgen/main_txsend.py index 80f33910..4249a473 100755 --- a/mmgen/main_txsend.py +++ b/mmgen/main_txsend.py @@ -22,7 +22,7 @@ mmgen-txsend: Broadcast a transaction signed by 'mmgen-txsign' to the network import sys -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.tx import * from mmgen.util import * diff --git a/mmgen/main_txsign.py b/mmgen/main_txsign.py index 98ea6962..1cfdb2ee 100755 --- a/mmgen/main_txsign.py +++ b/mmgen/main_txsign.py @@ -22,7 +22,7 @@ mmgen-txsign: Sign a transaction generated by 'mmgen-txcreate' import sys -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.tx import * from mmgen.util import do_license_msg diff --git a/mmgen/main_walletchk.py b/mmgen/main_walletchk.py index 935aa8b2..c9632733 100755 --- a/mmgen/main_walletchk.py +++ b/mmgen/main_walletchk.py @@ -22,7 +22,7 @@ mmgen-walletchk: Check integrity of an MMGen deterministic wallet, display """ import sys -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.util import * from mmgen.crypto import * diff --git a/mmgen/main_walletgen.py b/mmgen/main_walletgen.py index 05a94a3c..2d65080d 100755 --- a/mmgen/main_walletgen.py +++ b/mmgen/main_walletgen.py @@ -23,7 +23,7 @@ mmgen-walletgen: Generate an MMGen deterministic wallet import sys, os from hashlib import sha256 -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.util import * from mmgen.crypto import * diff --git a/mmgen/mnemonic.py b/mmgen/mnemonic.py index 679fe7f4..af6230c4 100755 --- a/mmgen/mnemonic.py +++ b/mmgen/mnemonic.py @@ -24,7 +24,7 @@ import sys from binascii import hexlify from mmgen.util import msg,msg_r,make_chksum_8,Vmsg,Msg from mmgen.crypto import get_random -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt wl_checksums = { diff --git a/mmgen/obj.py b/mmgen/obj.py index 34668edd..4b670cc3 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -19,7 +19,7 @@ """ obj.py: The MMGenObject class and methods """ -import mmgen.config as g +import mmgen.globalvars as g from mmgen.util import msgrepr_exit,msgrepr lvl = 0 @@ -89,4 +89,5 @@ class MMGenObject(object): lvl -= 1 else: out.append(fs % (k, conv(val,col_w))) - return "\n".join(out) + + return repr(self) + "\n " + "\n ".join(out) diff --git a/mmgen/opts.py b/mmgen/opts.py index 9feeb060..5b1e42d1 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -21,10 +21,10 @@ opts.py: MMGen-specific options processing after generic processing by share.Op """ import sys -import mmgen.config as g +import mmgen.globalvars as g import mmgen.share.Opts import opt -from mmgen.util import msg,msgrepr_exit,msgrepr,Msg +from mmgen.util import msg,msgrepr_exit,msgrepr,Msg,fmt_type def usage(): Msg("USAGE: %s %s" % (g.prog_name, usage_txt)) @@ -44,15 +44,17 @@ def warn_incompatible_opts(incompat_list): ["--"+b.replace("_","-") for b in bad])) sys.exit(1) -def typeconvert_from_dfl(key): - - vtype = type(g.__dict__[key]) - if g.debug: Msg("Override opt: %-15s [%s]" % (key,vtype)) +def _typeconvert_from_dfl(key): global opt + gval = g.__dict__[key] + uval = opt.__dict__[key] + gtype = type(gval) + utype = type(uval) + try: - opt.__dict__[key] = vtype(opt.__dict__[key]) + opt.__dict__[key] = gtype(opt.__dict__[key]) except: d = { 'int': 'an integer', @@ -60,11 +62,17 @@ def typeconvert_from_dfl(key): 'float': 'a float', 'bool': 'a boolean value', } - m = [d[k] for k in d if __builtins__[k] == vtype] + m = [d[k] for k in d if __builtins__[k] == gtype] fs = "'%s': invalid parameter for '--%s' option (not %s)" msg(fs % (opt.__dict__[key],opt.replace("_","-"),m)) sys.exit(1) + if g.debug: + Msg("Opt overriden by user:\n %-18s: %s" % ( + key, ("%s -> %s" % (gval,uval)) + )) + + def _show_hash_presets(): fs = " {:<7} {:<6} {:<3} {}" msg("Available parameters for scrypt.hash():") @@ -72,7 +80,6 @@ def _show_hash_presets(): for i in sorted(g.hash_presets.keys()): msg(fs.format("'%s'" % i, *g.hash_presets[i])) msg("N = memory usage (power of two), p = iterations (rounds)") - sys.exit(0) def init(opts_data,add_opts=[]): @@ -84,11 +91,12 @@ def init(opts_data,add_opts=[]): if g.debug: d = ( - ("short opts", short_opts), - ("long opts", long_opts), - ("user-selected opts", uopts), - ("cmd args", args), + ("Short opts", short_opts), + ("Long opts", long_opts), + ("User-selected opts", uopts), + ("Cmd args", args), ) + Msg("\n### BEGIN OPTS.PY ###") for e in d: Msg("{:<20}: {}".format(*e)) # Save this for usage() @@ -114,21 +122,24 @@ def init(opts_data,add_opts=[]): # A special case - do this here, before opt gets set from g.dfl_vars if opt.usr_randchars: g.use_urandchars = True - # If user opt is unset, set it to default value in mmgen.config (g): - # If set, convert its type based on value in mmgen.config + # If user opt is set, convert its type based on value in mmgen.globalvars + # If unset, set it to default value in mmgen.globalvars (g): for k in g.dfl_vars: if k in opt.__dict__ and opt.__dict__[k] != None: - typeconvert_from_dfl(k) + _typeconvert_from_dfl(k) else: opt.__dict__[k] = g.__dict__[k] - if opt.show_hash_presets: _show_hash_presets() + if opt.show_hash_presets: + _show_hash_presets(); sys.exit(0) if opt.debug: opt.verbose = True if g.debug: - Msg("opts after typeconvert:") + Msg("Opts after processing:") for k in opt.__dict__: - if opt.__dict__[k] != None and k != "opts": - msg(" %-18s: %s" % (k,opt.__dict__[k])) + v = opt.__dict__[k] + if v != None and k != "opts": + Msg(" %-18s: %-6s [%s]" % (k,v,fmt_type(v))) + Msg("### END OPTS.PY ###\n") for l in ( ('from_incog_hidden','from_incog','from_seed','from_mnemonic','from_brain'), diff --git a/mmgen/rpc/proxy.py b/mmgen/rpc/proxy.py index 62c98f04..7cfe6f43 100755 --- a/mmgen/rpc/proxy.py +++ b/mmgen/rpc/proxy.py @@ -1,6 +1,6 @@ """ Copyright (C) 2013 by philemon - Added http_timeout from mmgen.config + Added http_timeout from mmgen.globalvars Previous copyright from bitcoin-python/proxy.py: @@ -58,7 +58,7 @@ class JSONRPCException(Exception): self.error = rpcError -import mmgen.config as g +import mmgen.globalvars as g class AuthServiceProxy(object): def __init__(self, serviceURL, serviceName = None): diff --git a/mmgen/seed.py b/mmgen/seed.py index e947d5ee..e8c52b50 100755 --- a/mmgen/seed.py +++ b/mmgen/seed.py @@ -19,10 +19,10 @@ """ seed.py: Seed-related classes and methods for the MMGen suite """ -import sys +import sys,os from binascii import hexlify,unhexlify -import mmgen.config as g +import mmgen.globalvars as g from mmgen.obj import * from mmgen.filename import * from mmgen.util import * @@ -51,23 +51,15 @@ class SeedSource(MMGenObject): class SeedSourceData(MMGenObject): pass desc = "seed source" - seed_opts = { - "mnemonic": "Mnemonic", - "brain": "Brainwallet", - "seed": "SeedFile", - "incog": "IncogWallet", - "incog_hex": "IncogWalletHex", - "incog_hidden": "IncogWalletHidden", - } def __init__(self,fn=None,seed=None,passwd=None): self.ssdata = self.SeedSourceData() + self.ssdata.passwd = passwd if seed: self.desc = "new " + self.desc self.seed = seed - self.ssdata.passwd = passwd self._pre_encode() self._encode() else: @@ -85,27 +77,24 @@ class SeedSource(MMGenObject): def _pre_encode(self): pass - def init(cls,fn=None,seed=None,passwd=None): + def init(cls,infile=None,seed=None,passwd=None): sstype = None - sopts=["%s_%s" % (l,k) for k in cls.seed_opts for l in "from","export"] - for o in sopts: - if o in opt.__dict__ and opt.__dict__[o]: - sstype = cls.seed_opts[o.split("_",1)[1]] - break if seed: - return globals()[sstype or "Wallet"](seed=seed) + if opt.out_fmt: + sstype = fmt_code_to_sstype(opt.out_fmt) + # Output format defaults to "Wallet" + return globals()[sstype or "Wallet"](seed=seed,passwd=passwd) else: - if fn: - if opt.from_incog_hidden: - fn = Filename(fn,ftype="hincog") - else: - fn = Filename(fn) - sstype = fn.linked_obj - return globals()[sstype](fn=fn) + if infile: + fn = Filename(infile) + return globals()[fn.sstype](fn=fn,passwd=passwd) + elif opt.in_fmt: # Input format + sstype = fmt_code_to_sstype(opt.in_fmt) + return globals()[sstype](passwd=passwd) else: - return globals()[sstype or "Wallet"]() + die(2,"Either an input file or input format must be specified") init = classmethod(init) @@ -127,9 +116,8 @@ empty passphrase, just hit ENTER twice. } def _pre_encode(self): - if not self.ssdata.passwd: - self._get_hash_preset() - self._get_first_passwd() + if self.ssdata.passwd == None: self._get_first_passwd() + self._get_hash_preset() self._encrypt_seed() def _get_first_passwd(self): @@ -326,6 +314,7 @@ class Wallet (SeedSourceEnc): passwd = get_mmgen_passphrase(self.desc+prompt_add) key = make_key(passwd, d.salt, d.hash_preset) self.seed = Seed(decrypt_seed(d.enc_seed, key, d.seed_id, d.key_id)) + self.ssdata.passwd = passwd def _check_master_chksum(self,lines): @@ -483,7 +472,7 @@ to exit and re-run the program with the '--old-incog-fmt' option. d.wrapper_key = make_key(d.passwd, d.iv, d.hash_preset, "incog wrapper key") d.key_id = make_chksum_8(d.wrapper_key) - d.data_len = self._get_incog_data_len(opt.seed_len) + d.target_data_len = self._get_incog_data_len(opt.seed_len) def _format(self): d = self.ssdata @@ -506,14 +495,17 @@ to exit and re-run the program with the '--old-incog-fmt' option. def _deformat(self): - # Data could be of invalid length, so check: - valid_dlens = map(self._get_incog_data_len, g.seed_lens) - # => [56, 64, 72] + # Data could be of invalid length, so check: [56, 64, 72] + valid_dlen = self._get_incog_data_len(opt.seed_len) raw_d = self.fmt_data - if len(raw_d) not in valid_dlens: - die(1, - "Invalid incognito file size: %s. Valid sizes (in bytes): %s" % - (len(raw_d), " ".join(map(str, valid_dlens)))) + if len(raw_d) != valid_dlen: + msg("Invalid incognito data size: %s" % len(raw_d)) + msg("Valid incognito data size for this seed length: %s bytes" % + valid_dlen) + for sl in g.seed_lens: + if len(raw_d) == self._get_incog_data_len(sl): + die(1,"Maybe you need to specify a seed length of %s?" % sl) + die(1,"The data size is invalid for all available seed lengths") d = self.ssdata d.iv = raw_d[0:g.aesctr_iv_len] @@ -521,8 +513,8 @@ to exit and re-run the program with the '--old-incog-fmt' option. d.enc_incog_data = raw_d[g.aesctr_iv_len:] msg("Incog ID: %s" % d.incog_id) qmsg("Check the applicable value against your records") - k = 'incog_iv_id_hidden' if opt.from_incog_hidden else 'incog_iv_id' - vmsg("\n%s\n" % self._icg_msg[k]) + ksuf = '_hidden' if self.__class__ == "IncogWalletHidden" else "" + vmsg("\n%s\n" % self._icg_msg['incog_iv_id' + ksuf]) def _decode(self): d = self.ssdata @@ -565,24 +557,35 @@ class IncogWalletHex (IncogWallet): self.fmt_data = decode_pretty_hexdump(self.fmt_data) IncogWallet._deformat(self) + def _format(self): + IncogWallet._format(self) + self.fmt_data = pretty_hexdump(self.fmt_data) + + def _filename(self): + return IncogWallet._filename(self)[:-len(g.incog_ext)] + g.incog_hex_ext + class IncogWalletHidden (IncogWallet): - def _parse_hincog_opt(self): - class HincogParams(MMGenObject): pass - o = opt.from_incog_hidden or opt.export_incog_hidden - p = HincogParams() - a,b = o.split(",") - p.filename = a - p.offset = int(b) - return p + _hicg_msg = { + 'choose_file_size': """ +You must choose a size for your new hidden incog data. The minimum size is +{} bytes, which puts the incog data right at the end of the file. Since you +probably want to hide your data somewhere in the middle of the file where +it's harder to find, you're advised to choose a much larger file size. + """.strip(), + } + + def _get_hincog_params(self): + a,b = opt.hidden_incog_params.split(",") + return a,int(b) def _check_valid_offset(self,fn,action): d = self.ssdata - if fn.size < d.hincog_offset + d.data_len: + if fn.size < d.hincog_offset + d.target_data_len: die(1, "Destination file has length %s, too short to %s %s bytes of data at offset %s" - % (f.size,action,d.data_len,d.hincog_offset)) + % (fn.size,action,d.target_data_len,d.hincog_offset)) # overrides method in SeedSource @@ -590,43 +593,62 @@ class IncogWalletHidden (IncogWallet): if fn: die(1, "Specify the filename as a parameter of the '--from-hidden-incog' option") d = self.ssdata - p = self._parse_hincog_opt() - d.hincog_offset = p.offset - self.infile = Filename(p.filename,ftype="hincog") + f,d.hincog_offset = self._get_hincog_params() + self.infile = Filename(f,ftype="hincog") qmsg("Getting hidden incog data from file '%s'" % self.infile.name) # Already sanity-checked: - d.data_len = self._get_incog_data_len(opt.seed_len) + d.target_data_len = self._get_incog_data_len(opt.seed_len) self._check_valid_offset(self.infile,"read") - import os fh = os.open(self.infile.name,os.O_RDONLY) - os.lseek(fh,int(p.offset),os.SEEK_SET) - self.fmt_data = os.read(fh,d.data_len) + os.lseek(fh,int(d.hincog_offset),os.SEEK_SET) + self.fmt_data = os.read(fh,d.target_data_len) os.close(fh) qmsg("Data read from file '%s' at offset %s" % - (self.infile.name,p.offset), "Data read from file") + (self.infile.name,d.hincog_offset), "Data read from file") # overrides method in SeedSource def write_to_file(self): d = self.ssdata self._format() - compare_or_die(d.data_len, "target data length", + compare_or_die(d.target_data_len, "target data length", len(self.fmt_data),"length of formatted " + self.desc) - p = self._parse_hincog_opt() - d.hincog_offset = p.offset - self.outfile = f = Filename(p.filename,ftype="hincog") + fn,d.hincog_offset = self._get_hincog_params() + + self.hincog_data_is_new = False + try: + os.stat(fn) + except: + if keypress_confirm("Requested file '%s' does not exist. Create?" + % fn, default_yes=True): + min_fsize = d.target_data_len + d.hincog_offset + msg(self._hicg_msg['choose_file_size'].format(min_fsize)) + while True: + fsize = my_raw_input("Enter file size: ") + if is_int(fsize) and int(fsize) >= min_fsize: break + msg("File size must be an integer no less than %s" % min_fsize) + + g.use_urandchars = True + from mmgen.tool import rand2file + rand2file(fn, str(fsize)) + self.hincog_data_is_new = True + else: + die(1,"Exiting at user request") + + self.outfile = f = Filename(fn,ftype="hincog") if opt.debug: - Msg("Incog data len %s, offset %s" % (d.data_len,p.offset)) - self._check_valid_offset(f,"write") + Msg("Incog data len %s, offset %s" % (d.target_data_len,d.hincog_offset)) + + if not self.hincog_data_is_new: + self._check_valid_offset(f,"write") + if not opt.quiet: confirm_or_exit("","alter file '%s'" % f.name) - if not opt.quiet: confirm_or_exit("","alter file '%s'" % f.name) - import os fh = os.open(f.name,os.O_RDWR) - os.lseek(fh, int(p.offset), os.SEEK_SET) + os.lseek(fh, int(d.hincog_offset), os.SEEK_SET) os.write(fh, self.fmt_data) os.close(fh) - msg("Data written to file '%s' at offset %s" % (f.name,p.offset)) + msg("Incog data written to file '%s' at offset %s" % (f.name,d.hincog_offset)) diff --git a/mmgen/term.py b/mmgen/term.py index 1beb8272..f19be1d6 100755 --- a/mmgen/term.py +++ b/mmgen/term.py @@ -21,7 +21,7 @@ term.py: Terminal-handling routines for the MMGen suite """ import sys, os, struct -import mmgen.config as g +import mmgen.globalvars as g import opt from mmgen.util import msg, msg_r diff --git a/mmgen/tool.py b/mmgen/tool.py index 4958bfd5..c643cdd0 100755 --- a/mmgen/tool.py +++ b/mmgen/tool.py @@ -24,7 +24,7 @@ import sys import mmgen.bitcoin as bitcoin import binascii as ba -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.crypto import * from mmgen.util import * @@ -600,7 +600,7 @@ def rand2file(outfile, nbytes, threads=4, silent=False): if not silent: msg("\rRead: %s bytes" % nbytes) - qmsg("\r%s bytes written to file '%s'" % (nbytes,outfile)) + qmsg("\r%s bytes of random data written to file '%s'" % (nbytes,outfile)) q1.join() q2.join() f.close() diff --git a/mmgen/tx.py b/mmgen/tx.py index caed7432..db3c0bc9 100755 --- a/mmgen/tx.py +++ b/mmgen/tx.py @@ -25,7 +25,7 @@ from binascii import unhexlify from decimal import Decimal from collections import OrderedDict -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.util import * from mmgen.term import do_pager diff --git a/mmgen/util.py b/mmgen/util.py index 694483a0..c004e73f 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -25,7 +25,7 @@ from hashlib import sha256 from binascii import hexlify,unhexlify from string import hexdigits -import mmgen.config as g +import mmgen.globalvars as g pnm = g.proj_name @@ -55,7 +55,20 @@ def die(ev,s): def Die(ev,s): sys.stdout.write(s+"\n"); sys.exit(ev) +def fmt_type(x): return "%s" % str(type(x)).split("'")[1] + import opt + +def fmt_code_to_sstype(fmt_code): + for e in g.wallet_fmt_codes: + if fmt_code in e: return e[0] + die(2,"'%s': unrecognized format code" % fmt_code) + +def format_fmt_codes(): + return "".join( + ["%-20s " % (e[0]+":") + ",".join(e[1:]) + "\n" + for e in g.wallet_fmt_codes]) + def qmsg(s,alt=False): if opt.quiet: if alt != False: sys.stderr.write(alt + "\n") @@ -128,6 +141,13 @@ def secs_to_hms(secs): def _is_whatstring(s,chars): return set(list(s)) <= set(chars) +def is_int(s): + try: + int(s) + return True + except: + return False + def is_hexstring(s): return _is_whatstring(s.lower(),hexdigits.lower()) def is_hexstring_lc(s): @@ -161,7 +181,7 @@ def pretty_hexdump(data,gw=2,cols=8,line_nums=False): (" " if (i+1) % cols else "\n") for i in range(len(data)/gw + r) ] - ).rstrip() + ).rstrip() + "\n" def decode_pretty_hexdump(data): from string import hexdigits diff --git a/setup.py b/setup.py index 2b131d0f..c4552da5 100755 --- a/setup.py +++ b/setup.py @@ -32,14 +32,17 @@ setup( 'mmgen.__init__', 'mmgen.addr', 'mmgen.bitcoin', - 'mmgen.config', + 'mmgen.globalvars', 'mmgen.crypto', + 'mmgen.filename', 'mmgen.license', 'mmgen.mn_electrum', 'mmgen.mnemonic', 'mmgen.mn_tirosh', + 'mmgen.obj', 'mmgen.opts', 'mmgen.opt', + 'mmgen.seed', 'mmgen.term', 'mmgen.test', 'mmgen.tool', diff --git a/test/test.py b/test/test.py index f5a90c63..4f926cbe 100755 --- a/test/test.py +++ b/test/test.py @@ -8,7 +8,7 @@ pn = os.path.dirname(sys.argv[0]) os.chdir(os.path.join(pn,os.pardir)) sys.path.__setitem__(0,os.path.abspath(os.curdir)) -import mmgen.config as g +import mmgen.globalvars as g import mmgen.opt as opt from mmgen.util import msgrepr,msgrepr_exit,Msg,die from mmgen.test import *