Compare commits

..

No commits in common. "1db7f3f8c85e677d0bd8d90562d92270fb43c9b5" and "9419fbb77b314ba91800384857e86e7c3173b2e8" have entirely different histories.

8 changed files with 45 additions and 125 deletions

View File

@ -1,11 +1,5 @@
- 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 - 0.0.22
* Man page generator script * Add man page generator script
- 0.0.21 - 0.0.21
* Log rpc reply before json parse * Log rpc reply before json parse
- 0.0.20 - 0.0.20

View File

@ -1 +1 @@
include *requirements.txt LICENSE chainlib/data/config/* chainlib/data/env/* include *requirements.txt LICENSE chainlib/data/config/*

View File

@ -3,8 +3,7 @@ from .base import (
argflag_std_read, argflag_std_read,
argflag_std_write, argflag_std_write,
argflag_std_base, argflag_std_base,
argflag_std_base_read, reset,
flag_reset,
) )
from .arg import ArgumentParser from .arg import ArgumentParser
from .config import Config from .config import Config

View File

@ -203,9 +203,8 @@ class ArgumentParser(argparse.ArgumentParser):
if arg_flags & (Flag.SIGN | Flag.FEE): 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-price', dest='fee_price', type=int, help='override fee price')
self.add_argument('--fee-limit', dest='fee_limit', type=int, help='override fee limit') self.add_argument('--fee-limit', dest='fee_limit', type=int, help='override fee limit')
# wtf? if arg_flags & argflag_std_target == 0:
#if arg_flags & argflag_std_target == 0: arg_flags |= Flag.WALLET
# arg_flags |= Flag.WALLET
if arg_flags & Flag.EXEC: if arg_flags & Flag.EXEC:
self.add_argument('-e', self.long_args['-e'], dest=self.arg_dest['-e'], type=str, help='contract address') self.add_argument('-e', self.long_args['-e'], dest=self.arg_dest['-e'], type=str, help='contract address')
if arg_flags & Flag.WALLET: if arg_flags & Flag.WALLET:

View File

@ -33,32 +33,14 @@ class Flag(enum.IntEnum):
SEND = 262144 SEND = 262144
# rpc extras - nibble 6 # rpc extras - nibble 6
RPC_AUTH = 1048576 RPC_AUTH = 1048576
# upper bound
MAX = 1048576
argflag_std_read = 0x23ff argflag_std_read = 0x23ff
argflag_std_write = 0x1731ff argflag_std_write = 0xff31ff
argflag_std_base = 0x200f argflag_std_base = 0x200f
argflag_std_base_read = 0xbf
argflag_std_target = 0x00e000 argflag_std_target = 0x00e000
argflag_all = 0x17f7ff argflag_all = 0xffffff
def reset(flags, v):
def flag_reset(flags, v):
mask = ~(argflag_all & v) mask = ~(argflag_all & v)
r = flags & mask r = flags & mask
return r 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

View File

@ -132,7 +132,6 @@ class DocGenerator:
def process_arg(self): def process_arg(self):
if self.arg_flags & Flag.VERBOSE: if self.arg_flags & Flag.VERBOSE:
o = DocEntry('--no-logs') o = DocEntry('--no-logs')
o.set_groff('Turn of logging completely. Negates \\fB-v\\fP and \\fB-vv\\fP') o.set_groff('Turn of logging completely. Negates \\fB-v\\fP and \\fB-vv\\fP')
@ -146,6 +145,7 @@ class DocGenerator:
o.set_groff('Very verbose. Show logs with debugging information.') o.set_groff('Very verbose. Show logs with debugging information.')
self.docs['vv'] = o self.docs['vv'] = o
if self.arg_flags & Flag.CONFIG: if self.arg_flags & Flag.CONFIG:
o = DocEntry('-c', '--config', argvalue='config_dir') 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.') 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,6 +244,7 @@ class DocGenerator:
o.set_groff('Produce output most optimized for machines.') o.set_groff('Produce output most optimized for machines.')
self.docs['raw'] = o self.docs['raw'] = o
if self.arg_flags & (Flag.SIGN | Flag.NONCE): if self.arg_flags & (Flag.SIGN | Flag.NONCE):
o = DocEntry('--nonce') o = DocEntry('--nonce')
o.set_groff('Explicitly set nonce to use for transaction.') o.set_groff('Explicitly set nonce to use for transaction.')
@ -259,10 +260,9 @@ 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.') 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 self.docs['feelimit'] = o
# TODO: this manipulation should be DRYd
# # TODO: this manipulation should be DRYd if self.arg_flags & argflag_std_target == 0:
# if self.arg_flags & argflag_std_target == 0: self.arg_flags |= Flag.WALLET
# self.arg_flags |= Flag.WALLET
if self.arg_flags & Flag.EXEC: if self.arg_flags & Flag.EXEC:

View File

@ -14,12 +14,9 @@ from chainlib.cli.man import (
DocGenerator, DocGenerator,
apply_groff, apply_groff,
) )
from chainlib.cli.base import ( from chainlib.cli.base import argflag_std_base
argflag_std_base,
flag_names,
)
from chainlib.cli.arg import ArgumentParser as ChainlibArgumentParser from chainlib.cli.arg import ArgumentParser as ChainlibArgumentParser
from chainlib.cli.config import Config from chainlib.eth.cli.config import Config
logging.basicConfig(level=logging.WARNING) logging.basicConfig(level=logging.WARNING)
@ -79,99 +76,56 @@ https://git.defalsify.org
argparser = argparse.ArgumentParser() argparser = argparse.ArgumentParser()
argparser.add_argument('-b', default=add_0x(hex(argflag_std_base)), help='argument flag bitmask') 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('-c', help='config override directory')
argparser.add_argument('-n', required=True, help='tool name to use for man filename') argparser.add_argument('-n', help='tool name to use for man filename')
argparser.add_argument('-d', default='.', help='output directory') argparser.add_argument('-d', default='.', help='output directory')
argparser.add_argument('-v', action='store_true', help='turn on debug logging') argparser.add_argument('-v', action='store_true', help='turn on debug logging')
#argparser.add_argument('--overrides-dir', dest='overrides_dir', help='load options description override from file') argparser.add_argument('--overrides-file', dest='overrides_file', 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-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('--overrides-config-file', dest='overrides_config_file', help='load configuration text from file')
argparser.add_argument('source_dir', help='directory containing sources for the tool man page') argparser.add_argument('header_file', help='groff file containing heading, synopsis and description')
args = argparser.parse_args(sys.argv[1:]) args = argparser.parse_args(sys.argv[1:])
if args.v: if args.v:
logg.setLevel(logging.DEBUG) logg.setLevel(logging.DEBUG)
b = bytes.fromhex(strip_0x(args.b)) b = bytes.fromhex(strip_0x(args.b))
flags = int.from_bytes(b, byteorder='big') flags = int.from_bytes(b, byteorder='little')
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) g = DocGenerator(flags)
toolname = args.n toolname = args.n
if toolname == None:
parts = os.path.splitext(os.path.basename(args.header_file))
toolname = parts[0]
g.process() g.process()
def apply_override(g, override_dir): if args.overrides_file != None:
#if args.overrides_dir != None: f = open(args.overrides_file, 'r')
overrides_file = os.path.join(override_dir, toolname + '.overrides') while True:
override = True s = f.readline()
f = None if len(s) == 0:
try: break
f = open(overrides_file, 'r') v = s.split('\t', maxsplit=2)
except FileNotFoundError: fargs = None
logg.debug('no overrides found for {}'.format(toolname)) try:
override = False fargs = v[2].rstrip().split(',')
except IndexError:
fargs = []
g.override_arg(v[0], v[1], fargs)
f.close()
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 = EnvDocGenerator(flags, override=args.overrides_env_dir)
ge.process() ge.process()
def get_head(tool_name, source_dir): f = open(args.header_file)
header_file = os.path.join(source_dir, tool_name + '.head.groff') head = f.read()
f = open(header_file, 'r') f.close()
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: if args.overrides_config_file != None:
f = open(args.overrides_config_file, 'r') f = open(args.overrides_config_file, 'r')
@ -183,14 +137,6 @@ f = os.fdopen(fd, 'w')
f.write(head) f.write(head)
f.write(str(g)) f.write(str(g))
f.write(configuration_description) 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(".SH ENVIRONMENT\n\n")
f.write(str(ge)) f.write(str(ge))
f.write(legal_description) f.write(legal_description)

View File

@ -3,7 +3,7 @@ name=chainlib
license=WTFPL2 license=WTFPL2
author_email=dev@holbrook.no author_email=dev@holbrook.no
description=Generic blockchain access library and tooling description=Generic blockchain access library and tooling
version=0.0.23 version=0.0.22
url=https://gitlab.com/chaintools/chainlib url=https://gitlab.com/chaintools/chainlib
author=Louis Holbrook author=Louis Holbrook