Compare commits
3 Commits
9419fbb77b
...
1db7f3f8c8
Author | SHA1 | Date | |
---|---|---|---|
|
1db7f3f8c8 | ||
|
9b0f900eb3 | ||
|
fcd78b5ca8 |
@ -1,5 +1,11 @@
|
||||
- 0.0.23
|
||||
* Configuration variable descriptions
|
||||
* Arg flags to names listing method
|
||||
* New flags preset for reads without wallet
|
||||
* Remove pesistent wallet arg flag bug
|
||||
* Rename arg flag reset to flag_reset
|
||||
- 0.0.22
|
||||
* Add man page generator script
|
||||
* Man page generator script
|
||||
- 0.0.21
|
||||
* Log rpc reply before json parse
|
||||
- 0.0.20
|
||||
|
@ -1 +1 @@
|
||||
include *requirements.txt LICENSE chainlib/data/config/*
|
||||
include *requirements.txt LICENSE chainlib/data/config/* chainlib/data/env/*
|
||||
|
@ -3,7 +3,8 @@ from .base import (
|
||||
argflag_std_read,
|
||||
argflag_std_write,
|
||||
argflag_std_base,
|
||||
reset,
|
||||
argflag_std_base_read,
|
||||
flag_reset,
|
||||
)
|
||||
from .arg import ArgumentParser
|
||||
from .config import Config
|
||||
|
@ -203,8 +203,9 @@ class ArgumentParser(argparse.ArgumentParser):
|
||||
if arg_flags & (Flag.SIGN | Flag.FEE):
|
||||
self.add_argument('--fee-price', dest='fee_price', type=int, help='override fee price')
|
||||
self.add_argument('--fee-limit', dest='fee_limit', type=int, help='override fee limit')
|
||||
if arg_flags & argflag_std_target == 0:
|
||||
arg_flags |= Flag.WALLET
|
||||
# wtf?
|
||||
#if arg_flags & argflag_std_target == 0:
|
||||
# arg_flags |= Flag.WALLET
|
||||
if arg_flags & Flag.EXEC:
|
||||
self.add_argument('-e', self.long_args['-e'], dest=self.arg_dest['-e'], type=str, help='contract address')
|
||||
if arg_flags & Flag.WALLET:
|
||||
|
@ -33,14 +33,32 @@ class Flag(enum.IntEnum):
|
||||
SEND = 262144
|
||||
# rpc extras - nibble 6
|
||||
RPC_AUTH = 1048576
|
||||
# upper bound
|
||||
MAX = 1048576
|
||||
|
||||
argflag_std_read = 0x23ff
|
||||
argflag_std_write = 0xff31ff
|
||||
argflag_std_write = 0x1731ff
|
||||
argflag_std_base = 0x200f
|
||||
argflag_std_base_read = 0xbf
|
||||
argflag_std_target = 0x00e000
|
||||
argflag_all = 0xffffff
|
||||
argflag_all = 0x17f7ff
|
||||
|
||||
def reset(flags, v):
|
||||
|
||||
def flag_reset(flags, v):
|
||||
mask = ~(argflag_all & v)
|
||||
r = flags & mask
|
||||
return r
|
||||
|
||||
|
||||
def flag_names(flags):
|
||||
flags_debug = []
|
||||
i = Flag.MAX
|
||||
while True:
|
||||
if flags & i > 0:
|
||||
v = Flag(i)
|
||||
flags_debug.append(v.name)
|
||||
i >>= 1
|
||||
if i == 0:
|
||||
break
|
||||
flags_debug.reverse()
|
||||
return flags_debug
|
||||
|
@ -132,6 +132,7 @@ class DocGenerator:
|
||||
|
||||
|
||||
def process_arg(self):
|
||||
|
||||
if self.arg_flags & Flag.VERBOSE:
|
||||
o = DocEntry('--no-logs')
|
||||
o.set_groff('Turn of logging completely. Negates \\fB-v\\fP and \\fB-vv\\fP')
|
||||
@ -145,7 +146,6 @@ class DocGenerator:
|
||||
o.set_groff('Very verbose. Show logs with debugging information.')
|
||||
self.docs['vv'] = o
|
||||
|
||||
|
||||
if self.arg_flags & Flag.CONFIG:
|
||||
o = DocEntry('-c', '--config', argvalue='config_dir')
|
||||
o.set_groff('Load configuration files from given directory. All files with an .ini extension will be loaded, of which all must contain valid ini file data.')
|
||||
@ -244,7 +244,6 @@ class DocGenerator:
|
||||
o.set_groff('Produce output most optimized for machines.')
|
||||
self.docs['raw'] = o
|
||||
|
||||
|
||||
if self.arg_flags & (Flag.SIGN | Flag.NONCE):
|
||||
o = DocEntry('--nonce')
|
||||
o.set_groff('Explicitly set nonce to use for transaction.')
|
||||
@ -260,9 +259,10 @@ class DocGenerator:
|
||||
o.set_groff('Set the limit of execution units for the transaction. If used with \\fB-s\\fP this may incur actual network token cost. If \\fB--fee-price\\fP is not explicitly set, the price \\fImay\\fP be retrieved from the network, and multiplied with this value to define the cost.')
|
||||
self.docs['feelimit'] = o
|
||||
|
||||
# TODO: this manipulation should be DRYd
|
||||
if self.arg_flags & argflag_std_target == 0:
|
||||
self.arg_flags |= Flag.WALLET
|
||||
|
||||
# # TODO: this manipulation should be DRYd
|
||||
# if self.arg_flags & argflag_std_target == 0:
|
||||
# self.arg_flags |= Flag.WALLET
|
||||
|
||||
|
||||
if self.arg_flags & Flag.EXEC:
|
||||
|
@ -14,9 +14,12 @@ from chainlib.cli.man import (
|
||||
DocGenerator,
|
||||
apply_groff,
|
||||
)
|
||||
from chainlib.cli.base import argflag_std_base
|
||||
from chainlib.cli.base import (
|
||||
argflag_std_base,
|
||||
flag_names,
|
||||
)
|
||||
from chainlib.cli.arg import ArgumentParser as ChainlibArgumentParser
|
||||
from chainlib.eth.cli.config import Config
|
||||
from chainlib.cli.config import Config
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
@ -76,56 +79,99 @@ https://git.defalsify.org
|
||||
argparser = argparse.ArgumentParser()
|
||||
argparser.add_argument('-b', default=add_0x(hex(argflag_std_base)), help='argument flag bitmask')
|
||||
argparser.add_argument('-c', help='config override directory')
|
||||
argparser.add_argument('-n', help='tool name to use for man filename')
|
||||
argparser.add_argument('-n', required=True, help='tool name to use for man filename')
|
||||
argparser.add_argument('-d', default='.', help='output directory')
|
||||
argparser.add_argument('-v', action='store_true', help='turn on debug logging')
|
||||
argparser.add_argument('--overrides-file', dest='overrides_file', help='load options description override from file')
|
||||
#argparser.add_argument('--overrides-dir', dest='overrides_dir', help='load options description override from file')
|
||||
argparser.add_argument('--overrides-env-dir', dest='overrides_env_dir', help='load envionment description override config from directory')
|
||||
argparser.add_argument('--overrides-config-file', dest='overrides_config_file', help='load configuration text from file')
|
||||
argparser.add_argument('header_file', help='groff file containing heading, synopsis and description')
|
||||
argparser.add_argument('source_dir', help='directory containing sources for the tool man page')
|
||||
args = argparser.parse_args(sys.argv[1:])
|
||||
|
||||
if args.v:
|
||||
logg.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
b = bytes.fromhex(strip_0x(args.b))
|
||||
flags = int.from_bytes(b, byteorder='little')
|
||||
flags = int.from_bytes(b, byteorder='big')
|
||||
|
||||
flags_debug= flag_names(flags)
|
||||
logg.debug('apply arg flags {}: {}'.format(flags, ', '.join(flags_debug)))
|
||||
|
||||
#empty_args = ChainlibArgumentParser(flags).parse_args([])
|
||||
#config = Config.from_args(empty_args, arg_flags=flags)
|
||||
#g = DocGenerator(flags, config)
|
||||
g = DocGenerator(flags)
|
||||
|
||||
toolname = args.n
|
||||
if toolname == None:
|
||||
parts = os.path.splitext(os.path.basename(args.header_file))
|
||||
toolname = parts[0]
|
||||
|
||||
g.process()
|
||||
|
||||
if args.overrides_file != None:
|
||||
f = open(args.overrides_file, 'r')
|
||||
while True:
|
||||
s = f.readline()
|
||||
if len(s) == 0:
|
||||
break
|
||||
v = s.split('\t', maxsplit=2)
|
||||
fargs = None
|
||||
try:
|
||||
fargs = v[2].rstrip().split(',')
|
||||
except IndexError:
|
||||
fargs = []
|
||||
g.override_arg(v[0], v[1], fargs)
|
||||
f.close()
|
||||
def apply_override(g, override_dir):
|
||||
#if args.overrides_dir != None:
|
||||
overrides_file = os.path.join(override_dir, toolname + '.overrides')
|
||||
override = True
|
||||
f = None
|
||||
try:
|
||||
f = open(overrides_file, 'r')
|
||||
except FileNotFoundError:
|
||||
logg.debug('no overrides found for {}'.format(toolname))
|
||||
override = False
|
||||
|
||||
if override:
|
||||
while True:
|
||||
s = f.readline()
|
||||
if len(s) == 0:
|
||||
break
|
||||
v = s.split('\t', maxsplit=2)
|
||||
fargs = None
|
||||
try:
|
||||
fargs = v[2].rstrip().split(',')
|
||||
except IndexError:
|
||||
fargs = []
|
||||
g.override_arg(v[0], v[1], fargs)
|
||||
f.close()
|
||||
return g
|
||||
|
||||
g = apply_override(g, args.source_dir)
|
||||
|
||||
ge = EnvDocGenerator(flags, override=args.overrides_env_dir)
|
||||
ge.process()
|
||||
|
||||
f = open(args.header_file)
|
||||
head = f.read()
|
||||
f.close()
|
||||
def get_head(tool_name, source_dir):
|
||||
header_file = os.path.join(source_dir, tool_name + '.head.groff')
|
||||
f = open(header_file, 'r')
|
||||
head = f.read()
|
||||
f.close()
|
||||
return head
|
||||
|
||||
|
||||
def get_examples(tool_name, source_dir):
|
||||
example_file = os.path.join(source_dir, tool_name + '.examples.groff')
|
||||
f = None
|
||||
try:
|
||||
f = open(example_file, 'r')
|
||||
except FileNotFoundError:
|
||||
logg.debug('no examples file found for {}'.format(tool_name))
|
||||
return None
|
||||
logg.info('examples file {} found for {}'.format(example_file, tool_name))
|
||||
examples = f.read()
|
||||
f.close()
|
||||
return examples
|
||||
|
||||
|
||||
def get_custom(tool_name, source_dir):
|
||||
custom_file = os.path.join(source_dir, tool_name + '.custom.groff')
|
||||
f = None
|
||||
try:
|
||||
f = open(custom_file, 'r')
|
||||
except FileNotFoundError:
|
||||
logg.debug('no custom file found for {}'.format(tool_name))
|
||||
return None
|
||||
logg.info('custom file {} found for {}'.format(custom_file, tool_name))
|
||||
custom = f.read()
|
||||
f.close()
|
||||
return custom
|
||||
|
||||
|
||||
head = get_head(toolname, args.source_dir)
|
||||
examples = get_examples(toolname, args.source_dir)
|
||||
custom = get_custom(toolname, args.source_dir)
|
||||
|
||||
if args.overrides_config_file != None:
|
||||
f = open(args.overrides_config_file, 'r')
|
||||
@ -137,6 +183,14 @@ f = os.fdopen(fd, 'w')
|
||||
f.write(head)
|
||||
f.write(str(g))
|
||||
f.write(configuration_description)
|
||||
|
||||
if custom != None:
|
||||
f.write(custom)
|
||||
|
||||
if examples != None:
|
||||
f.write(".SH EXAMPLES\n\n")
|
||||
f.write(examples)
|
||||
|
||||
f.write(".SH ENVIRONMENT\n\n")
|
||||
f.write(str(ge))
|
||||
f.write(legal_description)
|
||||
|
Loading…
Reference in New Issue
Block a user