Browse Source

renamed: mmgen/config.py -> mmgen/globalvars.py
modified: setup.py

philemon 10 years ago
parent
commit
f1f28a6e75

+ 1 - 1
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

+ 1 - 1
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

+ 5 - 4
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))

+ 9 - 0
mmgen/config.py → 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

+ 1 - 1
mmgen/license.py

@@ -19,7 +19,7 @@
 """
 license.py:  Text of GPLv3
 """
-import mmgen.config as g
+import mmgen.globalvars as g
 
 gpl = {
 	'warning': """

+ 1 - 1
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 *

+ 1 - 1
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

+ 1 - 1
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 = {

+ 1 - 1
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
 

+ 1 - 1
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 *
 

+ 1 - 1
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 *

+ 1 - 1
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

+ 1 - 1
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 *

+ 1 - 1
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 *

+ 1 - 1
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 = {

+ 3 - 2
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)

+ 31 - 20
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'),

+ 2 - 2
mmgen/rpc/proxy.py

@@ -1,6 +1,6 @@
 """
   Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
-  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):

+ 89 - 67
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))

+ 1 - 1
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
 

+ 2 - 2
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()

+ 1 - 1
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

+ 22 - 2
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

+ 4 - 1
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',

+ 1 - 1
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 *