chainlib

Generic blockchain access library and tooling
Log | Files | Refs | README | LICENSE

commit 3691f75f81b720e93762e6a13189b9a91ab6c8e0
parent 299b680748f4246483d91e934e3c5ff26adbe823
Author: lash <dev@holbrook.no>
Date:   Tue, 22 Feb 2022 12:11:38 +0000

Add heading file argument to generator script

Diffstat:
MCHANGELOG | 2++
Mchainlib/cli/man.py | 2+-
Mscripts/man.py | 40+++++++++++++++++++++++++++++++++++++---
Msetup.py | 3+++
4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,3 +1,5 @@ +- 0.0.22 + * Add man page generator script - 0.0.21 * Log rpc reply before json parse - 0.0.20 diff --git a/chainlib/cli/man.py b/chainlib/cli/man.py @@ -193,7 +193,7 @@ class DocGenerator: self.docs['feeprice'] = o o = DocEntry('--fee-limit') - 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 # TODO: this manipulation should be DRYd diff --git a/scripts/man.py b/scripts/man.py @@ -1,8 +1,42 @@ +import os import sys -from hexathon import strip_0x +import argparse +import tempfile +import shutil + +from hexathon import strip_0x, add_0x + from chainlib.cli.man import DocGenerator +from chainlib.cli.base import argflag_std_base -b = bytes.fromhex(strip_0x(sys.argv[1])) +argparser = argparse.ArgumentParser() +argparser.add_argument('-b', default=add_0x(hex(argflag_std_base)), help='argument flag bitmask') +argparser.add_argument('-n', help='tool name to use for man filename') +argparser.add_argument('-d', default='.', help='output directory') +argparser.add_argument('header_file', help='groff file containing heading, synopsis and description') +args = argparser.parse_args(sys.argv[1:]) + +#b = bytes.fromhex(strip_0x(sys.argv[1])) +b = bytes.fromhex(strip_0x(args.b)) g = DocGenerator(int.from_bytes(b, byteorder='little')) g.process() -print(g) + +f = open(args.header_file) +head = f.read() +f.close() + +toolname = args.n +if toolname == None: + parts = os.path.splitext(os.path.basename(args.header_file)) + toolname = parts[0] + +(fd, fp) = tempfile.mkstemp() +f = os.fdopen(fd, 'w') +f.write(head) +f.write(str(g)) +f.close() + +dest = os.path.join(args.d, toolname + '.1') +shutil.copyfile(fp, dest) + +os.unlink(fp) diff --git a/setup.py b/setup.py @@ -24,4 +24,7 @@ setup( 'chainlib', 'chainlib.cli', ], + scripts = [ + 'scripts/man.py', + ], )